About the Java Technology
Last updated
Last updated
Java技术既是一种编程语言也是一个平台
Java语言是一个高级语言,可以用如下这些时髦词语来描述它:
|
|
James Gosling
和Henry McGilto
的文章The Java Language Environment中对这些词进行了解释
在Java语言中,所有的源代码以.java
扩展名结尾的纯文本文件编写。接下来使用java compiler
将原文件编译为.class
文件。.class
文件并不包含处理器可以直接使用的代码,而是Java Virtual Machine(JVM)
使用的机器语言被称之为bytecodes
。Java启动工具通过一个JVM
实例运行你的程序。
由于JVM
可以运行在不同的操作系统之上,所以.class
文件就有能力在Microsoft Windows
,the Solaris™ Operating System (Solaris OS)
,Linux
,Mac OS
系统中运行。有些虚拟机比如Java SE HotSpot at a Glance,会在运行时进行额外的任务来提升程序的性能,包括发现程序的性能瓶颈和将经常运行的代码片段重新编译成native code
。
Platform
(平台)指的是一个程序运行的软硬件环境。我们已经提到过一些著名的平台比如Microsoft Windows
,Linux
,Solaris OS
,Mac OS
。大多数平台都可以描述成操作系统和底层硬件的混合体。Java平台不同于其他的平台因为它只是在其他基于硬件的平台之上的一个软件平台。
Java平台包含两个组件:
Java Virtual Machine
Java Application Programming Interface (API)
上文已经介绍过Java Virtual Machine
,它是Java平台的基础并且被移植到许多不同的硬件平台。
API
是一个现成的供许多有用功能的软件组件集合,它由许多关联的类和接口组成不同的libraries
,这些libraries
一般称之为包。下一章会介绍API
的一些功能。
作为一个平台无关的环境,Java平台可能比native code
(机器码)慢一些。但是编译器与虚拟机技术的进步使得性能接近于native code
,同时不会影响到可移植性。
Java Virtual Machine
和JVM
都指的是Java平台的虚拟机。