JSE1.5 In A Nutshell

June 01, 2004

JSE1.5 In A Nutshell

I have been wanting to catch up with some of the new features that are being added to J2SE 1.5, but haven't have much time to actually sit down and go through them. A recent article from java.sun.com called "J2SE 1.5 in a Nutshell" caught my eyes, so I decided to read it. I am trying out a new approach where if I would like to remember some of the key points from an article, then I would summarize it in writing similar to a blogging format. So here it is. (BTW this is my first attempt) 


New features of J2SE1.5 can be grouped into the following themes: 


1) Ease of development 

2) Scalability and Performance 

3) Monitoring and Manageability 

4) Desktop Client 

5) Miscellaneous Features 


The following sections will briefly summarize each of the new features in each of the themes 


Ease of development 

================================ 


Metadata 

-------------------------------- 

The ability to associate annotation with Java classes, methods, interfaces, methods and fields. This information can be used by javac or other tools. One example of is for a tool to use the annotation to generate additional source code or provide additional information when debugging. 



Generic Types 

-------------------------------- 

This is concept borrowed from C++ templates. The obvious place to see the benefits of generic types is in the Collection API. This feature will remove the casting when getting an element out of a collection and the collection can be checked for type safety at compile time. This is a really nice feature and developers will like this. Previously some of us wrote our own class to enforce the type, i.e IntegerArrayList. 


Autoboxing 

-------------------------------- 

Converting a primitive type to and from the equivalent wrapper classes is a bit tedious. This feature will leave the job to the compiler to perform the conversion. 


An example from the article: 

-------------------------------- 

ArrayList(Integer) list = new ArrayList<Integer>(); 

List.add(0, new Integer(40)); 

Int total = (list.get(0)).intValue(); 


ArrayList(Integer) list = new ArrayList<Integer>(); 

List.add(0, new Integer(40)); 

Int total = list.get(0); 


Enhanced For Loop 

This feature can be used to traverse through a Collection with style. Developers now can forget about the Iterator.hasNext() and Iterator.next APIs. 


ArrayList<Integer> list = new ArrayList<Integer>(); 

For (Integer I = list) { Â…. } 


The compiler will take care of generating the code to traverse the list. 


Enumerated Types 

-------------------------------- 

This is a convenient feature borrowed from the C language, so one can define a more meaningful type with built in range checking by the compiler. For example: 


public enum MyColor { Red, Green, White, Blue }; 


Static Import 

-------------------------------- 

This is another convenient feature and I really like this one because it allows a class to refer to static constants that are defined in another class or interface with having to extend/implement it. The current practice is to define a set of constants in an interface and the class that would like to use these constants would implements this interface or use fully qualified name. 

With this new feature one can just do this: 


import static java.awt.BorderLayout.*; 


getContentPane().add(new JPanel(), CENTER); 


C Style Formatted Input/Output 

-------------------------------- 

The Formatted Output feature which allow Java developers to have access to the printf-type functionality as in C language to generate formatted output. For example: 


System.out.printf("%s, %5d%n", user, total); 


Output would look something like this: "John Smith, 30.0"; 


The Formatted Input feature will make it easier to read data from the system console or any data stream using the new API from Scanner class. 


Variable Arguments 

-------------------------------- 

Another feature that is borrowed from C language, which will allow a method to accept a variable number of arguments, syntaxttact looks something like this: 


public void myMethod(Object ... args) { 

for (int i = 0; i < args.length; i++) { 



myMethod("one", "two"); 


Concurrency Utilities 

-------------------------------- 

This will be really nice for folks that are really into thread programming, a set of powerful, high level thread construts are being introduced into the Java language. These constructs include executors, thread safe queues, Timers, locks, and others. 


A lot of these are carried over from work that Doug Lea did in his concurrency utility library. 


Simpler RMI Interface Generation 

-------------------------------- 

The dynamica proxyies introduced in JDK 1.3 will obsolete the rmi compiler tool to generate remove interface stubs. 


Scalability and Performance 

================================ 

Some of the work will improve the startup time, memory footprint and make it easier to deploy applications. For a large Java desktop application or application server, this will improve developer productivity. 


Core JVM classes are pre-packed to help improve startup time. 


Much of the work in this feature are behind the scenes, all developers will just feel the different w/o having to do much, which is awesome. 



Monitoring and Manageability 

================================ 

This iniative will try to improve the RAS (Reliability, Availability, Serviceability) the Java platform. 


Using JMX framework, tools will be able to tap into the JVM to do instumentation. MBean can be accessed locally with the same JVM or remotely. 

One can use MBean to detect low memory and notify listeners. 


Remote mamangement of the JVM will available out-of-the-box using jconsole. 


New profiling APIs called JVMTI will added to allow do bytecode instrumentation which is a lot lighter than the existing JVMPI. The will add the flexibility in terms of where and when to perform the instrumentation, for example at runtime, class loading time and pre-processed as class files. 


Diagnostic Ability 

-------------------------------- 

Stack trace can be obtained programmatically using two new APIs, getStrackTrace() and getAllStackTraces() from the current thread. 


Thread.currentThread().getStackTrace() and Thread.getAllStackTraces() 


Desktop Client 

================================ 

A new theme called Ocean has been added to the Swing toolkit. Not sure how nice it is yet, but I am planning to check it out. 


Miscellaneous Features 

================================ 


XML Related 

-------------------------------- 

XML 1.1 with Namespaces and XML schema. Hmmm, wonder what is new in XML schema 1.1? SAX 2.0.2, DOM Level 3 Support and XSLT with a fast compiler. How fast? 

Will have do another blog for this :) 


JDBC RowSets 

-------------------------------- 

Wow, 5 new JDBC RowSet implementations are being added: 


1) JdbcRowSet - encapsulate a result set 

2) CachedRowSet - in-memory and disconnected result set, which can be 

synchronized at a later point. Very cool. 

3) WebRowSet - extends CachedRowSet and can be used to write or read 

the RowSet in XML format. Developers now don't have to write 

custom code generation to generate XML from an application object 

model. 

4) FilteredRowSet - extends CachedRowSet with filtering capabilities 

5) JoinRowSet - extends CachedRowSet that has join capabilities from multiple 

RowSet objects. 


Summary 

================================ 

Wow, that was a long blog. It looks like a bunch of exciting features are being added J2SE1.5, which will improve developer productivity as well as the RAS of the Java platform. I am looking forward to try some of these new features out. Stay tuned for more blogs on Java topic. 


First
0 Komentar