java 명령어

David8·2022년 4월 21일
0

java

목록 보기
2/7

import

  1. 다른 패키지 클래스를 가져다 쓰기 위하여 사용
    	import java.util.scanner; // java.util 패키지 안에 있는 scanner라는 클래스를 사용

System.out.println

  1. 출력
    1. System 클래스 안에 printstream 클래스의 out이라는 static final 변수가 있음
    2. printStream 클래스 안에 println 함수가 있음
          class System
          {
              public static final PrintStream out;
              //More Code Below
          }
          class PrintStream
          {
              public void print(argument)
              {
                  //implementation
              }
              public void println()
              {
                  //implementation
              }
              //Overloaded print() and println() methods below
          }

static

  1. static method
    1. static 메쏘드는 객체 생성 없이 사용 가능
      1. 컴파일 할 때 이미 메모리에 로드되기 때문임

        Math.random() // math함수를 import하지 않아도 static 메쏘드이기 때문에 사용가능
        
    2. main에서 static 사용 이유
      1. class 내에 다른 함수보다 가장 먼저 실행 되야 하기 때문
      2. Integer.parseInt와 같이 외부에서 객체 생성 없이 호출을 하기 위함이 아니라 class 내에서의 우선순위를 위해서인듯

equls

  1. 두개의 문자열이 동일한지 판별
    String a = "hello";
    String b = new String("hello");
    System.out.println(a.equals(b));  // true
    System.out.println(a == b);  // false, == 연산자는 두개의 자료형이 동일한 객체인지를 판별 --> a와b는 같지만 서로 다른 객체임

0개의 댓글