【Core Java】【Volume I ~Fundamentals】【Chapter 2】【2.1】【Installing the Java Development Kit】...

Installing the Java Development Kit
The most complete and up-to-date versions of the Java Development Kit (JDK) are available from Sun Microsystems for Solaris, Linux, and Windows. Versions in various states of development exist for the Macintosh and many other platforms, but those versions are licensed and distributed by the vendors of those platforms.

2.1 安装Java开发工具箱

Sun Microsystems公司为Solaris、Linux和Windows提供了Java开发工具箱(JDK)的最新、最完整的版本。用于Macintosh和一些其他平台的版本仍处于各种不同的开发状态中,不过,这些版本都是由相应平台的开发商授权并分发的。

NOTE: Some Linux distributions have prepackaged versions of the JDK. For example, on
Ubuntu, you can install the JDK by simply installing the sun-java6-jdk package with apt-get or
the Synaptic GUI.

注释:有些Linux的发行版已经预先打包了JDK。例如,在Ubuntu中,可以用apt-get或Synaptic GUI安装sun-java6-jdk包来安装JDK。

Downloading the JDK
To download the Java Development Kit, you will need to navigate the Sun web site and decipher an amazing amount of jargon before you can get the software that you need. See Table 2–1 for a summary.

2011052508051986.png

2.1.1 下载JDK

要想下载Java开发程序包,必须到Sun网站进行搜寻,并且在得到所需的软件之前必须弄清大量的专业术语。请看表2-1。

2011052508082868.png

You already saw the abbreviation JDK for Java Development Kit. Somewhat confusingly, versions 1.2 through 1.4 of the kit were known as the Java SDK (Software Development Kit). You will still find occasional references to the old term. There is also a Java Runtime Environment (JRE) that contains the virtual machine but not the compiler. That is not what you want as a developer. It is intended for end users who have no need for the compiler.

JDK是Java Development Kit的缩写。有点混论的地方是:工具箱的版本1.2~版本1.4被称为Java SDK(Software development Kit)。在某些场合下,还可以看到这些过时的术语。另外,还有Java运行时环境(JRE),它包含虚拟机但不包含编译器。这并不是开发者所想要的环境,而是专门为不需要编译器的用户而设计。

Next, you’ll see the term Java SE everywhere. That is the Java Standard Edition, in contrast to Java EE (Enterprise Edition) and Java ME (Micro Edition).

还有,随处可见的Java SE,相对于Java EE(Enterprise Edition)和Java ME(Micro Edition),它是Java的标准版。

You will occasionally run into the term Java 2 that was coined in 1998 when the marketing folks at Sun felt that a fractional version number increment did not properly communicate the momentous advances of JDK 1.2. However, because they had that insight only after the release, they decided to keep the version number 1.2 for the development kit. Subsequent releases were numbered 1.3, 1.4, and 5.0. The platform, however, was renamed from Java to Java 2. Thus, we had Java 2 Standard Edition Software Development
Kit Version 5.0, or J2SE SDK 5.0.

Java 2这种提法始于1998年。当时Sun公司的销售人员感觉通过增加小数点后面的数值改变版本号并没有反映出JDK1.2的重大改进。但是,由于在发布之后才意识到这个问题,所以决定将开发工具箱的版本号仍然沿用1.2,接下来的版本就是1.3、1.4和5.0。但是,Java平台被重新命名为Java 2。因此,就有了Java 2 Standard Edition Software Development Kit 的5.0版,即J2SE SDK 5.0

For engineers, all of this was a bit confusing, but that’s why we never made it into marketing. Mercifully, in 2006, sanity prevailed. The useless Java 2 moniker was dropped and the current version of the Java Standard Edition was called Java SE 6. You will still see occasional references to versions 1.5 and 1.6—these are just synonyms for versions 5.0 and 6.

对于工程师来说,所有这一切都可能引起困惑,这正是没有将其投入市场的原因。2006年,日趋完善的Java SE开始流行。无意义的Java 2被遗忘,Java当前的标准版本被称为Java SE 6.偶尔还会看到使用1.5版本和1.6版本,但这些只是5.0版本和6版本的同义词。

Finally, when Sun makes a minor version change to fix urgent issues, it refers to the change as an update. For example, the first update of the development kit for Java SE 6 is officially called JDK 6u1 and has the internal version number 1.6.0_01.

最后,当Sun为解决一些紧急问题做出了某些微小的版本改变时,将其称为更新。例如:对Java SE 6开发包做出的第一次更新,正式称为JDK 6u1,内部的版本号为1.6.0_01

If you use Solaris, Linux, or Windows, point your browser to http://java.sun.com/javase to download the JDK. Look for version 6 or later and pick your platform. Don’t worry if the software is called an “update.” The update bundles contain the most current version of the whole JDK.

如果使用Solaris、Linux或Windows,就应该从http://java.sun.com/javase下载Java软件开发工具箱。找到版本6或后续的版本,并选择自己的平台。如果软件被称为“更新”也不必担心。更新将捆绑包含了整个JDK的最新版本。

Sometimes, Sun makes available bundles that contain both the Java Development Kit and an integrated development environment. That integrated environment has, at different times of its life, been named Forte, Sun ONE Studio, Sun Java Studio, and Netbeans. We do not know what the eager beavers in marketing will call it when you approach the Sun web site. We suggest that you install only the Java Development Kit at this time. If you later decide to use Sun’s integrated development environment, simply
download it from http://netbeans.org.

Sun公司曾经制作过将Java开发工具箱和集成开发环境绑在一起的产品。其中的集成开发环境,在不同时期,被命名为不同的名字,例如,Forte, Sun ONE Studio, Sun Java Studio, 和 Netbeans。我们无法知道每个人在登录Sun网站时,市场正在热销什么。这里,建议大家只安装Java开发工具箱。如果最终决定使用Sun的集成开发环境,就可以从http://netbeans.org下载。

After downloading the JDK, follow the platform-dependent installation directions. At the time of this writing, they are available at http://java.sun.com/javase/6/webnotes/install/index.html.

下载JDK之后,随后的安装过程请参看不同平台的安装指南。在编写本书时,可以在网站 http://java.sun.com/javase/6/webnotes/install/index.html上搜寻到。

Only the installation and compilation instructions for Java are system dependent. Once you get Java up and running, everything else in this book should apply to you. System independence is a major benefit of Java.

只有Java的安装过程和编译命令与系统有关。一旦安装并运行了Java,本书阐述的所有内容都使用。与系统无关性是Java的一个主要优势。

NOTE: The setup procedure offers a default for the installation directory that contains the JDK version number, such as jdk1.6.0. This sounds like a bother, but we have come to appreciate the version number—it makes it easier to install a new JDK release for testing.
Under Windows, we strongly recommend that you do not accept a default location with spaces in the path name, such as c:\Program Files\jdk1.6.0. Just take out the Program Files part of the path name.
In this book, we refer to the installation directory as jdk. For example, when we refer to the jdk/bin directory, we mean the directory with a name such as /usr/local/jdk1.6.0/bin or
c:\jdk1.6.0\bin.

注释:安装过程提供了包含JDK版本号(如jdk1.6.0)的默认的安装路径。这似乎有些烦恼,但是,应该重视版本号,它会给安装新版JDK的测试带来方便。

在Windows环境下,强烈建议不要接受带空格的默认路径名,如:c:\Program Files\jdk1.6.0。应该将Program Files部分删掉。

在本书中,使用的安装路径是jdk。例如,当引用jdk/bin目录时,意味着引用的是/usr/local/jdk 1.6.0/bin或c:\jdk1.6.0\bin。

Setting the Execution Path

After you are done installing the JDK, you need to carry out one additional step: Add  the jdk/bin directory to the execution path, the list of directories that the operating system traverses to locate executable files. Directions for this step also vary among operating  systems.

2.1.2 设置执行路径

在完成了JDK的安装之后,还需要执行另外一个步骤:把jdk/目录添加到执行路径中。所谓执行路径是指操作系统搜索本地可执行文件的目录列表。对于不同的操作系统,这个步骤的操作过程有所不同。

In UNIX (including Solaris and Linux), the procedure for editing the execution path depends on the shell that you are using. If you use the C shell (which is the Solaris default), then add a line such as the following to the end of your ~/.cshrc file:
set path=(/usr/local/jdk/bin $path)
If you use the Bourne Again shell (which is the Linux default), then add a line such as the following to the end of your ~/.bashrc or ~/.bash_profile file:
export PATH=/usr/local/jdk/bin:$PATH

在UNIX(包括Solaris和Linux)环境下,编辑执行路径的过程与所使用的shell有关。如果使用的是C shell(Solaris的默认选择),在~/.cshrcde的文件的末尾就要添加:

set path=(/usr/local/jdk/bin Spath)

如果使用的是Bourne Again shell(Linux的默认选择),在~/.bashrc文件或~/.bash_profile末尾就要添加:

export PATH=/usr/local/jdk/bin:SPATH

、、

Under Windows, log in as administrator. Start the Control Panel, switch to Classic View, and select the System icon. In Windows NT/2000/XP, you immediately get the system properties dialog. In Vista, you need to select Advanced System Settings (see Figure 2–1). In the system properties dialog, click the Advanced tab, then click on the Environment button. Scroll through the System Variables window until you find a variable named Path. Click the Edit button (see Figure 2–2). Add the jdk\bin directory to the beginning of the path, using a semicolon to separate the new entry, like this:
c:\jdk\bin;other stuff
Save your settings. Any new console windows that you start have the correct path. Here is how you test whether you did it right: Start a shell window. Type the line
java -version and press the ENTER key. You should get a display such as this one:
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
If instead you get a message such as “java: command not found” or “The name specified is not recognized as an internal or external command, operable program or batch file”, then you need to go back and double-check your installation.

在Windwos下,以管理员身份登录。启动Control Panel,切换到Classic View,并选择System图标。在Windows NT/2000/XP中,立即会看到System Properties对话框。在Vista中,需要选择Advanced系统设置(如图2-1所示)。在System Properties对话框中,点击Advanced标签,然后点击Enviroment Variables按钮。滚动System Variables窗口直到找到变量名path为止。点击Edit按钮(如图2-2所示)。将jdk\bin目录添加到路径的开始处,用分号将新条目隔开,如下所示:

c:\jdk\bin;other stuff

2011052509585538.png

2011052510031549.png

将这个设置保存起来,打开的任何控制窗口都会有正确的路径。

下面是测试上述设置是否正确的方法:打开一个shell窗口,键入:

java -version

然后按ENTER键。应该能够看到下面的显示信息

java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

如果看到的是 “java: command not found” 或 “The name specified is not recognized as an internal or external command, operable program or batch file”,则需要回到前面,重新检查整个的安装过程。

NOTE: In Windows, follow these instructions to open a shell window. If you use Windows NT/2000/XP, select the “Run” option from the Start menu and type cmd. In Vista, simply type cmd into the “Start Search” field in the Start menu. Press ENTER, and a shell window appears.
If you’ve never seen one of these, we suggest that you work through a tutorial that teaches the basics about the command line. Many computer science departments have tutorials on the Web, such as http://www.cs.sjsu.edu/faculty/horstman/CS46A/windows/tutorial.html.

注释:在Windows中,按照下面的命令打开shell窗口。如果使用Windows NT/2000/XP环境,那么在开始菜单中选择Run选项,并键入cmd。在Vsiata中,只在开始菜单中的Start Search中输入cmd,再按下ENTER键就会出现了一个shell窗口。

如果曾经没有接触过这些内容,建议学习一下有关命令行的基础教程。很多大学的计算机科学系在网上都有相关的教程,例如http://www.cs.sjsu.edu/faculty/horstman/CS46A/windows/tutorial.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值