Java 8
Upcoming release, not
yet final.
Language changes:
·
continuation of
Project Coin (small language improvements)
·
annotations on Java
types
Library changes:
Java 7
Language changes:
·
Project Coin (small
changes)
·
switch on Strings
Library changes:
·
improved concurrency
libraries
·
elliptic curve
encryption
·
more incremental
upgrades
Platform changes:
Java 6
Mostly
incremental improvements to existing libraries, no new language features
(except for the@Override snafu).
Java 5
Language Changes:
·
varargs, enhanced for
loops (for-each)
Library changes:
·
concurrency utilities
in java.util.concurrent
Java 1.4
Language changes:
Library changes:
·
NIO
·
integrated XML
handling
Java 1.3
Mostly minor
improvements, really.
Platform changes:
·
HotSpot JVM:
improvement over the original JIT
Java 1.2
Language changes:
Library changes:
Platform changes
·
a real JIT, greatly
improving speed
Java 1.1
Language changes:
·
inner classes
Library changes:
·
AWT event changes
·
JDBC, RMI
·
reflection
Java 1.0
Initial
release, everything is new ;-)
Code examples for new features in Java 1.7
Most of what is below come from the excellent article from Joe Wright on his blog about New language features in Java 7
Language support for collections
This is all about writing less code when you create a List, a Set or a Map. You don't have to instantiate the Object and then add the element to the Collection. You can now do it in 1 line.
List<String> list = ["item"];
String item = list[0];
Set<String> set = {"item"};
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
List<String> list = ["item"];
String item = list[0];
Set<String> set = {"item"};
Map<String, Integer> map = {"key" : 1};
int value = map["key"];
Automatic Resource Management
Annoyed to have verbose code because of try / catch statement. You will love this one.
Indeed, this:
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
br.close();
}
Become this:
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
try (BufferedReader br = new BufferedReader(new FileReader(path)) {
return br.readLine();
}
Improved Type Inference for Generic Instance Creation (diamond)
Same thing, today you specify the Generic when you declare the interface of your object and then you have to repeat yourself when you instantiate the object. You won't have to now as you can do:
Map<String, List<String>> map = new HashMap<>();
Map<String, List<String>> map = new HashMap<>();
Underscores in numeric literals
Not sure this one will be useful to lot of people. You can do:
int billion = 1_000_000_000;
int billion = 1_000_000_000;
Strings in switch
Nothing to explain here, the title says it all.
String availability = "available";
switch(availability) {
case "available":
//code
break;
case "unavailable":
//code
break;
case "merged":
//code
default:
//code
break;
}
String availability = "available";
switch(availability) {
case "available":
//code
break;
case "unavailable":
//code
break;
case "merged":
//code
default:
//code
break;
}