Java command line profile

xiaoxiao2021-03-05  52

Mainly introduces the use of Java and Javac commands.

Band package and without package,

Use the -classpath parameter if you want to use the third party package.

No package

Hello.java

Public Class Hello

{

Public static void main (String [] args) {

System.out.Println ("Hello");

}

}

C: /java/hello/hello.java

Compile

C: / java / hello> javac hello.java

Generate Class files

C: /java/hello/hello.class

run

C: / Java / Hello> Java Hello

2. Situation with package

The source file should be put on the package directory, which is definitely a good habit

Hello.java

Package my; // Note this sentence

Public Class Hello

{

Public static void main (String [] args) {

System.out.Println ("Hello");

}

}

C: /java/hello/my/hello.java

Compile

C: / java / hello / my> javac hello.java

Generate Class files

C: /java/hello/my/hello.class

run

C: / java / hello> java my.hello

3. The use of the-classpath parameter

Jar01.jar; jar02.jar; ...; jarn.jar class_name.java

Java -classpath.; jar01.jar; jar02.jar; ...; jarn.jar main_class_name

转载请注明原文地址:https://www.9cbs.com/read-31893.html

New Post(0)