This time I will talk to you about how to use Java after installation. I was confused when I first came into contact with Java. I thought that I could start Java programming directly after installing the Java software. In fact, otherwise, I had to set up small development conditions.
Recommended tutorial:Java introductory video tutorial
1. First install jdk
Let me explain here first, only installing Java cannot compile and execute Java programs, so we actually install jdk, and installing java is just to install jre (Java runtime environment).
I believe everyone knows that jdk is the core of Java.
To download jdk, I suggest you go to 360 Software Manager to search and download, it is simple and convenient.
Tip: Installing jdk will automatically install java, so you don’t need to install java separately. If you have already installed java before, you can click Close in the upper right corner to exit the java installation when installing jdk to the step of installing java. . (Basically, you just need to click Next, and you only need to select the default installation directory.)
2. Configure Java environment variables
Open Computer Properties, "Advanced System Settings" → "Environment Variables",
Create a new variable The name "JAVA_HOME" value is "jdk installation path"
The new variable name "CLASSPATH" value is ".;%JAVA_HOME%\lib"
Modify the variable name "path" and add "%JAVA_HOME%\bin;" at the front
##3. Installed. Start writing programs.
Congratulations! Once the above steps are completed, we can start writing the program. Are you a little impatient? hey-hey. Create a new text file on the desktop and paste the following contentpublic class HelloWorld{ public static void main(String []args) { System.out.println("hello world"); } }
## Exit and click Save
Change the extension to java and the file name to HelloWorld (H and W are capitalized)
Hold down the shift right button of the mouse and select "Open command window here" to open cmd
Enter javac (a space) HelloWorld.java and press Enter. At this time, a word HelloWorld.class will be generated on the desktop. Section code file, this is the compiled file
Then execute java (a space) HelloWorld
Congratulations! "hello world" appears!
##
The above is the detailed content of How to use java. For more information, please follow other related articles on the PHP Chinese website!