New Feature in Java7
- Strings in switch Statements
- Type Inference for Generic Instance Creation
- Multiple Exception Handling Syntax
- The try-with-resources Statement.
- Improved File IO API
- Support for Non-Java Languages: invokedynamic
- Binary Literal/Underscore in Literals
- Fork-Join
Step 1 : Download JDK7 from the link below –
http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u1-download-513651.html
After downloading the JDK7, execute the file, it will install JDK7 in your directory.
Step 2 : Access your directory and set path for JDK7 –
For example – here we will develop our java programs (based on Java7) in “c:\sun” directory. You may choose any location to write your java programs. We will set path only for this directory.
Alternatively we can do it permanently via environment variables too.
Step 3 : Create a file “Test.java”. Copy and paste the code below –
public class Test{
public static void main(String[]arg){
String type=arg[0];
switch(type){
case "Hello":
System.out.println("You input- Hello");
break;
case "Hi":
System.out.println("You input- Hi");
break;
default:
System.out.println("Oh! come on!");
}
}//main method
}//Test class
Step 4 : Compile and run the program as follows.
The string handling in switch..case is introduced first time ever in JDK. So the program above will not be compiled in the version below JDK7. Try to run the same program using JDK6