JDK 1.5 Features
1)
Generics
2)
Enhanced For Loop
3)
Autoboxing/Unboxing
4)
TypeSafe enums
5)
Static import
6)
Declarative
programming(Metadata/Annotations)
7)
Concurrent Package
8)
Var args
9)
Scanner
JDK 1.5 Concurrency
Limitations
of JDK 1.4 Synchronization
1.
No
way to back off or wait time out or cancellation once lock is held.
2.
Lock
semantics can not be changed- Re-entrancy, read vs write protection or fairness
3.
No
access control for synchronization
4.
Lock
and unlock cannot be done outside of a method.
Concurrency Features
-
Task scheduling
framework: Executor Framewrok
-
Concurrent
Collections: Queue, Blocking Queue, Concurrent Hahshmap, List and Queue
-
Atomic
Variables: AtomicInteger etc.
-
Locks:
-
Nanonsecond
granularity timing
-
Utility classes
for synchronization
o
Semaphore
o
CyclicBarrier
o
CountDownLatch
o
Exchanger
JDK 7 – New Features
1.
switch
block with string
for (String arg: args) {
switch (arg) {
case "-c": create = true;
break;
case "-v": verbose =
true; break;
case "-d": debug = true;
break;
default:
System.out.println("invalid
option");
System.exit(1);
}
}
2.
Binary
Literals with prefix 0b e.g int number1 =
0b01010000101000101101000010100010;
3.
_
for numerical Literlas
short aShort =
(short)0b0111_0101_0000_0101;
4.
Catching
Multiple Exception Types
try {
......
}
catch(ClassNotFoundException|SQLException ex) {
ex.printStackTrace();
}
5.
The
try-with-resource Statement (Auto-close resources)
public class FileCopyJDK7
{
public static void main(String[] args) {
try (BufferedReader in = new BufferedReader(new
FileReader("in.txt"));
BufferedWriter out = new
BufferedWriter(new FileWriter("out.txt"))) {
int charRead;
while ((charRead = in.read()) != -1) {
System.out.printf("%c ",
(char)charRead);
out.write(charRead);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
6.
Type
Interference for Generic Instance Creation . e.g. List<String> lst1 = new ArrayList<String>();
7.
Fork and Join
JDK 8– New Features
1)
Lambda expressions
btn.setOnAction(new
EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello
World!");
}
});
With lambda in java 8
you just have:
btn.setOnAction(
event -> System.out.println("Hello
World!")
);
2)
Remove the Permanent
Generation
3)
Small VM
4)
Parallel Array Sorting
5)
Bulk Data Operations for
Collections
6)
Define a standard API
for Base64 encoding and decoding
7)
New Date & Time API
8)
Provide stronger
Password-Based-Encryption (PBE) algorithm implementations in the SunJCE
provider
No comments:
Post a Comment