8

Example: I have some source code, FooBar.java

javac FooBar.java

that gives me FooBar.class.

Why does the JVM command line API take FooBar instead of FooBar.class (working on UNIX FYI)?

Zong
  • 6,160
  • 5
  • 32
  • 46
  • 2
    dublicate, http://stackoverflow.com/questions/8651140/why-compiler-needs-java-suffix-but-interpreter-doesnt-need-class-suffix http://stackoverflow.com/questions/8755746/why-javac-requires-java-extension-and-java-doesnt-require-class-extension – Ahmet Karakaya Nov 25 '13 at 21:00

2 Answers2

5

That's just a convention! Classes are loaded using their fully qualified class name. The ClassLoader then knows how to map class names to file names (e.g. by appending '.class').

isnot2bad
  • 24,105
  • 2
  • 29
  • 50
4

Just because you have to tell the JVM the name of the class you want to run, not its actual filename. Another example, if your class was myPackage/FooBar.java you would compile to myPackage/FooBar.class, though you would put myPackage.FooBar as jvm argument.

Michael Zilbermann
  • 1,398
  • 9
  • 19