JDK 1.5 Features

Allows programmers to specify the types allowed for Collections
Allows the compiler to enforce the type specifications
List stringList
//In JDK 1.5
List<String> stringList;
2.Enhanced for loop
A new language constuct for the Iterator pattern
for(Iterator i = line.iterator();i.hasNext(); )
  String word = (String)i.next();
//In JDK 1.5
for(String word: line)
Essentially bridges between the “primitive” types (such as int, boolean) and the
“boxed” types (such as Integer, Boolean)

int primitive = 5;
Integer boxed = primitive;
int unboxed = boxed + 5;

Allow a variable number of arguments for methods like printf() or Method.invoke()
Internally parameters are an array of Object
Compiler constructs array for the call
void printf(String format, Object…args);

printf(“{0} {1}\n”, “Hello”, “World”);
printf(“PI = {0}”, 3.14159);
Essentially the “typesafe enum pattern”.
Simple C-style enumeration
Can add behavior to each instance
High peformance EnumSet implementaion using a bit-vector

public enum Coin {
private final int value;
Coin(int value) {this.value = value}

Ability to decorate Java classes and their members with arbitrary data
Retrieve values
– From source files
– From class files
– At runtime using Reflection
public @interface Test{}