对Declaration, Instantiation 和Initialization一直都存在疑惑,直到看了Brown大学的这个文档。
对象(也就是类)被实例化,变量被初始化。
实例化例子:
new Guitarist(); 这就是实例化了Guitarist
初始化例子:
Guitarist guitarist = new Guitarist();
_guitarist = new Guitarist();
int num = 3;
这样,我们就初始化了实例变量_guitarist 和局部变量guitarist,num。
初始化一个变量就是指给一个变量赋初始值,使其不为空null。
声明一个变量和初始化不同,以下是初始化的例子
privateGuitarist_guitarist;_guitarist is null, or has no value //_guitarist 是空值或者没有值
Guitaristguitarist;again, guitarist is null.//guitarist 值为空
初始化一个变量
intnum=5;here, num is given an initial value of 5. //num被赋予的值为5
Remember that “=” means assignment or “gets,” not “is equal to”//记住”=“是赋值,不是等于
实例化
_guitarist=newGuitarist();this is instantiating an object. We create a new instance of a Guitaristand initialize _guitaristto be the value of the new Guitarist
//这是实例化一个对象
既然说到了初始化和实例化,那我们再来看一下ClassLoader,因为类加载机制也是一个容易使人迷惑的概念。
java.lang
Class ClassLoader
- java.lang.ClassLoader
- Direct Known Subclasses:
public abstract class ClassLoader extends Object //Object是所有类的基类
A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class. Given the binary name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class. A typical strategy is to transform the name into a file name and then read a "class file" of that name from a file system.
//类加载器就是一个负责加载类的对象。ClassLoader是一个抽象类,给定类的二进制名,类加载器应能尝试定位或者生成构成类的定义的数据。一个经典的策略是将二进制名转换为文件名然后从文件系统中读取该名称的类文件。