As the saying goes, everything starts hard.
A lot of things seem to be natural to people who already understand them, but they are confusing for beginners. When I first started reading JAVA, it also took a lot of time to configure JDK. I will write down some of my experiences here, hoping to help beginners.
Of course, here is an exception. It is difficult to start with everything.
However, there are still many difficulties after the beginning of everything.
If you don't work hard, you won't succeed.
Okay. I will not talk much about it.
Step 1: Download JDK from the Internet.
This can be searched by the search engine, where resources are downloaded everywhere. Note that you must first know the version of your system. Generally, JDK on the official website has different versions for windows and unix.
Official download address:
Http://www.oracle.com/technetwork/java/javaee/downloads/java-ee-sdk-6u4-jdk-7u11-downloads-1900532.html
Here, you need to select the correct version. Nowadays, many computers use 64-bit operating systems. Here you can select a 64-bit jdk version. This is not detailed.
Of course, you can also download from other resources.
Step 2: Install the SDK.
This process is simple, just remember the last installation path. We recommend that you change the system settings. Generally, files on the computer do not display the suffix. In later JAVA learning, you need to operate on the suffix.
The following uses the XP system as an example.
Open "my computer", select tool (T), and then select Folder Options.
It is shown as follows:
Here, select "View"
In advanced settings, find
"Hide extensions of known file types"
This option.
Remove the check box.
After installing JDK, find the installation path. The default path is as follows:
C: \ Program Files \ Java \ jdk1.7.0 _ 15
After this step, JDK has been installed.
In the initial learning, we want to use the java.exeand javac.exe files in the bindirectory.
The former is used for running, and the latter is used for compiling.
Here, JDK, C, C ++, and other programming languages of VC or objective l studio are different. It does not include an edited software.
You can run the two software in cmd.exe to ensure that the software is available.
The method is as follows:
Click Start of the computer,
Select "run"
Here, there may be a slight difference between different computers, but you can always find this directory. You can also use the "win + R" key to directly open the interface.
Enter cmd,
After confirmation, the following page is displayed.
Because the computer settings are different, different directories are started. Here I am D: disk.
However, this does not affect anything.
Continue to the next step.
At this time, we can send a command to the corresponding java.exeand javac.exe.
First, if your JDK is installed on drive C.
Enter "c:" And press OK. The directory will be transferred to drive c.
(Many computers are initially configured on drive C, which is a special case here)
Next, you can copy the JDK directory on your computer.
"C: \ Program Files \ Java \ jdk1.7.0 _ 15"
Enter
Cd C: \ Program Files \ Java \ jdk1.7.0 _ 15
In this way, you will go to the JDK directory.
Our files are in the bin folder.
Input
Cd bin can be used for this directory.
In this way, you can enter javac and JAVA. If JDK is normal, the display will appear.
If an error occurs, it may occur. (Of course, this situation is minimal)
Now, step 2 is complete. ,
Step 3: configure the JDK environment.
First, let's briefly explain why we need to configure the JDK environment.
Because we need to use a file to access the directory of the file. For example, we need to use two exe files: java and javac. We all need to first access its directory and then run it in its directory.
However, when writing our own program, we may not necessarily put it in this directory, but may put it in any other place on the computer.
So that our java.exeand javac.exe can be used anywhere on the computer.
For example, we put the source code of JAVA under the java folder of the E drive.
We can directly run javac and Java in this directory to compile and run the source files.
The procedure is as follows:
Right-click my computer, select "properties", and select "advanced"
Select environment variables,
Then select the new variable name in the system variable
JAVA_HOME
Variable value:
Your JDK directory
Here is
C: \ Program Files \ Java \ jdk1.7.0 _ 15
This step facilitates you to access your JDK directory.
The operations that allow your java.exeand javac.exe software to run anywhere on the computer.
Find the PATH variable in the system variable.
Add
% Java_home % \ bin; % java_home % \ JRE \ bin;
Remember to use a semicolon.
A semicolon is used to differentiate each item.
Files in every folder under the PATH variable can be accessed anywhere on the computer.
Here, we add the bin directory of JDK and the bin directory under JRE to the path.
In this way, our javac and Java can be run anywhere on the computer.
You can learn about the system environment variables on your own. This is not detailed here.
Here is a brief description of JRE \ bin.
DK is the Java Development Kit. In short, JDK is an SDK for developers. It provides the Java development environment and runtime environment. The SDK is a software development kit. It generally refers to a software development kit, which can include function libraries and compiled programs.
JRE is the Java runtime enviroment, which refers to the Java Runtime Environment and is intended for Java program users rather than developers.
If JDK is installed, there will be two sets of JRE on your computer, one in the \ jre and the other in the C: \ Program Files \ Java \ jre1.5.0 _ 15 directory, this later set is less Server-side Java virtual machine than the previous one, but simply copy the previous Server-side Java virtual machine. When installing JDK, you can choose whether to install the JRE in the C: \ Program Files \ Java directory. If you only install JRE instead of JDK, only a unique set of JRE will be installed in the C: \ Program Files \ Java directory.
The status of JRE is just like that of a PC. The Win32 application we write requires the operating system to help us run it. Similarly, the Java program we write must also run JRE. So after installing JDK, if two sets of JRE are installed in two different locations on the hard disk, you can imagine that your computer has two virtual Java PCs, all have the function of running Java programs. So we can say that if your computer has installed JRE, you can run the Java application correctly.
Next, we are setting the classpath
Select environment variables and create
The variable name is classpath; the variable value is
".; % JAVA_HOME % \ lib \ tools. jar; % JAVA_HOME % \ lib \ dt. jar ;"
Note that there is a "." At the beginning of CLASSPATH, indicating the current directory. When we run java AClass, the system will first find the AClass file in the current directory.
In this configuration, We can automatically include some classes in tools. jar and dt. jar.
These classes are some basic requirements for running java code.
For example, you need to use the JDK machine to run your JAVA code. You need some basic classes, just like playing hero league with a computer, you need to download the League of legends game first. Otherwise, you cannot play.
At this point, your JDK configuration is complete.
At this time, we can try to use javac and java in any other location. Check whether the operation is successful.
If the configuration fails, the following situations may occur:
Step 4: The first JAVA program
Create a java directory under drive D. Create a text document in it.
Change its name
HelloWorld. java
Remember the suffix. java. At this time, the system will prompt you to change the suffix name, which may make the file unusable. Click OK.
Next, you write the following code in Notepad:
Public class HelloWorld
{
Public static void main (String [] args)
{
System. out. println ("Hello World! ");
}
}
Save the settings.
Access this directory through cmd.exe.
Perform javac compilation first.
D: \ java \ javac HelloWorld. java
Step 1
At this time, a HelloWorld. class file is generated under the java directory.
Then, run java.
Enter java HelloWorld and press Enter.
Step 2. If the program runs successfully, the Hello World is displayed below!
So far, your JDK configuration is complete, and you have run the first program for verification to prove its normal use. Don't treat others, immediately enter your Java learning career.