Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

When I compile a Java program, I use javac file.java, while I run the code I use java file. 

Can anyone tell me why one has to explicitly specify file extension during compilation and not when one runs the Java program?

1 Answer

0 votes
by (19.7k points)

When you compile, you do javac MyClass.java tell the compiler that it’s a file and you provide it with the extension for it to find. 

When you run the compiled file ‘java .class’, you tell the application launcher to start the Java runtime environment and load the specified class.

Interested in Java? Check out this Java tutorial by Intellipaat.  

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
asked Mar 29, 2021 in Java by dev_sk2311 (45k points)

Browse Categories

...