- Try with Resources
- Multi Catch Statements
- Diamond Syntax
- Binary Literals
- Underscore Between Literals
- String in Switch
import java.io.*;
import java.awt.Color;
import java.util.*;
public class Test {
public static void main(String[] args)throws IOException {
try{
try (FileInputStream in = new FileInputStream(args[0])) { // Try with Resources
int i = in.read();
}
} catch(FileNotFoundException | ArrayIndexOutOfBoundsException e) { // Multi Catch Statements
e.printStackTrace();
}
List<Color> colors = new ArrayList<>(); // Diamond Syntax
int no = 4 << 1;
int bi8 = 0b1000; // Binary Literals
System.out.println(" 4 << 1 == 0b1000 > "+(no == bi8));
int oldOneMillion = 1000000;
int newOneMillion = 1_000_000; // Underscore Between Literals
System.out.println("1000000 == 1_000_000 ? "+(oldOneMillion == newOneMillion));
/* String in Switch */
final String RED = "Red";
final String GREEN = "Green";
final String BLUE = "Blue";
Scanner sn = new Scanner(System.in);
System.out.print("Enter choice (Red, Green, Blue): ");
String input = sn.nextLine();
switch(input) {
case RED :
colors.add(Color.RED);
break;
case GREEN :
colors.add(Color.GREEN);
break;
case BLUE :
colors.add(Color.BLUE);
break;
default :
System.out.println("None");
}
}
}
Great Features, Thanks Sun/Oracle Engineers. Hope you all fix the minor bugs soon!
No comments:
Post a Comment