Home  >  Article  >  Java  >  How to execute java program

How to execute java program

藏色散人
藏色散人Original
2019-11-13 10:15:032265browse

How to execute java program

How to execute java?

Use CMD to execute Java program

1. Execute a single java class

1. Create a notepad and enter (remember java is case-sensitive)

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

2. Save the notepad as helloworld.java (note the file name To be consistent with the class name), save it to, for example, D:\java

3. Run cmd, enter

d: Enter (locate to the D drive)

cd java Press Enter (locate to the folder)

4. Generate the HelloWord.class file

Enter javac helloworld and press Enter

5. Run the helloworld program

Enter java helloworld Enter

6. Compile and output Hello World

2. Execute the java class under the specified package

1. Create a notepad, Enter (remember that java is case-sensitive)

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

2. Save the notepad as helloworld.java (note that the file name must be consistent with the class name), and save it to, for example, D:\java

3 , run cmd, enter

d: press enter (locate to the D drive)

cd java press enter (locate to the folder)

4. Generate the HelloWord.class file

Enter javac -d . helloworld.java and press Enter

5. Run the helloworld program

Enter java AAA/helloworld or java AAA.helloworld and press Enter

6. Compile and output Hello World

3. The executed java class references other java classes

For example, if you want to execute the A.java class under Package X1, However, A.java references the B.java class under Package X2. In this case, the steps are as follows:

1) Copy all classes A.java and B.java to a specified path, such as D :\java

2) Run cmd, enter

d: Enter (locate to the D drive)

cd java Enter (locate to the folder)

3) Generate class file

Enter javac -d . *.java and press Enter

4) Run A.java program

Enter java X1.A

4. Two java classes need to be executed at the same time, such as the communication between the client and the server.

You only need to open two cmds and execute them separately, but you need to pay attention to which java is executed first. kind

The above is the detailed content of How to execute java program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is proxy in javaNext article:What is proxy in java