user2563044
user2563044

Reputation:

Why do you remove .class when executing on the JVM?

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)?

Upvotes: 8

Views: 239

Answers (2)

Michael Zilbermann
Michael Zilbermann

Reputation: 1428

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.

Upvotes: 4

isnot2bad
isnot2bad

Reputation: 24454

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').

Upvotes: 5

Related Questions