Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bart van Kuik Application Developer Oracle Corporation.

Similar presentations


Presentation on theme: "Bart van Kuik Application Developer Oracle Corporation."— Presentation transcript:

1

2 Bart van Kuik Application Developer Oracle Corporation

3 Java 1.5 New Language Features

4 Java 1.5: Tiger  Less boilerplate code through syntax changes  But no new keywords so compatibility with existing code, except the enum keyword

5 Additions to Syntax  Generics  Enhanced for loop  Autoboxing/unboxing  Typesafe enums  Static Imports  Varargs  Metadata

6 Generics  Also called 'parameterized types', since you pass a parameter upon declaration and instantiation: List lijstMetNamen = new ArrayList (); // 1.4: runtime error / 1.5: compiler error lijstMetNamen.add(new Integer(1));  Feature: covariant return types

7 Enhanced for loop // Old syntax with iterators: List list = new ArrayList(); for(Iterator i = list.iterator(); i.hasNext();) { String s = (String) i.next(); System.out.println("String: " + s); } // New syntax List list = new ArrayList (); for (String s : list) { // do something} // The following is also possible: String naam = "Harry"; for (char c : naam.toCharArray()) { // do something }

8 Autoboxing/unboxing  public static void Cow.milk(Integer liter); public static void Monkey.throw(int distance);  From primitive to reference and back: int i = 4; Cow.milk(new Integer(i)); // 1.4 Cow.milk(i); // 1.5 Object obj = new Integer(3); Monkey.throw(((Integer)obj).intValue()); // 1.4 Monkey.throw((Integer)obj); // 1.5  Boxing null gives a NullPointerException

9 Typesafe enum s  Various disadvantages: class Kaart { static final int HARTEN = 0; static final int KLAVEREN = 1; static final int RUITEN = 2; static final int SCHOPPEN = 3; }  New syntax: public enum Kaart { harten, klaveren, ruiten, schoppen }

10 Static Imports  Before 1.5: lots of typing work to get a constant: ErrorConstants.XML_NOT_VALID  New type of import statement: import static com.elsevier.ew.ErrorConstants.*;  Both static attributes and methods

11 Varargs  Pass a variable number of arguments to a method  Like the C function: printf("value: %d", 15);  Compiler now understands this syntax: public static int optellen(int args...) { int resultaat = 0; for(i = 0; i < args.length; i++) restultaat = resultaat + args[i]; }

12 Metadata  Newest addition, separate JSR  Clues for precompilers, testtools, e.d.  C# attribute syntax: [xxx]  Java metadata syntax: @xxx @test public static int add(int... params) { // blah }

13 Conclusie  Gone through the JCP  Early access 2.2 is downloadable  Beta and Final release somewhere in 2004  Big names: Joshua Blog, Neil Gafter

14 A Q & Q U E S T I O N S A N S W E R S

15


Download ppt "Bart van Kuik Application Developer Oracle Corporation."

Similar presentations


Ads by Google