Due to the need to run the java project on the command line. First of all, there must be jdk on the computer, which is a necessary condition. Secondly, you can create a new project folder, such as ShowTime, and then create a new src folder (just for convenient management, not necessarily necessary), then you can create a new java file in it.
import java.util.*;
public class HelloDate{
public static void main(String[] args){
System.out.println("Hello,it's:");
System.out.println(new Date());
}
}
In this way, name it time.java
and then operate on the command line, first enter the src folder, and then type:
javac time.java
At this time, an error is reported, because the file name is inconsistent with the class name, so change the file name to HelloDate.java, and type again:
javac HelloDate.java
At this time, no error is reported, indicating that the compilation is successful!
Then according to many blog tutorials on the Internet, type the following command:
java HelloDate.class
It was wrong... So I changed it to another way of writing, and it's still the same.
Finally found a solution online:
java -cp ./ HelloDate
Finally it worked!
As for compiling multiple java files, use the following command:
javac *.java
It's ok, you must choose a class with a main method to run when running!