Skip to content

Instantly share code, notes, and snippets.

@clarenced
clarenced / underscore.java
Created August 11, 2011 14:12
Underscore in integer literals
int one_million = 1_000_000;
@clarenced
clarenced / switch.java
Created August 11, 2011 14:18
Switch with string in Java7
public static void sayHello(String language){
switch(language) {
case "FR" : System.out.println("Bonjour"); break;
case "EN" : System.out.println("Hello World"); break;
case "JP" : System.out.println("Sayonara"); break;
default: System.out.println(" Hello World");
}
}
@clarenced
clarenced / binary.java
Created August 11, 2011 14:31
Binary representation
//Un nombre au format hexa
int hexa = 0x12345;
//Un nombre au format binaire
int binary = 0b01110111;
public static void readFile(String path) {
BufferedReader buffer = null;
try {
buffer = new BufferedReader(new FileReader(path));
String line;
while( (line = buffer.readLine()) != null){
System.out.println(line);
}
} catch (FileNotFoundException fne) {
System.out.println("File Not found");
try(BufferedReader buffer = new BufferedReader(new FileReader(path))){
String line;
while( (line = buffer.readLine()) != null){
System.out.println(line);
}
}
Map<String, Map<String, List<String>>> map = new HashMap<String, Map<String, List<String>>>();
Map<String, Map<String, List<String>>> newmap = new HashMap<>();
catch (IOException|SQLException ex) {
logger.log(ex);
throw ex;
}
catch (IOException ex) {
logger.log(ex);
throw ex;
catch (SQLException ex) {
logger.log(ex);
throw ex;
}
package com.grosdim.randomCallable;
public class CallableExample {
static final int NB_THREADS = 5;
public static class StringCallable implements Callable<String>{
private String stringToUpper;