JVM详解 -> 深入理解栈
-
数据结构
-
栈:先进后出、后进先出
-
队列:先进先出(FIFO:First Input First Output)
-
思考一个问题:为什么main()先执行,最后结束?
-
栈:栈内存,主管程序的运行,生命周期和线程同步,线程结束,栈内存也就释放,对于栈来说,不存在垃圾回收问题
-
栈里面存放的:8大基本类型、对象引用、实例的方法
-
栈的运行原理
- 栈满了:StackOverflowError
- 栈+堆+方法区 的交互关系
-
对象实例化在内存中的实例:
public class Student { String name; int id; double height; void studentInfo(){ System.out.println("Name:" + name); System.out.println("ID:" + id); System.out.println("Height:" + height); } public static void main(String[] args) { Student student = new Student(); student.name = "Ano"; student.id = 1001; student.height = 54.2; student.studentInfo(); } }