J2SE 5


Published on

New features in J2SE 1.5, and comparison with java 1.4

Published in: Technology, Education
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

J2SE 5

  1. 1. J2SE 5.0 Tiger
  2. 2. J2SE Road Map <ul><li>Version </li></ul><ul><li>Code Name </li></ul><ul><li>Release Date </li></ul>JDK 1.1.4 JDK 1.1.5 JDK 1.1.6 JDK 1.1.7 JDK 1.1.8 J2SE 1.2 J2SE 1.2.1 J2SE 1.2.2 J2SE 1.3 J2SE 1.3.1 J2SE 1.4.0 J2SE 1.4.1 J2SE 1.4.2 Sparkler Pumpkin Abigail Brutus Chelsea Playground (none) Cricket Kestrel Ladybird Merlin Hopper Mantis Sept 12, 1997 Dec 3, 1997 April 24, 1998 Sept 28, 1998 April 8, 1999 Dec 4, 1998 March 30, 1999 July 8, 1999 May 8, 2000 May 17, 2001 Feb 13, 2002 Sept 16, 2002 June 26, 2003 J2SE 5.0 (1.5.0) Tiger Sept 29, 2004
  3. 3. J2SE Themes <ul><li>J2SE 1.4.0 - Quality </li></ul><ul><li>(Merlin) </li></ul><ul><li>J2SE 5.0 - Ease of Development </li></ul><ul><li>(Tiger) </li></ul><ul><li>J2SE 6.0 - Becoming more open </li></ul><ul><li>(Mustang) (Java goes multilingual) </li></ul>
  4. 4. Theme for J2SE 5.0 <ul><li>Ease of development </li></ul><ul><li>Quality </li></ul><ul><li>Monitoring and Manageability </li></ul><ul><li>Performance and Scalability </li></ul><ul><li>Desktop Client </li></ul>
  5. 5. New Features in J2SE 5.0 <ul><li>Language Features </li></ul><ul><li>Virtual Machine Features </li></ul><ul><li>Performance Enhancements </li></ul><ul><li>Base Libraries </li></ul><ul><li>Integration Libraries </li></ul>
  6. 6. New Features in J2SE 5.0 <ul><li>Language Features </li></ul><ul><li>Virtual Machine Features </li></ul><ul><li>Performance Enhancements </li></ul><ul><li>Base Libraries </li></ul><ul><li>Integration Libraries </li></ul>
  7. 7. Language Features <ul><li>Generics </li></ul><ul><li>Enhanced for Loop </li></ul><ul><li>Variable Arguments </li></ul><ul><li>Boxing / Unboxing </li></ul><ul><li>Type-safe enumerations </li></ul><ul><li>Static import </li></ul>
  8. 8. Generics <ul><li>A way to make class type-safe that are written on any arbitrary object type. </li></ul><ul><li>Allows to narrow an instance of a Collection to hold a specific object type and eliminating the need to typecast it while retrieving the object. </li></ul>
  9. 9. J2SE 1.4.0 ArrayList intList = new ArrayList(); intList.add(new Integer(0)); Integer intObj = (Integer) intList.get(0); J2SE 5.0 ArrayList<Integer> intList = new ArrayList<Integer>(); intList.add(new Integer(0)); // Only Integer Objects allowed Integer intObj = intList.get(0); // No need to Type Cast
  10. 10. Enhanced for Loop <ul><li>Iterating over collections is a pain. </li></ul><ul><li>● Often, iterator is unused except to get elements. </li></ul><ul><li>Iterators are error-prone. </li></ul><ul><li>– Iterator variable occurs three times per loop. </li></ul><ul><li>– Gives you two opportunities to get it wrong. </li></ul><ul><li>– Common cut-and-paste error. </li></ul><ul><li>Wouldn’t it be nice if the compiler took care of the iterator for you? </li></ul>
  11. 11. J2SE 1.4.0 for(Iterator iter = myArray.iterator(); iter.hasNext(); ) {     MyClass myObj = (MyClass)iter.next();     myObj.someOperation(); } J2SE 5.0 for(MyClass myObj : myArray) {     myObj.someOperation(); }
  12. 12. // Returns the sum of the elements of a int sum(int[] a) { int result = 0; for (int i : a) result += i; return result; } For Arrays ● Eliminates array index rather than iterator ● Similar advantages
  13. 13. Variable Arguments <ul><li>To write a method that takes an arbitrary number of parameters, you must use an array. </li></ul><ul><li>Creating and initializing arrays is a pain. </li></ul><ul><li>Why not complier take care of it? </li></ul>
  14. 14. public int sum(int... intList){     int i, sum;         sum=0;     for(i=0; i<intList.length; i++) {         sum += intList[i];     }         return(sum); } Possible ways to call this method int arr[] = { 3,5,7 }; int result = sum (arr); int result = sum (20, 30, 10 ,5 ); int result = sum(); Example of a method that takes an arbitrary number of int arguments and returns their sum:
  15. 15. Boxing / Unboxing <ul><li>Collections hold only objects, so to put primitive data types it needs to be wrapped into a class, like int to Integer. </li></ul><ul><li>It is a pain to wrap and unwrap. </li></ul><ul><li>Wouldn’t it be nice if the compiler took care of it for you? </li></ul>
  16. 16. J2SE 1.4.0 ArrayList arrayList = new ArrayList();     Integer intObject = new Integer(10); arrayList.add(intObject); // cannot add 10 directly J2SE 5.0 ArrayList arrayList = new ArrayList();     arrayList.add(10); // int 10 is automatically wrapped into Integer
  17. 17. Type-safe enumerations <ul><li>Compiler support for Typesafe Enum pattern. </li></ul><ul><li>Looks like traditional enum (C, C++, Pascal). </li></ul><ul><li>Far more powerful. </li></ul><ul><li>Can be used in switch/case statements. </li></ul><ul><li>Can be used in for loops. </li></ul>
  18. 18. <ul><li>An enumeration is an ordered list of items wrapped into a single entity. </li></ul><ul><ul><li>enum Season {winter, spring, summer, fall} </li></ul></ul><ul><li>Usage Example </li></ul><ul><li>for (Season s : Season.VALUES){ </li></ul><ul><li>// </li></ul><ul><li>} </li></ul><ul><li>An enumeration (abbreviated enum in Java) is a special type of class. </li></ul><ul><li>All enumerations implicitly subclass a new class in Java, java.lang.Enum. </li></ul><ul><li>This class cannot be subclassed manually. </li></ul>
  19. 19. Static import <ul><li>Ability to access static members from a class without need to qualify them with a class name. </li></ul>
  20. 20. interface ShapeNumbers {     public static int CIRCLE = 0;     public static int SQUARE = 1;     public static int TRIANGLE = 2; } Implementing this interface creates an unnecessary dependence on the ShapeNumbers interface. It becomes awkward to maintain as the class evolves, especially if other classes need access to these constants also and implement this interface
  21. 21. To make this cleaner, the static members are placed into a class and then imported via a modified syntax of the import directive . package MyConstants;     class ShapeNumbers {     public static int CIRCLE = 0;     public static int SQUARE = 1;     public static int TRIANGLE = 2; } To import the static members in your class, specify the following in the import section of your Java source file. import static MyConstants.ShapeNumbers.*; // imports all static data You can also import constants individually by using the following syntax: import static MyConstants.ShapeNumbers.CIRCLE; import static MyConstants.ShapeNumbers.SQUARE;
  22. 22. New Features in J2SE 5.0 <ul><li>Language Features </li></ul><ul><li>Virtual Machine Features </li></ul><ul><li>Performance Enhancements </li></ul><ul><li>Base Libraries </li></ul><ul><li>Integration Libraries </li></ul>
  23. 23. Virtual Machine Features <ul><li>Class Data Sharing </li></ul><ul><li>Server-Class Machine Detection </li></ul><ul><li>Garbage Collector Ergonomics </li></ul><ul><li>Thread Priority Changes </li></ul><ul><li>High-Precision Timing Support </li></ul>
  24. 24. Class Data Sharing <ul><li>Reduces startup time of java applications. </li></ul><ul><li>Better results for smaller applications. </li></ul><ul><li>Automatically enabled when conditions allow it to be used. </li></ul><ul><li>Not supported in Microsoft Windows 95/98/ME. </li></ul>
  25. 25. How CDS Works : When JRE is installed on 32-bit platforms using the Sun provided installer, it loads a set of classes from the system jar file into a private internal representation, and dumps that representation to a file, called a &quot; shared archive &quot;. Unix : jre/lib/[arch]/client/classes.jsa Windows : jre/bin/client/classes.jsa During subsequent JVM invocations, the shared archive is memory-mapped in, saving the cost of loading those classes and allowing much of the JVM's metadata for these classes to be shared among multiple JVM processes. CDS produces better results for smaller applications because it eliminates a fixed cost of loading certain core classes .
  26. 26. <ul><li>The footprint cost of new JVM instances has been reduced in two ways. </li></ul><ul><ul><li>First, a portion of the shared archive, currently 5-6 MB, is mapped read-only and therefore shared among multiple JVM processes. Previously this data was replicated in each JVM instance. </li></ul></ul><ul><ul><li>Second, since the shared archive contains class data in the form in which the Java VM uses it, the memory which would otherwise be required to access the original class information in rt.jar is not needed. </li></ul></ul><ul><li>These savings allow more applications to be run concurrently on the same machine. </li></ul>
  27. 27. Server-Class Machine Detection <ul><li>At startup Launcher automatically detects if application is running on “server-class” Machine. </li></ul><ul><li>Uses Server VM / Client VM accordingly. </li></ul><ul><li>Server-class Machine : One with at least 2 CPUs and at least 2GB of physical memory. </li></ul><ul><li>Server VM start more slowly than client VM, but over time runs more quickly. </li></ul>
  28. 28. Garbage Collector Ergonomics <ul><li>On server-class machines running the server VM , the garbage collector (GC) has changed from the previous serial collector to a parallel collector. </li></ul><ul><li>Can switch the GC collector mode using the command-line option. </li></ul><ul><ul><li>XX:+UseSerialGC - Serial collector </li></ul></ul><ul><ul><li>XX:+UseParallelGC - Parallel collector </li></ul></ul>
  29. 29. Thread Priority Changes <ul><li>Java threads and Native threads to compete on equal footing. </li></ul><ul><li>Java threads at NORM_PRIORITY can now compete as expected with native threads. </li></ul><ul><li>Java priorities in the range [10...5] are all mapped to the highest possible TS (timeshare) or IA (interactive) priority. </li></ul><ul><li>Priorities in the range [1..4] are mapped to correspondingly lower native TS or IA priorities </li></ul>
  30. 30. High-Precision Timing Support <ul><li>System.nanoTime() method added. </li></ul><ul><li>Provides access to nanosecond granularity time source for relative time measurements. </li></ul><ul><li>The actual precision of the time value returned is platform dependant. </li></ul>
  31. 31. New Features in J2SE 5.0 <ul><li>Language Features </li></ul><ul><li>Virtual Machine Features </li></ul><ul><li>Performance Enhancements </li></ul><ul><li>Base Libraries </li></ul><ul><li>Integration Libraries </li></ul>
  32. 32. Performance Enhancements <ul><li>Garbage collection Ergonomics </li></ul><ul><li>StringBuilder Class </li></ul><ul><li>Java 2D Technology </li></ul><ul><li>Image I/O </li></ul>
  33. 33. Garbage collection Ergonomics <ul><li>Automatic detection of Sever-Class Machine </li></ul><ul><ul><li>Using Client / Server VM accordingly. </li></ul></ul><ul><li>Parallel Garbage Collection </li></ul><ul><ul><li>Default parallel garbage collection on Server VM. </li></ul></ul>
  34. 34. StringBuilder Class <ul><li>Introduced a new class java.lang.StringBuilder. </li></ul><ul><li>It is like unsunchronized StringBuffer. </li></ul><ul><li>Faster than StringBuffer. </li></ul>
  35. 35. Java 2D Technology <ul><li>Improved acceleration for Buffered Image Objects </li></ul><ul><li>Support for H/W accelerated rendering using OpenGL. </li></ul><ul><li>Improved text-rendering performance. </li></ul>
  36. 36. Image I/O <ul><li>Improved Performance and memory usage while reading and writing JPEG Images. </li></ul><ul><li>In mage I/O API ( javax.imageio ) added support for reading and writing BMP and WBMP images. </li></ul>
  37. 37. New Features in J2SE 5.0 <ul><li>Language Features </li></ul><ul><li>Virtual Machine Features </li></ul><ul><li>Performance Enhancements </li></ul><ul><li>Base Libraries </li></ul><ul><li>Integration Libraries </li></ul>
  38. 38. Base Libraries <ul><li>Lang and Util Packages </li></ul><ul><li>Networking </li></ul><ul><li>JAXP </li></ul><ul><li>Bit Manipulation Operations </li></ul>
  39. 39. Lang and Util Packages <ul><li>ProcesBuilder </li></ul><ul><ul><li>More convenient way to invoke sub processes than Runtime.exec </li></ul></ul><ul><li>Formatter </li></ul><ul><ul><li>printf style format strings. </li></ul></ul><ul><ul><li>Support for layout justification and alignment, common formats for numeric, string and date/time data. </li></ul></ul><ul><li>Scanner </li></ul><ul><ul><li>Converts text into primitives or Strings. </li></ul></ul><ul><ul><li>regular expression based searches on streams, file data, strings. </li></ul></ul>
  40. 40. Lang and Util Packages contd… <ul><li>Instrumentation </li></ul><ul><ul><li>New package java.land.instrument , allows java programming agents to instrument programs running on the Java virtual machine by modifying methods' bytecodes at runtime </li></ul></ul><ul><li>Threads </li></ul><ul><ul><li>getState() for querying the execution state of a thread. </li></ul></ul><ul><ul><li>getStackTrace to obtain stack trace of a thread. </li></ul></ul><ul><ul><li>A new form of the sleep() method is provided which allows for sleep times smaller than one millisecond. </li></ul></ul>
  41. 41. Networking <ul><li>Complete support for IPv6 on Windows XP (sp1) and 2003. </li></ul><ul><li>ping like feature – InetAddress class provides API to test the reachability of a host. </li></ul><ul><li>Improved Cookie support. </li></ul><ul><li>Proxy Sever Configuration – ProxySelector API provides dynamic proxy configuration. </li></ul>
  42. 42. JAXP 1.3 <ul><li>A built-in validation processor for XML Schema. </li></ul><ul><li>XSLTC, the fast, compiling transformer, which is now the default engine for XSLT processing. </li></ul><ul><li>Java-Centric XPath APIs in javax.xml.xpath , which provide a more java-friendly way to use an XPath expression . </li></ul><ul><li>Grammar pre-parsing and caching, which has a major impact on performance for high-volume XML processing. </li></ul>
  43. 43. Bit Manipulation Operations <ul><li>The wrapper classes (Integer, Long, Short, Byte, and Char) now support common bit manipulation operations like </li></ul><ul><ul><li>highestOneBit, </li></ul></ul><ul><ul><li>lowestOneBit, </li></ul></ul><ul><ul><li>numberOfLeadingZeros, </li></ul></ul><ul><ul><li>numberOfTrailingZeros, </li></ul></ul><ul><ul><li>bitCount, </li></ul></ul><ul><ul><li>rotateLeft, </li></ul></ul><ul><ul><li>rotateRight, </li></ul></ul><ul><ul><li>reverse, </li></ul></ul><ul><ul><li>signum, and </li></ul></ul><ul><ul><li>reverseBytes. </li></ul></ul>
  44. 44. New Features in J2SE 5.0 <ul><li>Language Features </li></ul><ul><li>Virtual Machine Features </li></ul><ul><li>Performance Enhancements </li></ul><ul><li>Base Libraries </li></ul><ul><li>Integration Libraries </li></ul>
  45. 45. Integration Libraries <ul><li>Remote Method Invocation (RMI) </li></ul><ul><li>Java Database Connectivity (JDBC) </li></ul><ul><li>Java Naming and Directory Interface (JNDI) </li></ul>
  46. 46. Remote Method Invocation (RMI) <ul><li>Dynamic Generation of Stub Classes </li></ul><ul><ul><li>Generation of stub at runtime eliminated the need of stub compiler rmic . </li></ul></ul><ul><li>Standard SSL/TLS Socket Factory Classes </li></ul><ul><ul><li>Standard Java RMI socket factory classes, javax.rmi.ssl.SslRMIClientSocketFactory and javax.rmi.ssl.SslRMIServerSocketFactory added. </li></ul></ul><ul><ul><li>Communicate over the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocols using the Java Secure Socket Extension (JSSE). </li></ul></ul>
  47. 47. Java Database Connectivity (JDBC) <ul><li>RowSet interface has been implemented in five common ways a RowSet object can be used. </li></ul><ul><ul><li>JdbcRowSet - used to encapsulate a result set or a driver. </li></ul></ul><ul><ul><li>CachedRowSet - disconnects from its data source and operates independently except when it is getting data from the data source or writing modified data back to the data source. </li></ul></ul><ul><ul><li>FilteredRowSet - extends CachedRowSet and is used to get a subset of data. </li></ul></ul><ul><ul><li>JoinRowSet - extends CachedRowSet and is used to get an SQL JOIN of data from multiple RowSet objects. </li></ul></ul><ul><ul><li>WebRowSet - extends CachedRowSet and is used for XML data. </li></ul></ul>
  48. 48. Java Naming and Directory Interface (JNDI) <ul><li>Enhancements to javax.naming.NameClassPair to access the fullname from the directory/naming service. </li></ul><ul><li>Support for standard LDAP controls: Manage Referral Control, Paged Results Control and Sort Control. </li></ul><ul><li>Support for manipulation of LDAP names. </li></ul>
  49. 49. Q & A Tiger
  50. 50. Thank You