Created
July 17, 2011 11:51
-
-
Save rhmoller/1087499 to your computer and use it in GitHub Desktop.
Java 7: Project Coin Examples
This file contains hidden or 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
public void createGenerics() { | |
List<String> list = new ArrayList<String>(); | |
Map<String, List<String>> keyValues = new HashMap<String, List<String>>(); | |
} | |
public void createWithDiamondOperator() { | |
List<String> list = new ArrayList<>(); | |
Map<String, List<String>> keyValues = new HashMap<>(); | |
} |
This file contains hidden or 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
public void multiCatch(Class<MultiCatch> myClass) { | |
try { | |
Method method = myClass.getMethod("sayHello"); | |
} catch (NoSuchMethodException | SecurityException e) { | |
// common exception handling logic | |
} | |
} |
This file contains hidden or 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
public void numericLiterals() { | |
int mask1 = 0b1000100010001000; | |
int mask2 = 0b1000_1000_1000_1000; | |
int color = 0xff_f0_fe_ff; | |
int price = 1_000_000; | |
double PI = 3.141_592_653_589_793d; | |
} |
This file contains hidden or 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
public void executeCommand(String command) { | |
switch (command) { | |
case "start": | |
startService(); | |
break; | |
case "stop": | |
stopService(); | |
break; | |
case "status": | |
showStatus(); | |
break; | |
default: | |
unknownCommand(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment