+ All Categories
Home > Documents > 1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.

1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.

Date post: 01-Jan-2016
Category:
Upload: amos-garrison
View: 223 times
Download: 1 times
Share this document with a friend
21
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland
Transcript

1162JDK 5.0 Features

Christian KemperPrincipal Architect

Borland

JDK 5.0 and JBuilder

Download and configure a JDK5.0http://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)

Java Language Changes

Generics

Enhanced For

Autoboxing

Varargs

Enums

Metadata

GenericsAllows programmers to specify the types

allowed for Collections

Allows the compiler to enforce the type specifications

//This should only contain StringsList stringList;

//This can only contain StringsList<String> stringList;

Generics and JBuilder

Introduce Generics Refactoring

Allows you to change the use of untyped Collection classes to use generics

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:

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

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

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

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

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}}

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{}

Metadata

Auto generate boilerplate code

Generate other files:– Deployment descriptor

Replace naming patternspublic class Foo { public static void bar() {} @Test public static void testBar() { ... }}

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()

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

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”

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

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

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)

Questions?

Thank You

1162

JDK 5.0 Features

Please fill out the speaker evaluation

You can contact me further at …[email protected]


Recommended