wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Class and Java file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Class and Java file" Watch "Class and Java file" New topic
Author

Class and Java file

Thirumalai Muthu
Ranch Hand

Joined: Oct 07, 2007
Posts: 75
Hi, Why should the name of the Java file and the class having the main method be the same?

Waiting for reply. Thanks


SCJP 5
Dean Jones
Ranch Hand

Joined: Dec 29, 2007
Posts: 129
It is not a requirement, if the class is not marked public.
Thirumalai Muthu
Ranch Hand

Joined: Oct 07, 2007
Posts: 75


I typed the above code in the notepad and named the file as b.java. The compile was successful but when the program was run I got a No Classdef exception. Can anyone explain why this is happening?

Hi Dean you said that only if the class having the main method is marked public,then the file name and the class name should be same. I got that point.

But my question is how do you compile the above "class a" which resides inside the file called "b.java"
[ January 07, 2008: Message edited by: Thirumalai Muthu ]
Ganesha Kumar
Ranch Hand

Joined: May 04, 2006
Posts: 56
When you compile b.java, the class that is generated is a.class. You have to run the class a. Then you don't get ClassNotFoundException.
Thirumalai Muthu
Ranch Hand

Joined: Oct 07, 2007
Posts: 75
Ok Thanks ganesh I got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class and Java file