aspose file tools
The moose likes Beginning Java and the fly likes why .class is not specified during execution Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "why .class is not specified during execution" Watch "why .class is not specified during execution" New topic
Author

why .class is not specified during execution

Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 204

If we have to execute a class Student.class, we run it as

java Student

question is, why do we omit .class extension while executing? Why not following:

java Student.class


-Varun -
(My Blog) - Mock Tests
Sid Murrey
Ranch Hand

Joined: Jul 07, 2008
Posts: 58
Just a wild guess.. The JVM takes all the .class files it finds in the directories specified by the classpath and stores them using the package and class name in a list. When you specify the class to execute, the JVM does not associate that class name with a specific file, but with the real class stored in memory?

Just thinking here.. No facts! Just what I would handle it as a JVM programmer ;-)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Close; a class is only loaded when it is needed. But you are right that it uses the class name (including full package), and not the class file.

Of course it will read the file when the class is first needed, but that is handled by the ClassLoader after a request for a class (name) has come in.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
That's the way Java was designed. Might be because the people who designed it came from the Unix tradition of calling executable code by their names without an extension.

Apart from that, don't know. I have always looked on it as "one of those things."
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 204

Thanks Friends.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: why .class is not specified during execution
 
Similar Threads
Java program file name question
targetEntity and erasing early
Difference in HQL and Criteria
Why we have to write .java when we compile a program
Why Stringbuffer not implemented equals method