Presentation is loading. Please wait.

Presentation is loading. Please wait.

1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.

Similar presentations


Presentation on theme: "1162 JDK 5.0 Features Christian Kemper Principal Architect Borland."— Presentation transcript:

1 1162 JDK 5.0 Features Christian Kemper Principal Architect Borland

2 JDK 5.0 and JBuilder Download and configure a JDK5.0 http://java.sun.com/j2se/1.5.0/download.jsp Switch your project to use the new JDK Switch the language level to 5.0 support (generics enabled)

3 Java Language Changes Generics Enhanced For Autoboxing Varargs Enums Metadata

4 Generics Allows programmers to specify the types allowed for Collections Allows the compiler to enforce the type specifications //This should only contain Strings List stringList; //This can only contain Strings List stringList;

5 Generics and JBuilder Introduce Generics Refactoring Allows you to change the use of untyped Collection classes to use generics

6 for (Iterator i = line.iterator(); i.hasNext();) { String word = (String)i.next();... } for (String word : line){... } Enhanced for loop A new language construct for the Iterator pattern:

7 Enhanced for loop and JBuilder Introduce foreach refactoring Changes a regular iterator pattern into the new language construct Works best after making the Iterator itself generic

8 Autoboxing 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;...

9 Autoboxing and JBuilder Introduce Auto(un)boxing Refactoring Allows you to eliminate all boxing and unboxing expression from a Java source file –new Integer(5) –boxedInt.intValue() Generated code in the class file is still the same! So no performance improvement! But: The code is easier to read and maintain

10 void printf(String format, Object...args);... printf(“{0} {1}\n”, “Hello”, “World!”); printf(“PI = {0}”, 3.14159); Varargs Allow a variable number of arguments for methods like printf() or Method.invoke() Internally parameters are an array of Object Compiler constructs the array for the call

11 Enumerations Essentially the “typesafe enum pattern” Simple C-style enumeration Can add behavior to each instance High performance EnumSet implementation using a bit-vector public enum Coin { PENNY(1), NICKEL(5); private final int value; Coin(int value) {this.value = value} }

12 Metadata Ability to decorate Java classes and their members with arbitrary data Retrieve values –From source files –From class files –At runtime using Reflection @Retention(RetentionPolicy.RUNTIME) public @interface Test{}

13 Metadata Auto generate boilerplate code Generate other files: –Deployment descriptor Replace naming patterns public class Foo { public static void bar() {} @Test public static void testBar() {... }

14 API changes Updated APIs to take advantage of new language features: –Generics in the Collection framework –Varargs for System.out.printf(), Method.invoke(), String.format() Other improvements: –boolean String.contains()

15 Concurrency Utilities Powerful framework for concurrent programming Essentially Doug Lea’s Concurrency Utilities rolled into the JDK Updated to take advantage of the new memory model Updated to use generics where possible

16 Concurrency Utilities Task scheduling framework –Single thread, thread pool, multiple threads Synchronization primitives –semaphores, mutexes etc. Locks with timeouts Concurrent collections –Map, List and Queue Atomic variables (references and primitives) –high performance –atomic arithmetic and “compare-and-set”

17 Servicability Agent Allows you to introspect a running VM –Find the process id using jps –Attach to the process –Inspect the stack –Detach to let the process continue

18 Class Data Sharing Shares the data in the runtime class files between multiple instances of the VM Does not work on Windows 95/98/ME Improves startup performance –Shared class data gets memory mapped into each running VM instead of reading from jar and converting Reduces memory footprint –Shared data is ready to be used by HotSpot –Only one in memory representation

19 Garbage Collection Performance improvements: –Parallel collector for server VM on server class machines –Improved defaults for server class machines “Ergonomics” can tune the garbage collector according to specified targets (throughput vs. latency)

20 Questions?

21 Thank You 1162 JDK 5.0 Features Please fill out the speaker evaluation You can contact me further at … Christian.Kemper@borland.com


Download ppt "1162 JDK 5.0 Features Christian Kemper Principal Architect Borland."

Similar presentations


Ads by Google