This page lists some of the main things added to Java in recent releases. By the author of O'Reilly's popular Java Cookbook, this page is maintained (every so often) at http://www.darwinsys.com/whatsnew.html.
This is still not finalized, but will probably include Closures, better support in the JVM for other languages, and lots more.
JavaFX is a new graphics language and API based on the Java machine and runtime. Primarily, it's what we've long needed: a compositional API for Swing and 2D graphics. JavaFX can be used in Applets, in Java WebStart, in desktop applications, and (very importantly) on mobile devices. Scope this out at Sun's new javafx.com site.
Java SE 6 (Java SDK 1.6) continues the trend, but most of the changes are in the libraries; there are no major changes in the language.
For more details, see Sun's Java SE 6 article.
Java 5 (Java SDK 1.5) is now called Java SE (Standard Edition), e.g., the "Java 2" part has been dropped from the name). Java SE 5 features important new features, some of which change the language in ways that are not backwards compatible:
@Override
public boolean equals(Mytype other) { ... }
This code mistakenly overloads rather than overrides; prior to this compile
time annotation (whose full name is java.lang.Override), it would not be noticed
and the code would fail mysteriously much later. With the override, a Java 5 compiler
is obligated to report it as an error!
List list = new ArrayList(); ... String s = (String)list.get(0);can and should be re-written as
List<String> list = new ArrayList<String>(); ... String s = list.get(0);
enum Color {
RED, BLUE, GREEN
};
public static void main(String[] args) {
Color color = Color.RED;
String line = getLine();
if (line != null)
color = Color.valueOf(line);
switch (color) {
case RED:
System.out.println("You like dark apples");
break;
case GREEN:
System.out.println("You like light apples");
break;
case BLUE:
System.out.println("You like blue balloons");
break;
}
}
Old code that uses enum as a variable, as in
Enumeration enum;will have to be changed.
Integer val = new Integer(42); int i = val; System.out.println(i);will now work. For that matter, the first line can be just:
Integer val = 42;
for (Color c : Color.values()) {
...
}
System.out.printf("Hello %s of %s%n", "World", "Java");
String x = String.format("The meaning of the %s is %d?", "universe", 42);
public void process(String line, Integer ... nums) {
for (int i : nums) {
System.out.println("A number is " + i);
}
}
Although Java 4 has been out for a long time, some Java developers still don't know about some of its new features: