Here,if you would observe , there is a repetition of both on the left hand side and right hand side

Hence with Java 1.7 , you don't have to do a repeat on the right hand side
This means you can do something like this on the code

Map<Object,Object> mpObj = new HashMap<>();

Because of the symbol hence created , the name "Diamond Operator" was coined in by Ronaldinho

2.Using Strings in switch statements

Until Java 1.6 , we have only int values (convertible) , enum's as contestants of switch cases . Starting
Java 1.7 , we have even java.lang.String was nominated to be a contestant for the switch cases .

for example :

String caseContestant= "Apple";

switch(caseContestant){ the location i was talking about is this position . This position only convertible intsand enums had the keys to enter into the gates , now in java 1.7 ,duplicate key has been given to even java.lang.String

case "Apple" :
System.out.print("I am apple");
break;

case "Mango" :
System.out.print("I am mango");

break;

}

3. Automatic Resource Management

This means that the management of resources will not be anymore done by developers, but will be
automatically taken care by Java (JVM)

Now the question arises How the hell JVM come to know anything about the elements mentioned in the above argument list separated by semi colons.

The answer to the question is that all of the above mentioned elements in the list implement an interface called java.lang.AutoCloseable . This interface declares a method called "void close() throws Exception" . This method is completely used for management of resources .

4.Numeric literals with underscores

This means that we can have underscores in between the numbers for readability purposes .

int thousand = 1_000 ; We can introduce underscores in between the numbers for readability purposes; still the value remains the same
int tenthousand = 10_000 ;

There is complete change in the framework when it comes to file handling , input/output operations
and others .

All elements that make up the new framework are all placed under the package java.nio .

To give a brief understanding on this , let's try to understand below picture

As described in the above figure , the architecture/framework always gives you a component that is strongly coupled with the underlying architecture. But these components still share a common interface . We will call it as "Platform based architecture" , actually it is Factory Pattern exemplified at its best .Having this in mind lets analyze the new wonderful things that come as part of java.nio

Path

The first change is the introduction of the Path (java.nio.file.path) component in the place of File (java.io)
.And for Paths , Paths (Java.nio.file.Paths) act as the Component provider . The Component structure of the
Path looks like this

Now the component provider for the same would be Paths from java.nio.file package

Hence the file object instantiation which had been like

File file= new File ("fileName");
Would now look like

Path path= new Paths.get("fileName");Paths is the Component provider

Note that there is something common between the above two statements , both are just object /virtual entities . No links exists between these objects and the storage devices , until some action like create ,
delete , modification of the file is done .

For example , in the old API , it would be something like the below to create a file.

file.createNewFile();

In the new API it is something like ,

Files.createFile(path);This being the utility class from the java.nio.file package

Accordingly we have delete,deleteExists,copy,move,createSymbolicLink(for creating shortcut for files) for different actions from the java.nio.file.Files utility class .

File Change Notification:

Consider a scenario :

You as a policeman (the program you write) , call out on a FBI (who is the WatchService in java terms)
to monitor a robber (directory/file) . The FBI informs you back using signals (WatchKeys in this case) .

Steps involved in accomplishing the file notification functionality .

1. Create a WatchService .This service consists of a queue to hold WatchKeys.
2. Register the directory/file you wish to monitor with this WatchService .
3. While registering ,specify the types of events you wish to recieve (create , modify or delete events) .
4. You have to start an infinite loop to listen to events .
5. When an event occurs , a WatchKey is placed into the queue.
6. Consume the WatchKey and invoke queries on it .

This is a mechanism through which you make the best use of the processors available in your systems .Fork a term coined by the UNIX bad boys , saying to create a child process .Join also a term coined by the UNIX bad boys , saying to wait for a child process to complete and join

Following are the steps you do to make the dangerous move with Fork and Join mechanism of Java

Step 1:ForkJoinPool pool = new ForkJoinPool(Runtime.getRunTime().availableProcessors())
The first step informs the master (ForkJoinPool) , the number of processors available in the system for it to manage with .

Step 2:pool.invoke(task);

Here you will give the task you want to be executed to the ForkJoinPool ,and it will take care of delegating this work to the free processor.

About The Author

Subham Mittal has worked in Oracle for 3 years .
For more java articles , follow javahungry @javahungry