Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why javac requires .java extension and java command does not?

 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was wondering in order to run javac, i need to run the command as javac helloDark1.java


But to run the interpreter i need to run as "java helloDark1" not as "java helloDark1.class". Why that so?
 
John Jai
Rancher
Posts: 1776
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac compiles the source file, hence it needs a Java file name. java command runs a Java class, and hence it needs a Java class name (not the .class file name).
 
Manu Somasekhar
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,

Thanks for your help.

As per this link:-


java documentation


"The java tool launches a Java application. It does this by starting a Java runtime environment, loading a specified class, and invoking that class's main method"
So the input of javac is the java file and the input of java is class which contains the main method.

Thank you .

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic