2. Enhanced for Loop The new enhanced for construct lets you iterate over collections and arrays without using iterators or index variables. The new form of the for statement has the following syntax: for (FormalParameter : Expression) Statement
5. The problem here is that an explicit cast is required in the printCollection method. This class compiles fine, but throws a ClassCastException at runtime as it attempts to cast an Integer to a String: Item: Hello world! Item: Good bye! Exception in thread "main" java.lang.ClassCastException: java.lang.Integer at Ex1.printCollection(Ex1.java:16) at Ex1.testCollection(Ex1.java:10) at Ex1.main(Ex1.java:23) Generics, which are also known as parameterized types, provide compile-time typesafety for collections and eliminate the drudgery of casting.
6.
7.
8.
9.
10. Metadata The J2SE 5.0 metadata feature is a facility that allows developers to annotate their code so that tools can generate boilerplate code (e.g stub generation to remote procedure calls) as directed by annotations. This facility allows for parsing of your Java files and generating artifacts such as XML descriptors or source code.
11.
12.
13. Enhanced Input : Prior to J2SE 5.0, in order to read an integer value from the keyboard, it has to be read as a String and then parsed as follows BufferedReader br = new BufferedReader(new InputStreamReader (System.in)); String str = br.readLine(); int n = Integer.parseInt(str); In J2SE 5.0, the java.util.Scanner class can be used to accomplish the same thing but with less code as follows: Scanner reader = new Scanner(System.in); int n = reader.nextInt();