0.1) 本文转自 core java volume 1,旨在说明如何设置 JDK环境变量,以及为什么要设置的问题;
Attention)就Java 而言, docs 和 src 是两个最有用的子目录:因为 docs 目录 包含了HTML 格式的类库文件;而 src目录 包含了 Java 类库中公共部分的源代码;
2.1)执行路径:它是指os 搜索本地可执行文件的目录列表;(在安装完JDK后,我们还要把 jdk/bin 目录添加到 执行路径中), jdk里面全是可执行文件,如 编译器javac.exe 和解释器 java.exe , 抽取注释工具 javadoc.exe 等;
2.2)如何测试 jdk 设置是否正确: java -version;
Attention)
Alert) javac 编译器总是在当前等级目录中查找文件, 但 java虚拟机仅在类路径中有 “.” 目录的时候才查看当前目录;
3.1)看个荔枝, 虚拟机如何搜寻类文件:
import java.util.*;
import com.horstmann.corejava.*;
3.2)设置CLASSPATH 环境变量(为什么设置 CLASSPATH为 .;C:\jdk1.8.0_60\lib ?) 参见JDK目录树;
3.3)设置类路径 (调用的类库 不存在于当前目录或 CLASSPATH路径的时候,需要设置)
java -classpath /home/user/classdir : . : /home/user/archives/archive.jar MyProg
或者
java -classpath c:\classdir; . ; c:\archives\archive.jar MyProg
linux中: export CLASSPATH=/home/user/classdir: . : /home/user/archives/archives.jar
windows中: set CLASSPATH=c:\classdir; . ; c:\archives\archive.jar
following contents are reshipped from http://docs.oracle.com/javase/7/docs/webnotes/install/windows/jdk-installation-windows.html
Updating the PATH Environment Variable (Optional)
You can run the JDK without setting the PATH environment variable, or you can optionally set it so that you can conveniently run the JDK executable files (javac.exe, java.exe, javadoc.exe, and so forth) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it, such as:
C:\> "C:\Program Files\Java\jdk1.7.0\bin\javac" MyClass.java
It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.7.0\bin directory to the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.7.0\bin. Set the PATH variable as follows on Microsoft Windows:
Note:
Starting to Use the JDK
If you are new to developing and running programs in the Java programming language, see The Java Tutorial online for some guidance. Note especially the tutorial trails under the heading Trails Covering the Basics.
You can also download the JDK documentation from the Java SE Downloads page.
Uninstalling the JDK
If you should ever want to uninstall the JDK, use the “Add/Remove Programs” utility in the Microsoft Windows Control Panel.
Installed Directory Tree
See JDK and JRE File Structure for a description of the directory structure of the JDK. (Note that the file structure of the JRE is identical to that of the JDK’s jre directory.)