Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
J2SE 5.0
Tiger
J2SE Themes
J2SE 1.4.0
(Merlin)
J2SE 5.0
(Tiger)
J2SE 6.0
(Mustang)
Ease of development Quality Monitoring and Manageability Performance and Scalability Desktop Client
Language Features Virtual Machine Features Performance Enhancements Base Libraries Integration Libraries
Language Features Virtual Machine Features Performance Enhancements Base Libraries Integration Libraries
Language Features
Generics Enhanced for Loop Variable Arguments Boxing / Unboxing Type-safe enumerations Static import
Generics
A way to make class type-safe that are written on any arbitrary object type. 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.
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
Iterating over collections is a pain. Often, iterator is unused except to get elements. Iterators are error-prone. Iterator variable occurs three times per loop. Gives you two opportunities to get it wrong. Common cut-and-paste error. Wouldnt it be nice if the compiler took care of the iterator for you?
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(); }
For Arrays
Eliminates array index rather than iterator Similar advantages // Returns the sum of the elements of a
Variable Arguments
To write a method that takes an arbitrary number of parameters, you must use an array. Creating and initializing arrays is a pain. Why not complier take care of it?
Example of a method that takes an arbitrary number of int arguments and returns their sum:
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();
Boxing / Unboxing
Collections hold only objects, so to put primitive data types it needs to be wrapped into a class, like int to Integer. It is a pain to wrap and unwrap. Wouldnt it be nice if the compiler took care of it for you?
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
Type-safe enumerations
Compiler support for Typesafe Enum pattern. Looks like traditional enum (C, C++, Pascal). Far more powerful. Can be used in switch/case statements. Can be used in for loops.
Static import
Ability to access static members from a class without need to qualify them with a class name.
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
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.
Language Features Virtual Machine Features Performance Enhancements Base Libraries Integration Libraries
Class Data Sharing Server-Class Machine Detection Garbage Collector Ergonomics Thread Priority Changes High-Precision Timing Support
Reduces startup time of java applications. Better results for smaller applications. Automatically enabled when conditions allow it to be used. Not supported in Microsoft Windows 95/98/ME.
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 "shared archive".
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.
The footprint cost of new JVM instances has been reduced in two ways. 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. 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.
These savings allow more applications to be run concurrently on the same machine.
At startup Launcher automatically detects if application is running on server-class Machine. Uses Server VM / Client VM accordingly.
Server-class Machine : One with at least 2 CPUs and at least 2GB of physical memory.
Server VM start more slowly than client VM, but over time runs more quickly.
On server-class machines running the server VM, the garbage collector (GC) has changed from the previous serial collector to a parallel collector. Can switch the GC collector mode using the command-line option.
XX:+UseSerialGC XX:+UseParallelGC
Java threads and Native threads to compete on equal footing. Java threads at NORM_PRIORITY can now compete as expected with native threads. Java priorities in the range [10...5] are all mapped to the highest possible TS (timeshare) or IA (interactive) priority. Priorities in the range [1..4] are mapped to correspondingly lower native TS or IA priorities
System.nanoTime() method added. Provides access to nanosecond granularity time source for relative time measurements. The actual precision of the time value returned is platform dependant.
Language Features Virtual Machine Features Performance Enhancements Base Libraries Integration Libraries
Performance Enhancements
Using Client / Server VM accordingly. Default parallel garbage collection on Server VM.
StringBuilder Class
Introduced a new class java.lang.StringBuilder. It is like unsunchronized StringBuffer. Faster than StringBuffer.
Java 2D Technology
Improved acceleration for Buffered Image Objects Support for H/W accelerated rendering using OpenGL. Improved text-rendering performance.
Image I/O
Improved Performance and memory usage while reading and writing JPEG Images. In mage I/O API (javax.imageio) added support for reading and writing BMP and WBMP images.
Language Features Virtual Machine Features Performance Enhancements Base Libraries Integration Libraries
Base Libraries
ProcesBuilder
More convenient way to invoke sub processes than Runtime.exec printf style format strings. Support for layout justification and alignment, common formats for numeric, string and date/time data.
Formatter
Scanner
Converts text into primitives or Strings. regular expression based searches on streams, file data, strings.
Instrumentation
New package java.land.instrument, allows java programming agents to instrument programs running on the Java virtual machine by modifying methods' bytecodes at runtime getState() for querying the execution state of a thread. getStackTrace to obtain stack trace of a thread. A new form of the sleep() method is provided which allows for sleep times smaller than one millisecond.
Threads
Networking
Complete support for IPv6 on Windows XP (sp1) and 2003. ping like feature InetAddress class provides API to test the reachability of a host. Improved Cookie support. Proxy Sever Configuration ProxySelector API provides dynamic proxy configuration.
JAXP 1.3
A built-in validation processor for XML Schema. XSLTC, the fast, compiling transformer, which is now the default engine for XSLT processing. Java-Centric XPath APIs in javax.xml.xpath, which provide a more java-friendly way to use an XPath expression. Grammar pre-parsing and caching, which has a major impact on performance for high-volume XML processing.
The wrapper classes (Integer, Long, Short, Byte, and Char) now support common bit manipulation operations like
highestOneBit, lowestOneBit, numberOfLeadingZeros, numberOfTrailingZeros, bitCount, rotateLeft, rotateRight, reverse, signum, and reverseBytes.
Language Features Virtual Machine Features Performance Enhancements Base Libraries Integration Libraries
Integration Libraries
Remote Method Invocation (RMI) Java Database Connectivity (JDBC) Java Naming and Directory Interface (JNDI)
Generation of stub at runtime eliminated the need of stub compiler rmic. Standard Java RMI socket factory classes, javax.rmi.ssl.SslRMIClientSocketFactory and javax.rmi.ssl.SslRMIServerSocketFactory added. Communicate over the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocols using the Java Secure Socket Extension (JSSE).
RowSet interface has been implemented in five common ways a RowSet object can be used.
JdbcRowSet - used to encapsulate a result set or a driver. 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.
Enhancements to javax.naming.NameClassPair to access the fullname from the directory/naming service. Support for standard LDAP controls: Manage Referral Control, Paged Results Control and Sort Control. Support for manipulation of LDAP names.
Tiger
Q&A
Thank You