我的问题是: 1.什么是类初始化?
2.类在初始化时,内存中的运行机制?或 初始化与分配内存有什么关系?
3.创建一个对象与初始化有什么区别?
先谢谢大家。。希望大家说说个自的了解。
5 个解决方案
#1
jvm lazy load class 机制, 下列情况会初始化类
1、T is a class and an instance of T is created.
2、T is a class and a static method declared by T is invoked.
3、A static field declared by T is assigned.
4、A static field declared by T is used and the field is not a constant variable
References to compile-time constants must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization.
1、T is a class and an instance of T is created.
2、T is a class and a static method declared by T is invoked.
3、A static field declared by T is assigned.
4、A static field declared by T is used and the field is not a constant variable
References to compile-time constants must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization.
#2
楼上英文挺厉害啊,学习啊。
#3
英文我的硬伤咧,,看不懂。
#4
类被使用之前需要被装载进虚拟机,分以下阶段:类的加载,链接和初始化,你问的什么是类的初始化即是第三阶段,会初始化类的静态变量,执行类的静态初始化方法.
类在链接的过程中的“准备阶段”会为类变量分配内存,设置默认的初始值(字节全为0)。
创建一个对象和类的初始化有什么区别:
类的初始化只会在类被装载的时候执行一次,而创建一个对象执行的是"对象的初始化方法",这两者需要加以区别,对象的初始化方法包含了:成员变量初始化,初始化块和构造函数
类在链接的过程中的“准备阶段”会为类变量分配内存,设置默认的初始值(字节全为0)。
创建一个对象和类的初始化有什么区别:
类的初始化只会在类被装载的时候执行一次,而创建一个对象执行的是"对象的初始化方法",这两者需要加以区别,对象的初始化方法包含了:成员变量初始化,初始化块和构造函数
#5
如果你是初学java,先有个概念,会做一些笔试题就可以了,等以后想深入理解,就看<深入java虚拟机>这本书
#1
jvm lazy load class 机制, 下列情况会初始化类
1、T is a class and an instance of T is created.
2、T is a class and a static method declared by T is invoked.
3、A static field declared by T is assigned.
4、A static field declared by T is used and the field is not a constant variable
References to compile-time constants must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization.
1、T is a class and an instance of T is created.
2、T is a class and a static method declared by T is invoked.
3、A static field declared by T is assigned.
4、A static field declared by T is used and the field is not a constant variable
References to compile-time constants must be resolved at compile time to a copy of the compile-time constant value, so uses of such a field never cause initialization.
#2
楼上英文挺厉害啊,学习啊。
#3
英文我的硬伤咧,,看不懂。
#4
类被使用之前需要被装载进虚拟机,分以下阶段:类的加载,链接和初始化,你问的什么是类的初始化即是第三阶段,会初始化类的静态变量,执行类的静态初始化方法.
类在链接的过程中的“准备阶段”会为类变量分配内存,设置默认的初始值(字节全为0)。
创建一个对象和类的初始化有什么区别:
类的初始化只会在类被装载的时候执行一次,而创建一个对象执行的是"对象的初始化方法",这两者需要加以区别,对象的初始化方法包含了:成员变量初始化,初始化块和构造函数
类在链接的过程中的“准备阶段”会为类变量分配内存,设置默认的初始值(字节全为0)。
创建一个对象和类的初始化有什么区别:
类的初始化只会在类被装载的时候执行一次,而创建一个对象执行的是"对象的初始化方法",这两者需要加以区别,对象的初始化方法包含了:成员变量初始化,初始化块和构造函数
#5
如果你是初学java,先有个概念,会做一些笔试题就可以了,等以后想深入理解,就看<深入java虚拟机>这本书