Map<String, List<String>> employeeRecords = new HashMap<String, List<String>>();
List<Integer> primes = new ArrayList<Integer>();
Map<String, List<String>> employeeRecords = new HashMap<>();
List<Integer> primes = new ArrayList<>();
switch (day) {
case "NEW":
System.out.println("Order is in NEW state");
break;
case "CANCELED":
System.out.println("Order is Cancelled");
break;
case "REPLACE":
System.out.println("Order is replaced successfully");
break;
case "FILLED":
System.out.println("Order is filled");
break;
default:
System.out.println("Invalid");
}
public static void main(String args[]) {
FileInputStream fin = null;
BufferedReader br = null;
try {
fin = new FileInputStream("info.xml");
br = new BufferedReader(new InputStreamReader(fin));
if (br.ready()) {
String line1 = br.readLine();
System.out.println(line1);
}
} catch (FileNotFoundException ex) {
System.out.println("Info.xml is not found");
} catch (IOException ex) {
System.out.println("Can't read the file");
} finally {
try {
if (fin != null)
fin.close();
if (br != null)
br.close();
} catch (IOException ie) {
System.out.println("Failed to close files");
}
}
}
public static void main(String args[]) {
try (FileInputStream fin = new FileInputStream("info.xml");
BufferedReader br = new BufferedReader(new InputStreamReader(fin));) {
if (br.ready()) {
String line1 = br.readLine();
System.out.println(line1);
}
} catch (FileNotFoundException ex) {
System.out.println("Info.xml is not found");
} catch (IOException ex) {
System.out.println("Can't read the file");
}
}
int billion = 1_000_000_000; // 10^9
long creditCardNumber = 1234_4567_8901_2345L; //16 digit number
long ssn = 777_99_8888L;
double pi = 3.1415_9265;
float pif = 3.14_15_92_65f;
double pi = 3._1415_9265; // 소수점 뒤에 _ 붙일 경우
long creditcardNum = 1234_4567_8901_2345_L; // 숫자 끝에 _ 붙일 경우
long ssn = _777_99_8888L; // 숫자 시작에 _ 붙일 경우
try {
//......
} catch(ClassNotFoundException ex) {
ex.printStackTrace();
} catch(SQLException ex) {
ex.printStackTrace();
}
try {
//......
} catch (ClassNotFoundException | SQLException ex) {
ex.printStackTrace();
}
//////////////////////////////////////////////////////////////////////////////
//Multi-Catch 구문 사용시 Exception들이 하위클래스 관계라면 컴파일 에러가 발생한다 //
//////////////////////////////////////////////////////////////////////////////
try {
//...... }
catch (FileNotFoundException | IOException ex) {
ex.printStackTrace();
}
Alternatives in a multi-catch statement cannot be related by sub classing, it will throw error at compile time :
java.io.FileNotFoundException is a subclass of alternative java.io.IOException at Test.main
16진법은 0X 또는 0x
int mask = 0b01010000101;
int binary = 0B0101_0000_1010_0010_1101_0000_1010_0010; // _를 이용한 가독성 향상!
public void obscure() throws Exception {
try {
new FileInputStream("abc.txt").read();
new SimpleDateFormat("ddMMyyyy").parse("12-03-2014");
} catch (Exception ex) {
System.out.println("Caught exception: " + ex.getMessage());
throw ex;
}
}
public void precise() throws ParseException, IOException {
try {
new FileInputStream("abc.txt").read();
new SimpleDateFormat("ddMMyyyy").parse("12-03-2014");
} catch (Exception ex) {
System.out.println("Caught exception: " + ex.getMessage());
throw ex;
}
}