Java file compilation with file extension
•
Java
When we compile Java programs, we use javac file Java commands, but we use java files at runtime
So why is it necessary to explicitly specify the file extension at compile time and not when running Java programs?
Solution
Because when you "run" Java Class when compiling the file, you tell the Java application launcher which class contains the main method The launcher starts the Java runtime environment and loads the specified classes
If you write java MyClass, the class with the main method is MyClass Notice that you write java MyClass Class is wrong because MyClass Class is not the name of the class
Use javac MyClass When compiling Java, you need to tell the java compiler the extension, because it is a file and you need to find it
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码