Build a Java development environment, write the first Java program using eclipse
First, the construction of the Java development environment
1. First install the Java SDK (JDK).
Click the executable file Jdk-6u24-windows-i586.exe.
The Select installation path appears and you can change the installation path as needed. Here we use the default path and go directly to the next step.
Installation is complete.
2. Next Configure Environment variables
Advanced tab, properties, right-click My Computer
Click on "Environment variables"
We want to configure the Java_home,path,classpath three property.
First, configure the Java_home
Locate the directory where we installed the Java SDK: C:\Program files\java\jdk1.6.0_24, copy the path.
Then click "New" under "System Variables" in the dialog box that appears as shown:
Fill in the variable name "Java_home", the variable value directly paste the previous copy of the JAVA SDK installation directory, that is: "C:\Program files\java\jdk1.6.0_24". Then click "OK", java_home
The variables are configured as well.
Next we configure the path variable (in the environment variable, the case of the variable name is not distinguished)
Find out if the path variable already exists in the system variable:
For example, the path variable already exists on my computer, click "Edit" here, as shown in the window below, you can see that the value of the variable has already been value, we add a half-width semicolon (";") at the end of the variable value. )。 Then paste the path to the bin directory under the Java SDK installation directory.
Click OK. The path variable is configured to complete.
Finally, we configure the CLASSPATH variable.
In "System variables" click on "New"
Variable name: "CLASSPATH"
Variable value: ".; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar "(Enclose the value in quotation marks, including the preceding". ", where%java_home% is a reference to the previously configured java_home)
Click "OK" when you are done.
The environment variables are configured as well.
3. Next, let's test if the environment variable you just configured is correct.
First, in the D packing directory, see a text file, enter the code:
public class Test
{
public static void Main (string[] args)
{
System.out.println ("hello,java!");
}
}
Rename the text file to: Test.java
Then click "Start", "Run"
Input cmd, enter, or click "OK" button
Enter: "D:", enter into the D drive.
Then, enter Javac Test.java to compile the Test.java file
There is no hint that the compilation passed.
Then enter Java Test and run the Java program that you just compiled.
Print out: hello,java!
Description Our environment variables are set correctly.
Second, use Eclipse to write my first Java program
Unzip the Eclipse-jee-helios-sr1-win32.zip file
Run Eclipse.exe (This is a free-to-install package, so just run it right)
Interface appears:
Here is to let us set the working directory, this casual settings can be, here we use the default configuration, direct "OK".
Click on the "Workbench" link in the upper right corner of the workspace to enter the Workbench
Now let's create a Java project
- File->new->java Project (if there is no Java project in the catalog, select "Project" and then the pop-up window select "Java", "Java Project")
The project name can be taken, here we fill: myfirst_javaapplication, the other options to use the default value, directly click "Finish". Workbench, the left side should look like the one shown in the project.
Right-click on the "src" package in the project and select "New"
Here the name of the package can actually be taken, but the formal development will often contract a specification, easy to maintain the project.
Here we register: Cn.edu.fjnu.hyan, after filling out, click "Finish".
We can see that the new package we just created appears in the SRC directory. (The so-called package, in fact, is the folder.) For example
Package named Cn.edu.fjnu.hyan, in fact, is in the SRC directory to create a folder, the folder name is "CN", and then in the folder "CN" To create a folder "Edu", and so on, and finally in the FJNU directory under the name "Hyan" folder. )
Next we'll create a new class in the package we just created, named Test.
After we have filled out the name of the class, tick the check box shown (public static void main (string[] args) to automatically generate the Main method. Click "Finish".
In the newly built class file, we can write the program code, here we add the following code in the Main method:
Press CTRL + F11 to run the program.
(add: There are many ways to start a program, you can right-click on the code window to select "Run", "Java appliction", or you can click the Run icon on the toolbar, such as:
You can also click "Run as" on the menu bar, "Java appliction")
After the program runs, you can see that the "hello,world!" is printed in the console window
Our first Java program is now complete!
Build a Java development environment, write the first Java program using eclipse