File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A Beginner Question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A Beginner Question?" Watch "A Beginner Question?" New topic
Author

A Beginner Question?

Owee Nicolas
Ranch Hand

Joined: Jun 16, 2002
Posts: 49
Is an empty file a valid source file?


Owee<br />SCJP 1.4
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
I deleted the answer I posted until you can confirm that this is not a homework problem.
[ June 16, 2002: Message edited by: John Dale ]
Owee Nicolas
Ranch Hand

Joined: Jun 16, 2002
Posts: 49
Hi John,
This is not a homework problem. I saw this question in Chapter 2: Language Fundamentals of Mughal's book. I posted it here because there are no Java experts here in our office to answer my question. Although I think the answer is NO. I mean I tried compiling an empty file and it compiled ok but when I ran it, I got a NoClassDefFoundError which only means that this isn't a valid source file. Am I correct?
[ June 17, 2002: Message edited by: owee nicolas ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Unless I'm not thinking clearly...
I tried compiling an empty file and it compiled ok
That means that it is a valid source file - the source file compiled ok.
but when I ran it, I got a NoClassDefFoundError
That means that it isn't a very useful class file - there is no actual class definition and so it serves no practical use.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
Right. The empty file seems to be a valid source file according to the according to the Java Language Specification (2nd Edition)section 3.5, Input Elements and Tokans, and section 7.3, Compilation Units.
However, when you ask "java" to run a class B, you are asking it to run a class, not a file. It's convention is that, if the class is not alreay loaded, it looks for the class in a file called B.class (among other places). But that class could be defined in a source file by any name, for example, in A.java. I think it is a requirement of some compilers (such as the JDK's javac), that a PUBLIC class must be specified in a .java file that matches the name of the class, but there is no such rule for non-public classes. Hence, it is legal to have a source file A.java that contains non-public class B, and produces a bytecode file called B.class .
Owee Nicolas
Ranch Hand

Joined: Jun 16, 2002
Posts: 49
Great! Got my answer
Thanks for all the response!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Beginner Question?