catch
-
Java - Java I/OJava 2018. 2. 1. 12:16
// Java I/O// Data의 흐름을 Stream이라 한다.// Byte Base -> Input Stream, Output Stream// Character Base -> Reader, Writer import java.io.IOException;import java.io.InputStream;public class SysInput { public static void main(String[] args) { System.out.println("아무거나 입력하십쇼 : "); InputStream is = System.in; int ascii; try { ascii = is.read(); // input으로 받는 int형 메서드 System.out.println(ascii);..
-
Java - ThreadJava 2018. 1. 30. 14:57
// Thread는 어떤 program을 실행 하게 해주는 원동력이다// 대표적으로 main(String[] args)로 실행 한다. // process는 1개 이상의 thread로 구성되어 있다.// process는 thread로 구성 된다.// 메모리 공유 부분에서 process는 메모리 공유가 안되지만,// Thread는 메모리 공유가 된다. // main method는 main thread를 생성 한다.// 처리가 버거우면 work thread를 생성할 수 있다.// 이것을 multi thread라 한다. // Runnable Interface, Thread Class 상속으로 생성할 수 있다. public class Main { public static void main(..
-
Java - throwsJava 2018. 1. 23. 10:33
public class Main { public static void main(String[] args) throws Exception { // jvm으로 exception 넘기기 Sub sub = new Sub(); sub.method1(); // jvm은 exception 메세지만 출력 } } public class Sub { public void method1() throws Exception { // NumberFormatException, Main으로 넘기기 method2(); } public void method2() throws Exception { // 호출 되었던 method()1로 넘기기 Integer.parseInt("sdasd"); // NumberFormatEx..
-
Java - Try, CatchJava 2018. 1. 23. 08:58
public class Main { public static void main(String[] args) { String data1 = "12345"; String data2 = "asdfg"; try {//예외 발생이 예상되는 지점 int val1 = Integer.parseInt(data1); int val2 = Integer.parseInt(data2); }catch(NumberFormatException e) {//NumberFormatException 발생시 실행 할 코드 System.out.println("입력된 값에 문자가 있는지 확인 해 주세요"); System.out.println(e.toString()); }finally {//예외 발생에 상관 없이 무조건 실행 System.out.pr..