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

2

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

Auburn answered 25/11, 2013 at 20:53 Comment(1)
dublicate, #8651640 #8756246Orazio
S
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').

Sectional answered 25/11, 2013 at 20:56 Comment(0)
G
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.

Gareth answered 25/11, 2013 at 20:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.