First, how to install the JDK?
When we down the J2SE 5.0 jdk from the network (is an executable file, the filename is called jdk-1_5_0- Windows-i586.exe, of course, this name will be different from the corresponding operating system, I use the operating system is windows, we found it? ), double-click on it and start installing it. It is important to choose the installation path problem, usually we install it in the C packing directory (this is the default path of the installation program), the other work is one after another to press next.
Second, build the operation and development environment
Is it possible to write code when we have finished loading the JDK, ready to compile and run? Don't be busy. People still follow me to check it:
1, click on the operating system desktop on the bottom left of the ' Start ' menu, select ' Run ', and then enter CMD in the Open dialog box, see, we entered the Command Prompt window, we love to call him DOS interface.
2. Now you should see the prompt in the window, usually this way: C:/Documents and Settings/administrator>
3, let's hit a command after the prompt: JAVA , is there a hint?
Usage:java [-options] class [args ...]
(to execute a class)
or Java [-options]-jar jarfile [args ...]
(to execute a jar file)
...
This is the help information for the Java command, and if so, half the success.
4, Next, try again: At the command prompt, knock: JAVAC. Did the Javac's command help tip also appear? I don't think so. What you see might be this: ' Javac ' is not an internal or external command, or a program or batch file that can be run.
Why is this happening?
This is because our operating system, when executing a command, first finds the command file in the current directory. If not found in the current directory, he will follow the system variable path indicated by the number of paths to search, until found. If you cannot find him in these two places, you will report the mistakes you have seen.
under C:/Documents and Settings/administrator, of course we can't find the Javac command. Our JDK is not installed in the C-packing directory? Our Javac, Java commands are in the Bin folder under the JDK directory, and there are many other baby commands in this clip.
How can I get the operating system to find the Javac command? Very simple! We need to modify the system variable path so that we don't have to run to the C:/j2sdk1.4.2_02/bin path every time we want to execute the command.
5. When we add a path to the PATH variable: c:/j2sdk1.4.2_02/bin, and then enter Javac at the command prompt, a help prompt will appear. That means we can start writing Java programs.
6, let us write a Hello.java test, I in E:/lesson1 this folder created a text file, enter the following code, and save it as Hello.java.
public class Hello
{
public static void Main (String args[])
{
System.out.println ("Hello world!");
}
}
7. Ok now we're back at the command prompt. Enter at the prompt: JAVAC hello.java, the command is wrong again. Why? Because the file is built under E:/lesson1, and our current directory is not it. At the prompt prompt-typed: ' E: ', and then knock: ' CD Lesson1 ', into the Java file in the same directory, now knock Javac Hello.java, the file successfully compiled. Note A successful compilation will produce a name in the current directory named:
How the Java environment variable is configured correctly