Using the command line to compile and run Java classes

Using the command line to compile and run Java classes

System Environment

Windows 10 64bit
Java 8 64

General Java class

java file

Current Location: c: \ java \ Hello.java

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

Compile

Current Location: c: \ java

javac *.java

run

Current Location: c: \ java

java Hello

Comprising the Java class package name (in the absence package configuration)

java file

java file

Current Location: c: \ java \ Hello.java

package com.study;

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

Compile

Current Location: c: \ java

javac -d . Hello.java

Description of the command:
-d: specifies the placement of the generated class files
: directory represents the operation of the class file, referred to herein as java directory
More Reference Description cmd: javac -help

run

Current Location: c: \ java

java com.study.Hello

Java class includes the package name (package name directory structure and consistency)

java file

Current Location: c: \ java \ com \ study \ Hello.java

package com.study;

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

Compile

Current Location: c: \ java

javac com\study\Hello.java

run

Current Location: c: \ java

java com.study.Hello

Jar with third-party classes (accounting positions added later)

java file

Compile

run

Released five original articles · won praise 4 · views 10000 +

Guess you like

Origin blog.csdn.net/u012117531/article/details/104697649