I completely forgot, so I remember it again.
There is main () in class.
The class name and file name should be the same, and the extension is class name.java
.
Compile to create classname.class
java class name
without extension! !! !! ** **$ cat HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
#compile
$ javac HelloWorld.java
#File is created
$ ll HelloWorld.class
-rw-r--r-- 1 root staff 426B 2 1 15:18 HelloWorld.class
#No extension is added at runtime! !! !!
$ java HelloWorld
Hello World!
#When I add an extension, I get this error
$ java HelloWorld.class
error:Main class Hello World.Could not find and load class
Cause: java.lang.ClassNotFoundException: HelloWorld.class
Recommended Posts