Tommy's Blog

Developer's Home

导航

JDK 1.5 notable new features..

Posted on 2004-12-20 15:14  Tommy's Blog  阅读(492)  评论(0编辑  收藏  举报

Some new features in JDK which maybe quite useful...

1. Generic Types

ArrayList<Integer> list =  new ArrayList<Integer>();
   list.add(0, new Integer(42));
   int total = list.get(0).intValue();

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

 

3. New loops

ArrayList<Integer> list = new ArrayList<Integer>();
  for (Iterator i = list.iterator(); i.hasNext();) {
         Integer value=(Integer)i.next();
    }

4. variable number of arguments

void argtest(Object ... args) {
      for (int i=0;i <args.length; i++) {
      }
    }
   
    argtest("test", "data");


5. AWT/Swing
 

AWT

Version 5.0 features many AWT enhancements and bug fixes, including some that have often been requested by our customers. Most notably, the new MouseInfo class makes it possible to determine the mouse location on the desktop. New Window methods make it possible to specify the default location for a newly created window (or frame), appropriate to the platform. Another Window enhancement makes it possible to ensure that a window (or frame) is always on top. (This feature does not work for some window managers on Solaris/Linux.) In the area of data transfer, the new DropTargetDragEvent API allows the drop target to access transfer data during the drag operation.

Swing

With the 1.4.2 release we provided two new look and feels for Swing: XP and GTK. Rather than taking a break, in 5.0 we're providing two more look and feels: Synth, a skinnable look and feel, and Ocean, a new theme for Metal. Beyond look and feels, we've added printing support to JTable, which makes it trivial to get a beautiful printed copy of a JTable. Lastly, after seven years, we've made jFrame.add equivalent to jFrame.getContentPane().add().