Created
May 1, 2012 17:33
-
-
Save sanaulla123/2569878 to your computer and use it in GitHub Desktop.
Project Coin- Java 7 language enhancements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
/** | |
* Created by IntelliJ IDEA. | |
* User: mohamed | |
* Date: 1/5/12 | |
* Time: 8:49 PM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class Java7FeatureDemo { | |
public static void main(String[] args){ | |
/* | |
Diamond Operator | |
*/ | |
//Pre Java 7 style of declaration | |
Map<String, List<Integer>> myMap = new HashMap<String, List<Integer>>(); | |
// Warning issued by compiler | |
Map<String, List<Integer>> myMap2 = new HashMap(); | |
// Java 7 language enhancement - Generic type inference. | |
Map<String, List<Integer>> myMap3 = new HashMap<>(); | |
/* | |
Strings in Switch statements. | |
*/ | |
String choice = "A"; | |
switch (choice){ | |
case "A": | |
System.out.println("A chosen"); | |
break; | |
case "B": | |
System.out.println("B chosen"); | |
break; | |
case "C": | |
System.out.println("C chosen"); | |
break; | |
} | |
/* | |
Multi catch blocks | |
*/ | |
try { | |
exceptionThrowingMethod1(); | |
} catch (IOException | NoSuchFieldException e){ | |
e.printStackTrace(); | |
} | |
/* | |
Binary Integral literals | |
*/ | |
int binary1 = 0b011; | |
int binary2 = 0B111; | |
int hex1 = 0x31; | |
System.out.println(binary1); | |
System.out.println(hex1); | |
System.out.println(binary2); | |
/* | |
Underscores in Integer literals | |
*/ | |
// Pre Java 7 | |
int hugeNumber = 1000000000; | |
// In Java 7 | |
int hugeNumber2 = 1_000_000_000; | |
System.out.println(hugeNumber == hugeNumber2); | |
} | |
static void exceptionThrowingMethod1() throws IOException, NoSuchFieldException{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment