Posted By:
4 Nov, 2014 1:01 am PST

Recenet Advancements in Java(2014) with overview of available versions

Overview of various Java versions and their features

 

Java SE 8

Java 8 was released on 18 March 2014. The code name culture is dropped with Java 8 and so no official code name going forward from Java 8.

 

New features in Java SE 8:

  • Lambda Expressions
  • Pipelines and Streams
  • Date and Time API
  • Default Methods
  • Type Annotations
  • Nashhorn JavaScript Engine
  • Concurrent Accumulators
  • Parallel operations
  • PermGen Error Removed
  • TLS SNI

 

Java Version SE 7

Code named Dolphin and released on July 28, 2011.

 

New features in Java SE 7:

  • Strings in switch Statement
  • Type Inference for Generic Instance Creation
  • Multiple Exception Handling
  • Support for Dynamic Languages
  • Try with Resources
  • Java nio Package
  • Binary Literals, underscore in literals
  • Diamond Syntax
  • Automatic null Handling

 

Java Version SE 6

Code named Mustang and released on December 11, 2006.

 

New features in Java SE 6:

  • Scripting Language Support
  • JDBC 4.0 API
  • Java Compiler API
  • Pluggable Annotations
  • Native PKI, Java GSS, Kerberos and LDAP support.
  • Integrated Web Services.
  • Lot more enhancements.

 

J2SE Version 5.0

Code named Tiger and released on September 30, 2004.

 

New features in J2SE 5.0:

  • Generics
  • Enhanced for Loop
  • Autoboxing/Unboxing
  • Typesafe Enums
  • Varargs
  • Static Import
  • Metadata (Annotations)
  • Instrumentation

 

J2SE Version 1.4

Code named Merlin and released on February 6, 2002 (first release under JCP).

 

New features in J2SE 1.4:

  • XML Processing
  • Java Print Service
  • Logging API
  • Java Web Start
  • JDBC 3.0 API
  • Assertions
  • Preferences API
  • Chained Exception
  • IPv6 Support
  • Regular Expressions
  • Image I/O API

 

J2SE Version 1.3

Code named Kestrel and released on May 8, 2000.

 

New features in J2SE 1.3:

  • Java Sound
  • Jar Indexing

 

J2SE Version 1.2

Code named Playground and released on December 8, 1998.

 

New features in J2SE 1.2:

  • Collections framework.
  • Java String memory map for constants.
  • Just In Time (JIT) compiler.
  • Jar Signer for signing Java ARchive (JAR) files.
  • Policy Tool for granting access to system resources.
  • Java Foundation Classes (JFC) which consists of Swing 1.0, Drag and Drop, and Java 2D class libraries.
  • Java Plug-in
  • Scrollable result sets, BLOB, CLOB, batch update, user-defined types in JDBC.
  • Audio support in Applets.

 

JDK Version 1.1

Released on February 19, 1997

 

New features in JDK 1.1:

  • JDBC (Java Database Connectivity)
  • Inner Classes
  • Java Beans
  • RMI (Remote Method Invocation)
  • Reflection (introspection only)

 

JDK Version 1.0

Codenamed Oak and released on January 23, 1996.

 

 

KEY NEW FEATURES IN THE LATEST JAVA VERISONS

 

 

Diamond Operator

Diamond operator is one of the most important features of Java 7 feature set. When we use generics and declare a map, then we need to specify the types on both the sides as shown below which was redundant, but in Java 7 we don't need to declare the types at right hand side. For example, if we have to declare a map of trades using Generics, we write the code as follows:

 

Before Java 7:

 

List<String> al=new ArrayList<String>();

 

In 7, it's written like this:

 

List<String> al=new ArrayList<>();

 

We don't have to type the whole list of types for the instantiation. Instead we use the <> symbol, which is called diamond operator.

 

For example,

Map<String, List<Trade>> trades = new TreeMap <> ();

 

 

Using strings in switch statements

Switch statements work either with primitive types or enumerated types. Java 7 introduced another type that we can use in Switch statements: the String type. This is a very good feature as lot of times we have Strings as key to match and we often work out if-else and equals for the check. But now we can directly use Strings in switch statement, so that we can use Switch functionality to fullest.

 

public class JavaSevenSwitch {

          public static void main(String[] args) {

                    String s = "java";

                    // switch allows string from java7

                    switch (s) {

                    case "java":

                              System.out.println("This is java");

                              break;

                    case ".net":

                              System.out.println("This is .net");

                              break;

                    }

          }

}

 

 

Automatic resource management

Resources such as Connections, Files, Input/Output Streams, etc. should be closed manually by the developer by writing bog-standard code. Usually we use a try-finally block to close the respective resources.

 

Before Java 7:

 

try {

 

FileOutputStream fos = new FileOutputStream("file.txt");

 

DataOutputStream dos = new DataOutputStream(fos);

 

 

} catch (IOException e) {

 

 

} finally {

 

try {

 

 

 

} catch (IOException e) {

 

// log the exception

}

}

 

However, Java 7 introduced a feature to manage the resources automatically. It is simple in operation, too. All we have to do is declare the resources in the try as follows:

 

try (FileOutputStream fos = new FileOutputStream("file.txt"); DataOutputStream dos = new DataOutputStream(fos)) { dos.writeUTF("test");

 

} catch (IOException e) {

 

// log the exception

 

}

 

 

Numeric literals with underscores

This is another excellent usability feature in java 7, which allows the user to add any number of underscores which can appear anywhere between the digits in a numeric literal. As shown below we are separating group of digits in numeric literals which is improving the readability of the number.

 

But there are some rules for adding underscores between digits.

 

 

 

 

int thousand = 1_000;

int million = 1_000_000;

 

 

Improved exception handling

Sometimes we need to handle lot of exceptions for which we need to have multiple catch statements, one for each exception we handle. However, in java 7 that is not the case anymore, as we can add multiple exceptions using the pipe.

 

Let's say we have a method that throws three exceptions. In the current state, we would deal them individually as shown in below:

 

//Multiple exception catch in single catch statement using "|" symbol.

catch(ArithmeticException|NumberFormatException|NullPointerException|IOException e)

{

}

 

 

File change Notifications

The long awaited and very much useful feature of notifications when a file change is done was also introduced in Java 7. When any file or directory changes, the changes or the events are notified using the API WatchService.

 

The steps involved in implementing the API are:

  • Create a WatchService. This service consists of a queue to hold WatchKeys.
  • Register the directory/file we wish to monitor with this WatchService.
  • While registering, we specify the types of events we wish to receive (create, modify or delete events).
  • We have to start an infinite loop to listen to events.
  • When an event occurs, a WatchKey is placed into the queue that consumes the WatchKey and invoke queries on it.

 

Let's follow this via an example. We create a DirPolice Java program whose responsibility is to police a particular directory. The steps are provided below:

 

 

WatchService watchService = FileSystems.getDefault().newWatchService();

 

 

path = Paths.get("C:\Temp\temp\");

 

 

 

These are java.nio.file.StandardWatchEventKinds event types

 

 

while(true) {

WatchKey key = watchService.take(); // this would return the keys …

}

 

 

for (WatchEvent<?> event : key.pollEvents()) {

 

Kind<?> kind = event.kind();

 

}

 

For example, if we modify or delete the temp directory, we would see statement as shown below on the console respectively:

 

Event on temp is ENTRY_MODIFY

 

Event on temp is ENTRY_DELETE

 

 

Fork and Join

The effective use of parallel cores in a Java program has always been a challenge. There were few home-grown frameworks that would distribute the work across multiple cores and then join them to return the result set. Java 7 has incorporated this feature as a Fork and Join framework.

 

Basically the Fork-Join breaks the task at hand into mini-tasks until the mini-task is simple enough that it can be solved without further breakups. It’s like a divide-and-conquer algorithm. One important concept to note in this framework is that ideally no worker thread is idle. They implement a work-stealing algorithm in that idle workers “steal” the work from those workers who are busy.

 

The core classes supporting the Fork-Join mechanism are ForkJoinPool and ForkJoinTask. The ForkJoinPool is basically a specialized implementation of ExecutorService implementing the work-stealing algorithm we talked about above.

 

We create an instance of ForkJoinPool by providing the target parallelism level — the number of processors as shown below:

 

ForkJoinPool pool = new ForkJoinPool(numberOfProcessors)

Where numberOfProcessors = Runtime.getRunTime().availableProcessors();

 

However, the default ForkJoinPool instantiation would set the parallelism level equal to the same number obtained as above.

 

The problem that needs to be solved is coded in a ForkJoinTask. However, there are two implementations of this class out of the box: the RecursiveAction and RecursiveTask. The only difference between these two classes is that the former one does not return a value while the latter returns an object of specified type.

 

Here’s how to create a RecursiveAction or RecursiveTask class that represents the requirement problem:

 

public class MyBigProblemTask extends RecursiveAction {

 

    @Override

 

    protected void compute() {

        . . . // problem invocation goes here

    }

}

We have to override the compute method wherein we need to provide the computing functionality. Now, provide this ForkJoinTask to the Executor by calling invoke method on the ForkJoinPool:

 

 

 

Supporting dynamism

Java is a statically typed language — the type checking of the variables, methods and return values is performed at compile time. The JVM executes this strongly-typed bytecode at runtime without having to worry about finding the type information.

 

There’s another breed of typed languages — the dynamically typed languages. Ruby, Python and Clojure are in this category. The type information is unresolved until runtime in these languages. This is not possible in Java as it would not have any necessary type information.

 

Although it is possible to run these languages on a JVM (using Reflection), it’s not without constraints and restrictions.

 

In Java 7, a new feature called invokedynamic was introduced. This makes VM changes to incorporate non-Java language requirements. A new package, java.lang.invoke, consisting of classes such as MethodHandle, CallSite and others, has been created to extend the support of dynamic languages.

 

 

JLayerPane

Java introduced another great feature for swing UI developer – JLayeredPane. With the use of JLayeredPane we can draw on the top of a component and handle the events without actually modifying the underlying component. This is a great feature because it can be used in many effects such as transition, blur, spotlight etc.

 

 

Binary Literals

Binary literals were also introduced in the java 7 release, so developers don't have to convert them to hexadecimals any more.

 

Before Java 7:

 

 

But this is slow and could throw runtime exceptions.

 

In Java 7:

 

int binary = 0b101010; // Much easier

 

 

 

Simplified Varargs Method Invocation

When a programmer tries to invoke a varargs method with a non-reifiable varargs type, the compiler currently generates an “unsafe operation” warning. JDK 7 moves the warning from the call site to the method declaration. This will enable API designers to use varargs due to the reduction of warnings reported.

 

Major Advantage: Safely and significantly reduces the total number of warnings reported to and suppressed by programmers.

Attachment:None



Please login to reply to this problem.