본문 바로가기
Java/Java 인강

Java 인강 필기9

by code2772 2022. 10. 2.

[ 목차 ]

    728x90
    반응형
    (22.8.3)
    
    # 31강 기본 API클래스 알아보기
    
    
    
    - API - 자바에서 개발자들을 위해 기본적으로 제공하는 클래스
    
    ​
    
    - object 틀래스 - 모든 클래스의 조상 클래스,
    
    ​
    
    - 문자열 클래스 - 문자열에 대한 다양한 처리를 위한 다양한 메서드가 정의
    
    ​
    
    - strinfBuffer 클래스 - string 클래스는 변하지 않는 객체이기 때문에, 자주 사용할수록 인스턴스를 만들기 때문이다, 따라서 이런 단점을 보완하기 위한 클래스이다.
    
    ​
    
    - StringTokenizer 클래스
    
    ​
    
    - nextToken() - 다음 토큰으로 이동
    
    - hashMoreTokens() - 다음 토큰이 존재하면 트루, 존재하지 않으면 펠스
    
    - countTokens() - 남은 토큰의 개수
    
    ​
    
    package day31;
    
    ​
    
    public class Day31_1 {
    
    ​
    
    public static void main(String[] args) {
    
    String str = "hello";
    
    //concat
    
    System.out.println(str.concat("world"));
    
    System.out.println("hello");
    
    //substring(시작위치, 끝위치): 끝위치 전까지
    
    System.out.println(str.substring(2,4));
    
    System.out.println(str.substring(3));
    
    //length()
    
    System.out.println(str.length());
    
    //soUpper : 대문자, toLower : 소문자
    
    System.out.println(str.toUpperCase());
    
    System.out.println(str.toLowerCase());
    
    //charAt 인덱스, indexOf 문자열, equals 문자열
    
    System.out.println(str.charAt(1));
    
    System.out.println("hello world".indexOf("world"));
    
    // -1 못찾으면 나옴 인덱스 오브
    
    System.out.println(str.equals("hello"));
    
    //trim(), replace, replaceAll
    
    System.out.println(" test ".trim()); // 공백 삭제
    
    System.out.println("hello world".replace('l','L'));
    
    System.out.println("hello world".replace("hello","bye"));
    
    ​
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    ​
    
    package day31;
    
    ​
    
    public class Day31_2 {
    
    ​
    
    public static void main(String[] args) {
    
    String str = "test";
    
    StringBuffer buffer = new StringBuffer("test");
    
    ​
    
    str.replace('t', 'T');
    
    System.out.println(str);
    
    //1,2까지 ES로 변경, 0123순으로 이동
    
    buffer.replace(1, 3, "ES");
    
    System.out.println(buffer);
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    # 32강 wrapper, random 클래스
    
    ​
    
    - wrapper 클래스 - 기본 자료형들을 객체로 다루는데 사용, 자바는 객체지향이므로, 객체 값을 다룰 일이 많기 때문에, 일반자료형의 데이터를 객체로 변환하는 작업이 필요.
    
    ​
    
    - 오토박싱 - 기본 자료형 값을 자동으로 wrapper 클래스의 객체로 변환 시켜주는 것
    
    - 오토 언박싱 - wrapper 클래스의 객체 값을 자동으로 기본 자료형 값으로
    
    ​
    
    - random 클래스 - 무작위의 값을 얻고 싶을 때 사용하는 클래스
    
    ​
    
    ​
    
    ​
    
    package day32;
    
    ​
    
    public class Day32_1 {
    
    ​
    
    public static void main(String[] args) {
    
    int i=30;
    
    Integer ii =new Integer(i);
    
    System.out.println(ii);
    
    ​
    
    double d= 3.14;
    
    Double dd =new Double(d);
    
    System.out.println(dd);
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    ​
    
    package day32;
    
    ​
    
    public class Day32_2 {
    
    ​
    
    public static void main(String[] args) {
    
    Integer ii =30;//auto boxing
    
    System.out.println(ii.intValue());
    
    System.out.println(ii.doubleValue());
    
    System.out.println(ii.floatValue());
    
    System.out.println(ii.toString()+3);// 문자열의 덧셈은 연결
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    ​
    
    package day32;
    
    ​
    
    public class Day32_3 {
    
    ​
    
    public static void main(String[] args) {
    
    //autoboxing
    
    Integer i = 10;
    
    Double d =3.14;
    
    Float f=3.14f;
    
    Character c ='A';
    
    ​
    
    //auto unboxing
    
    int ii=i;
    
    double dd =d;
    
    float ff = f;
    
    char cc =c;
    
    System.out.println(ii);
    
    System.out.println(dd);
    
    System.out.println(ff);;
    
    System.out.println(cc);
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    ​
    
    package day32;
    
    ​
    
    public class Day32_4 {
    
    ​
    
    public static void main(String[] args) {
    
    Random random = new Random();
    
    Random random2 = new Random(2);
    
    Random random3 = new Random(2);
    
    for(int i=0; i<5;i++) {
    
    System.out.println("기본생성자 :"+random.nextInt());
    
    }
    
    for(int i=0;i<5;i++) {
    
    System.out.println("random2 :"+"번째 값 :" +random2);
    
    }
    
    for(int i=0;i<5;i++) {
    
    System.out.println("random3 :"+"번째 값 :" +random3);
    
    }
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    ​
    
    # 33강 java.util 패키지
    
    ​
    
    - java.util 패키지 - 자바 프로그래밍에 유용한 클래스들을 모아둔 것
    
    - 대표적인 클래스로는 날짜와 관련된 데이터, 캘린더가 있으며, 자료구조와 관련된 선택 프레임워크를 포함하고 있다.
    
    ​
    
    - util - 컴퓨터 분야에서 유틸리티란, 사용자의 편리성을 향상하는 유용하고 실용적인 소프트웨어를 의미한다,
    
    ​
    
    ​
    
    - 시간처리 - 자바에서는 시간에 대한 처리를 할 수 있도록 클래스 제공
    
    ​
    
    - System.currentTimeMills() - 현재 운영체제의 시간을 long 타입으로 반환
    
    ​
    
    - java.util.Calendar - 자바에서 제공하는 날짜 관리 클레스
    
    ​
    
    - java.util.Date - 자바에서 제공하는 날짜 관리 클래스
    
    ​
    
    ​
    
    ​
    
    ​
    
    ​
    
    package day33;
    
    ​
    
    public class Day33_1 {
    
    ​
    
    public static void main(String[] args) {
    
    long start = System.currentTimeMillis();
    
    System.out.println("시작시간: "+start);
    
    int a=0;
    
    for(int i=1;i<10000000;i++) {
    
    a++;
    
    }
    
    long end = System.currentTimeMillis();
    
    System.out.println("종료시간 :"+end);
    
    System.out.println("걸린시간 : "+(end-start));
    
    }
    
    }
    
    ​
    
    ​
    
    ​
    
    ​
    
    package day33;
    
    ​
    
    import java.util.Calendar;
    
    import java.util.GregorianCalendar;
    
    ​
    
    public class Day33_2 {
    
    ​
    
    public static void main(String[] args) {
    
    Calendar a = Calendar.getInstance();//싱클패턴
    
    Calendar b = new GregorianCalendar();
    
    System.out.println(a.toString());
    
    System.out.println(b.toString());
    
    ​
    
    }
    
    ​
    
    }
    
    ​
    
    ​
    
    ​
    
    ​
    
    package day33;
    
    ​
    
    import java.util.Calendar;
    
    ​
    
    public class Day33_3 {
    
    ​
    
    public static void main(String[] args) {
    
    Calendar a = Calendar.getInstance();
    
    ​
    
    int year = a.get(Calendar.YEAR);
    
    int month = a.get(Calendar.MONTH)+1;//1원:0 12월:11
    
    int date = a.get(Calendar.DATE);
    
    ​
    
    ​
    
    }
    
    ​
    
    }
    반응형

    'Java > Java 인강' 카테고리의 다른 글

    Java 인강 필기 11  (0) 2022.10.02
    Java 인강 필기 10  (1) 2022.10.02
    Java 인강 필기 8  (0) 2022.10.02
    Java 인강 필기 7  (0) 2022.10.02
    Java 인강 필기 6  (0) 2022.10.02