java百问总结(四)

1.The equals() and hashCode() Contract

    ①.If two objects are equal, then they must have the same hash code.

    ②.If two objects have the same hashcode, they may or may not be equal.

2.Java Exception Class Hierarchy  // 异常类的等级

    Red colored are checked exceptions which must either be caugut or declared in the method's throws clause.

                                               

3.Stack and Heap

    As we know that JVM runtime data areas include heap, JVM stack, and others. For a simple example as follows, let's see where the array and its reference are stored.    

class A {
	int x;
	int y;
}
 
...
 
public void m1() {
	int i = 0;
	m2();
}
 
public void m2() {
	A a = new A();
}
 
...

    With the above declaration, let's invoke m1() and see what happens:

①.When m1 is invoked, a new frame(Frame-1) is pushed into the stack, and local variable i is also created in frame-1.

②.Then m2 is invoked inside of m1, another new frame(Frame-2) is pushed into the stack. In m2, an object of class A is created in the heap and reference variable is put in Frame-2. Now, at this point, the stack and heap looks like the following:



4.JVM Run-Time Data Areas 

    This is my note of reading JVM specification. I draw a diagram which helps me understand.



①.Data Areas for each individual thread include program counter register, JVM Stack, and Native Method Stack. They are all created when a new thread is created. 

    |--Program Counter Register: it is used to control each execution of each thread.    //程序计数器寄存器:它是用来控制每个每个线程的执行

    |--JVM Stack: It contains frames which is demonstrated in the diagram below.    //JVM 堆包含帧  

    |--Native Method Stack: it is used to support native methods, i.e., non-Java language methods.    //本地方法栈: 用于支持本地方法,即非java语言的方法

②.Data Areas Shared by All Threads

    All Threads share Heap and Area.

    |--Heap: it is the area that we most frequently deal with. It stores arrays and objects, created when JVM starts up. Garbage Collection works in this area.    //堆:这是我们最常处理的地方。它存储数组和对象,JVM启动时创建的。垃圾收集在这个领域工作。

    |--Method Area: it stores run-time constant pool, field and method data, and methods and constructors code.    //方法区:它存储运行时常量池,字段和方法数据和方法和构造函数的代码。

    |--Runtime Constant Pool: It is a per-class or per-interface run-time representation of the constant_pool table in a class file. It contains several kinds of constants, ranging from numeric literals known at compile-time to method and field references that must be resolved at run-time.    //运行时常量池:每个类或per-interface constant_pool表的运行时表示一个类文件。它包含多种常量,从数字文字在编译时方法和字段的引用必须在运行时解决。



    Stack contains Frames, and a frame is pushed to the stack when a method is invoked. A frame contains local variable array, Operand Stack, Reference to Constant Pool.      //堆栈包含帧,帧被推到堆栈调用方法时。一个框架包含了局部变量数组,操作数堆栈引用常量池。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值