java.lang 패키지
class HelloWorld{
public static void main(String[] args){
System.out.println("Hello, World!");
}
}
위와같은 class가 있다 가정해보자.
이때, 우린 아무런 package도 import하지 않았는데 System클래스에 존재하는 println메서드를 사용한다.
이러한 이유는 JAVA에서 필요한 클래스들이 모여있는 패키지인 java.lang package는 import문이 따로 없어도 자동적으로 프로그램에 포함이 되기 때문이다.
java.lang에 존재하는 클래스
Object: The root class of the Java class hierarchy.String: A class that represents a sequence of characters.System: A class that provides access to the standard input, output, and error streams of the program.Math: A class that provides methods for performing basic mathematical operations.Integer,Long,Float,Double,Short,Byte: Wrapper classes for primitive types.Exception,RuntimeException,Error: Classes for handling exceptions and errors.
In addition to these, the java.lang package also contains other classes such as Thread, ClassLoader, Process, and ProcessBuilder, among others.
위 클래스들말고도 수많은 클래스가 존재한다. 아무튼 결론은 우리가 따로 import하지않아도 사용할수 있는 클래스들은 java.lang package에 존재한다고 보면된다.
'Java > Java 개념' 카테고리의 다른 글
| [Java] equals,hashCode (0) | 2023.04.09 |
|---|---|
| [Java] Test코드에서 Assertions를 통해 오류 잡기 (0) | 2023.03.12 |
| [Java] Error And Exception (0) | 2023.03.12 |
| [Java] ArrayList 출력 방법 3가지 (0) | 2023.03.12 |
| [Java] Object를 String타입으로 변환 (0) | 2023.03.12 |