![How to execute java (command execution)](https://img.php.cn/upload/article/000/000/039/5ddb3fd554a27619.jpg)
Method to execute java files: (Related video tutorial recommendations: java video tutorial)
Using environment: jdk1.6
![157464939757497How to execute java (command execution) How to execute java (command execution)](https://img.php.cn/upload/image/383/418/290/157464939757497How%20to%20execute%20java%20(command%20execution))
File directory:
![157464942959828How to execute java (command execution) How to execute java (command execution)](https://img.php.cn/upload/image/667/887/127/157464942959828How%20to%20execute%20java%20(command%20execution))
##javac *.java will generate the corresponding *.class file
java *.class can be executed, .class can be omitted
1. There is no package in t.java
public class t{
public static void main(String[] args) {
System.out.println("Hi");
}
}
The first way
![1574649484600059.jpg How to execute java (command execution)](https://img.php.cn/upload/image/902/858/312/1574649484600059.jpg)
The second way
![157464958690517How to execute java (command execution) How to execute java (command execution)](https://img.php.cn/upload/image/384/845/206/157464958690517How%20to%20execute%20java%20(command%20execution))
2. a.java is packaged
package test;
public class a{
public static void main(String[] args) {
System.out.println("Hi");
}
}
The first way
![1574649640230680.jpg How to execute java (command execution)](https://img.php.cn/upload/image/253/759/523/1574649640230680.jpg)
The second method
![1574649671953388.jpg How to execute java (command execution)](https://img.php.cn/upload/image/437/763/116/1574649671953388.jpg)
Because a.java contains all the class files of the package, when executing the class file, you need to return to the layer where the package is located. Then execute
through the package name.
The above is the detailed content of How to execute java (command execution). 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