JVM(Java Virtual Machine)
자바 프로그램이 실행되는 환경 제공
JVM은 메모리를 체계적으로 관리하기 위해 여러 영역으로 나뉘어져 있다.
GC(Garbage Collection): 사용되지 않는 객체를 메모리에서 해제하여 자동으로 메모리를 관리

*JVM 버전에 따라 달라질 수 있다.




PC Register
Native Method Stack
Static: 클래스 자체에 1개만 공유되는 멤버 (필드, 메서드)
- Static 키워드를 작성하면 객체(인스턴스)와 무관하게 클래스 자체에 속함
- 특정 객체에 속하지 않고 모든 객체가 동일한 static 멤버를 참조
- 클래스의 이름을 통해 직접 호출 가능
- JVM 메서드 영역에 저장
// Person Class
public class Person {
static int pCount;
String name;
int age;
String hobby;
}
// PersonTest Class
public class PersonTest {
public static void main(String[] args) {
Person p = new Person();
p.name = "Kim";
Person.pCount++;
p.pCount++; // 오류는 나지 않지만 경고
}
}
public class Counter {
// static 변수
public static int sCount;
// non-static 변수
public int iCount;
// 초기화 블록
static {
sCount = 10;
}
}
static 영역에서는 non-static 영역을 직접 접근할 수 없음
non-static 영역에서는 static 영역에 대한 접근이 가능
public class Main {
String str = "문장";
public static void main(String[] args) {
System.out.println(str);
}
}
public class Main {
static String str = "문장";
public static void main(String[] args) {
System.out.println(str);
}
}