5 the final_hard_part

432 views

Published on

a series of basic java training courses, this is the last one

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
432
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
22
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 5 the final_hard_part

    1. 1. Java Basic Training V. The Final Hard Part
    2. 2. OutlineXMLJAXPThreadingClass LoaderThe Good to Know Libs
    3. 3. XML
    4. 4. XML XML - eXtensible Markup Language Designed to transport and store data Important to know Very easy to learn???? XML is a W3C Recommendation XML is Everywhere XML rules the Java world
    5. 5. XML XML - eXtensible Markup Language Designed to transport and store data Important to know Very easy to learn???? XML is a W3C Recommendation XML is Everywhere XML rules the Java world
    6. 6. XMLThe Evil Things
    7. 7. XMLThe Evil Things Namespace
    8. 8. XMLThe Evil Things Namespace Someone believes that tag name is not enough
    9. 9. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves
    10. 10. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves
    11. 11. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model
    12. 12. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model Attribute
    13. 13. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model Attribute Node
    14. 14. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model Attribute Node Element
    15. 15. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model Attribute Node Element Document
    16. 16. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model <root> Attribute <books> <book> this is my book <title>xxx</title> Node <publish_date>xxx</publish_date> </book> </books> </root> Element Document
    17. 17. XMLThe Evil Things Namespace Someone believes that tag name is not enough Then XML evolves DOM model <root> Attribute <books> <book> this is my book do ell ? <title>xxx</title> Node <publish_date>xxx</publish_date> e h this </book> th d </books> </root> Element hy ee W en Document w
    18. 18. ExercisesWrite a simple XMLAdd namespaceFinish the quiz: http://w3schools.com/xml/xml_quiz.aspYou may want to get certificate
    19. 19. ExercisesWrite a simple XMLAdd namespaceFinish the quiz: http://w3schools.com/xml/xml_quiz.aspYou may want to get certificate
    20. 20. ExercisesWrite a simple XMLAdd namespaceFinish the quiz: http://w3schools.com/xml/xml_quiz.aspYou may want to get certificate
    21. 21. JAXP
    22. 22. JAXPJava API for XML Processing JAXP is a specification JDK shipped with a reference implementation Complexity of JAXP is beyond your wildest imagination
    23. 23. JAXP - Parsing demo.xml
    24. 24. JAXP - Printing demo.xml
    25. 25. JAXP - Processing demo.xml
    26. 26. JAXP - DOM Model
    27. 27. JAXP - DOM Model http://www.xml.com/1999/07/dom/dom.gif
    28. 28. JAXP - DOM Model
    29. 29. JAXP - DOM Model here we have a text node! demo.xml
    30. 30. JAXP - DOM ModelDOM is actually a computer game
    31. 31. JAXP - DOM ModelDOM is actually a computer game DOM Level One
    32. 32. JAXP - DOM ModelDOM is actually a computer game DOM Level One DOM Level Two
    33. 33. JAXP - DOM ModelDOM is actually a computer game DOM Level One DOM Level Two DOM Level Three
    34. 34. ExercisesGet value of node “b”Set value of node “b” demo.xmlAdd element “c” under node “a”
    35. 35. Threading
    36. 36. ThreadingJava makes it simply to create new threads Extends Thread Or implements Runnable So what’s the difference?JVM makes it real native thread Thread is not simulated So your knowledge of thread still works
    37. 37. ExercisesWrite HelloThread, and HelloRunnableUnderstand the differenceTry join method
    38. 38. Threading - Synchronization Whenever there is threading, there is synchronization In Java world, synchronization can be Synchronized method Synchronized block Lock & Semaphore
    39. 39. ExercisesTry different synchronization mechanismsWhen should we use which
    40. 40. Threading - DRYTimer Consider using Timer when your thread does something timelyExecutorService For one task, you need another thread(s) to execute or schedule to execute Not need returned value or retrieve it laterForkJoinPool JDK7 Split your big task into small ones Accomplish small ones and then combine result togetherConcurrent container ConcurrentHashMap ConcurrentLinkedQueue CopyOnWriteArrayList ...
    41. 41. ExercisesTry TimerTry ExecutorServiceTry ConcurrentHashMap
    42. 42. Class Loader
    43. 43. Class Loader - IntroClass loader loads Java classes on demand dynamicallyClasses loaded by different class loaders are isolatedClasses will not be GCed if the corresponding class loader is aliveClasses are stored in permanent space Out of permanent space if Too many classes loaded Class loader leaks
    44. 44. Class Loader - IsolationClass loader loads Java classes on demand dynamicallyClasses loaded by different class loaders are isolatedClasses will not be GCed if the corresponding class loader is aliveClass loader A Class loader BClasses are stored in permanent spaceclass A of permanent space if Out class A Too manyA(); A a = new classes loaded A a1 = (A) object; // cast failure Class loader leaks
    45. 45. Class Loader - IsolationClass loader loads Java classes on demand dynamicallyClasses loaded by different class loaders are isolatedClasses will not be GCed if the corresponding class loader is aliveClass loader A Class loader BClasses are stored in permanent spaceclass A of permanent space if Out class A Too manyA(); A a = new classes loaded A a1 = (A) object; // cast failure Class loader leaks
    46. 46. ExercisesTaste class loader isolation by example
    47. 47. Class Loader - Delegation Bootstrap $JAVA_HOME/jre/lib/rt.jar Class Loader 1. Retrieve from cache Extension $JAVA_HOME/jre/lib/ext/*.jar Class Loader 2. Delegate to parent System $CLASSPATH Class Loader 3. Load by itself User-defined User-defined /path/to/something.jar Class Loader Class Loader User-defined Class Loaderhttp://www.techjava.de/topics/2008/01/java-class-loading/
    48. 48. Class Loader - Loading Incorporating the binary data into the runtime state of the JVM Bringing binary data from a class to JVM Linking Insure class is properly formed and fit for use by the JVM Loading Verifying • Verify bytecode • Prepare data structure for class/ methods/fields, etc • Resolve all other classes referenced by a particular class Preparing Class variables are give their proper initial value Resolving Initializinghttp://www.techjava.de/topics/2008/01/java-class-loading/
    49. 49. ExercisesPrint out class loader of different classesWrite our own class loader http://java.sun.com/developer/onlineTraining/Security/ Fundamentals/magercises/ClassLoader/help.html
    50. 50. Class Loader - OSGihttp://www.slideshare.net/honnix/osgi-class-loading
    51. 51. The Good to Know Libs the absolutely not complete list
    52. 52. The Good to Know Libs - Logging Logging facade commons-logging Not well suited into OSGi slf4j slf4j-jcl jcl-over-slf4j Logging backend log4j logback
    53. 53. The Good to Know Libs - WebContainer Tomcat Everybody knows it Jetty Actively evolving Perfect for embedding Driving for many servlet standards
    54. 54. The Good to Know Libs - IOCFramework Spring IOC Based on XML configuration Guice Based on Annotation
    55. 55. The Good to Know Libs -ApacheCommons Series BSF - Bean Script Framework CLI - Command Line Interpreter Codec - General encoding/decoding algorithm Collections - Extends or augments the Java Collection Framework DBCP - Database connection pooling service FileUpload - File upload capability for servlets and web apps Logging - Logging facade Pool - Generic object pooling http://commons.apache.org/
    56. 56. The Good to Know Libs - Unit Test JUnit4 Widely used TestNG Inspired by JUnit and NUnit with lots of new functionalities Mockito/PowerMock Mocking framework
    57. 57. The Good to Know Libs - Misc Hibernate OR mapping JBPM Workflow JGroups/Hazelcast Clustering Distributed collection JAX-WS Web service Gson Support JSON in Java JRebel Hot bytecode swapping Commercial
    58. 58. HomeworkStore addresses in XML formatMake use of ExecutorService for each operationForget about class loader until you really need itAdd logging capability to your AddressBook slf4j as facade logback as backend

    ×