Java Learning (1), download, configure environment variables, first demo, environment variable demo
1. download java JDK in http://www.oracle.com
Install it to a custom location.
2. Configure environment variables: on my computer → advanced system settings → Environment Variables
① Add a new Path to the Path (this Path is the bin where JDK is stored, for example, I placed it under D: \ J2EE \ JDK1.8.0 \ bin). separate the two paths with extra points.
② To prevent path changes, you can add a variable, which is customized by the variable name. The variable value is the JDK storage path.
Add a new Path named % JAVA_HOME % \ bin under Path.
Save and run (win + R) cmd. Type java-version to view the jdk version. (if not configured, the path should be directed to the binfile)
3. Complete the first demo and edit it in the text document.
Create a text document with the suffix. java. Edit the document and enter the content
1 public class First {2 public static void main (String [] args) {3 System. out. println ("FirstJava"); 4 System. out. print ("FirstJava \ n"); 5 System. out. println ("FirstJa \ tva"); 6} 7}View Code
After public is added, the method name must be the same as the file name. Only one public method (public) with the same file name can be used in a file, and no public method is required for other methods.
4. Run (win + R): cmd. First, enter ① d: (Open d disk) ② cd JavaStudy (under JavaStudy folder) ③ javac First. java (generate. class file)
④ Java First (execution method)
5. Generate classpath (temporary configuration): ① set classpath = d: \ JavaStudy (set the classpath path)
② Java First (execution method, which can be executed in any path)
8. Generate classpath (permanent): On my computer → advanced system settings → Environment Variables
Add a classpath variable, specify the path D: \ JavaStudy, and re-open cmd.