본문 바로가기
비트 장기/JAVA

7/23 (exception 예외처리 try catch)

by woohyun22 2018. 7. 23.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package pack;
import java.util.Random;
import java.util.Scanner;
class Tiger{
    String name;
    String address;
    int age;
    void func01() { System.out.println("호랑이"); }
}
public class Hello {
    
    /*    public static void main(String[] args)throws Exception {
        //throws ex ctrl space
        Thread.sleep(1000);
        //exception이 떳을때 catch를 할 수 없다. 간단하게 쓰기용 
        //보통은 try catch를 자주씀
     */
    public static void main(String[] args)/*throws Exception*/ {
        //throws ex ctrl space
        //try { Thread.sleep(1000);}catch (Exception e) {}
        try { Thread.sleep(1000); } catch (Exception e) {}
        //ctrl alt j 한줄만들기
    }
    //exception이 떳을때 catch를 할 수 없다. 간단하게 쓰기용 
    //보통은 try catch를 자주씀
 
}
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package pack;//getset함수
import java.util.Random;
import java.util.Scanner;
class Tiger{
    private String name = "호랑이";//private는 우리집만 쓸수있다.
    private String address;
    private int age;
    void setAge(int age) {//두단어 합칠때는 뒤에 첫단어도 대문자로
        this.age = age;//이렇게 함수로 우회해서 간접적으로 사용 private는 직접적으로 사용
    }
    void setName(String name) {
        this.name = name;
    }
    void setAddress(String address) {
        this.address = address;
    }
    int getAge() {
        return age;
    }
    String getName() {
        return name;
    }
    String getAddress() {
        return address;
    }
    void func01() { System.out.println("호랑이"); }
}
public class Hello {
    
    /*    public static void main(String[] args)throws Exception {
        //throws ex ctrl space
        Thread.sleep(1000);
        //exception이 떳을때 catch를 할 수 없다. 간단하게 쓰기용 
        //보통은 try catch를 자주씀
     */
    public static void main(String[] args)/*throws Exception*/ {
        //throws ex ctrl space
        //try { Thread.sleep(1000);}catch (Exception e) {}
        try { Thread.sleep(1000); } catch (Exception e) {}
        Tiger t1 = new Tiger();
        /*t1.name = "호랑이";
        t1.address = "김해시";
        t1.age = 25;*/
        //ctrl alt j 한줄만들기
        t1.setAge(999);
        System.out.println(t1.getAge());
        t1.setName("우현");
        System.out.println(t1.getName());
        t1.setAddress("김해시");
        System.out.println(t1.getAddress());
        
    }
    //exception이 떳을때 catch를 할 수 없다. 간단하게 쓰기용 
    //보통은 try catch를 자주씀
 
}
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package pack;//getter setter함수 자바bean
import java.util.Random;
import java.util.Scanner;
class Tiger{
    private String name = "호랑이";//private는 우리집만 쓸수있다.
    private String address;
    private int age;
    
    // 오른쪽클릭source getter setter
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getAddress() { return address; }
    public void setAddress(String address) { this.address = address; }
    public int getAge() { return age; }
    public void setAge(int age) { this.age = age;System.out.println("아"); }
    
}
public class Hello {
    
    /*    public static void main(String[] args)throws Exception {
        //throws ex ctrl space
        Thread.sleep(1000);
        //exception이 떳을때 catch를 할 수 없다. 간단하게 쓰기용 
        //보통은 try catch를 자주씀
     */
    public static void main(String[] args)/*throws Exception*/ {
        //throws ex ctrl space
        //try { Thread.sleep(1000);}catch (Exception e) {}
        short a = 10;//일반 type .변수 단독으로 사용
        Short b = 20;//Short라는 class .객체 .써서 함수사용
        float c = 3.14f;
        Float d = 3.14f;
        int f = 10;
        //제일마니 씀 Integer 
        long e = 40l;//long타입 일때는 뒤에 l은적는다.
        Long z = 200l; //wrapper boxing
        String s = "1234";
        int num = Integer.parseInt(s);
        System.out.println(s+100);
        System.out.println(num+100);
        String s1 = Integer.toString(num);//Integer 상호작용을 함
        System.out.println(s1);
        String s2 = num + " "
        System.out.println(s2);
        //양쪽에서 원하는 형식이 다르기 때문에 사용
        
        
    }
    //exception이 떳을때 catch를 할 수 없다. 간단하게 쓰기용 
    //보통은 try catch를 자주씀
 
}
cs


728x90

'비트 장기 > JAVA' 카테고리의 다른 글

7/24 복습  (0) 2018.07.25
7/24 배움  (0) 2018.07.24
7/21 배움 (추상class, )  (0) 2018.07.21
7/20 복습  (0) 2018.07.20
7/19 배움(상속, overriding, 다형성 )  (0) 2018.07.19

댓글