JDK environment variable configuration and dos test JAVA program

For Java program development, two commands of JDK are mainly used: javac.exe and java.exe. Path: C:\Java\jdk 1.8.0_111\bin. However, since these commands do not belong to windows' own commands, if you want to use them, you need to configure the path


1. Right-click My Computer ------Properties-----------Advanced System Settings

Two, advanced ----- environment variables


3. System variables

          New -> variable name " JAVA_HOME ", variable value "d :\Java\jdk1.8.0_111 " (that is, the installation path of JDK)

4. Double -click the system variable name " Path " to open it, and add " ; %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin " at the end of the original variable value, and pay attention to the separator.


5. New -> variable name " CLASSPATH ", variable value " .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar "

      Note the small dot in front. Confirm, then confirm to exit.


6. Confirm whether the environment variable configuration is correct

      win+R-->enter cmd-->confirm-->

         Enter the command:   java

      javac

        The java -version  test was installed successfully.


   JAVA command:



javac command:


     

 java -version command:




7. Verify the first java program under the console:

public class Hello {
    public static void main(String[] args) {    
    System.out.println("Hello Java");
    }
}

Write it in Notepad, click "Save" to save it as ".java" format, and save it in the root directory of D disk,

Enter the javac Test.java command to compile:


Then enter the java Test command to run the program


(prints out the result "Hello Java"). Note: These two commands are in the D:\java\jdk1.8.0_111\bin directory.

Program analysis:

 

First write the java source code program, Hello.java ;

In the command line mode, enter the command: javac Hello.java to compile the source code and generate a class bytecode file;

After the compilation is complete, if there is no error message, enter the command: java Hello to interpret and run the class bytecode file, and do not need to add the .class extension during execution. See below:

 

Note: If the javac test.java command is entered in the CMD, it is displayed that 'javac' is not an internal or external command, because the JDK development environment has not been installed in advance or the environment variable configuration is incorrect. 



      

Guess you like

Origin blog.csdn.net/u014304688/article/details/54203886