Chinaunix首页 | 论坛 | 博客
  • 博客访问: 229563
  • 博文数量: 108
  • 博客积分: 3092
  • 博客等级: 中校
  • 技术积分: 1172
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-25 16:35
文章分类

全部博文(108)

文章存档

2011年(3)

2010年(43)

2009年(19)

2008年(43)

我的朋友

分类: Java

2010-09-08 09:28:20

The Java class file is a precisely defined binary file format for Java programs. Each Java class file represents a complete description of one Java class or interface.

Although the class file is related to the Java language architecturally, it is not inextricably linked to the Java language. As shown in Figure 6-1, you could write programs in other languages and compile them to class files, or you could compile your Java programs to a different binary file format.

The Java Virtual Machine makes types available to the running program through a process of loading, linking, and initialization.

Loading


Loading is the process of bringing a binary form for a type into the Java Virtual Machine.

The Class instance, the end product of the loading step, serves as an interface between the program and the internal data structures.

The Java Virtual Machine specification does not say how the binary data for a type must be produced. Some potential ways to produce binary data for a type are:

·         load a Java class file from the local file system

·         download a Java class file across a network

·         extract a Java class file from a ZIP, JAR, CAB, or other archive file

·         extract a Java class file from a proprietary database

·         compile a Java source file on the fly into the class file format

·         compute the class file data for a type on the fly

·         any of the above, but using a binary file format other than the Java class file

if a class loader encounters a missing or malformed class file during early loading, it must wait to report that error until the class is first active use by the program.

Linking


Linking is the process of incorporating the binary type data into the runtime state of the virtual machine. Linking is divided into three sub-steps: verification, preparation, and resolution.

Verification ensures the type is properly formed and fit for use by the Java Virtual Machine. Preparation involves allocating memory needed by the type, such as memory for any class variables. Resolution is the process of transforming symbolic references in the constant pool into direct references. Implementations may delay the resolution step until each symbolic reference is actually used by the running program.

Initialization


During initialization, the class variables are given their proper initial values.

Unloading and Finalization of Classes


In many ways, the lifetime of a class in the Java Virtual Machine is similar to the lifetime of an object.

Types loaded through the primordial class loader will always be reachable and never be unloaded. Only dynamically loaded types--those loaded through class loader objects--can become unreachable and be unloaded by the virtual machine. A dynamically loaded type is unreachable if its Class instance is found to be unreachable through the normal process of garbage collecting the heap.

 

阅读(701) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-09-10 09:34:55

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com