File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes !!!MOST UNBELIVEABLE!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "!!!MOST UNBELIVEABLE!!!" Watch "!!!MOST UNBELIVEABLE!!!" New topic
Author

!!!MOST UNBELIVEABLE!!!

Amit Roy
Ranch Hand

Joined: Oct 10, 2000
Posts: 132
Dear frns,
examine the code below carefully and just tell wethet it will compile.

yes the code above will compile !!Zapped !!!
YES A FULLY EMPTY FILE IS A VALID SOURCE FILE AND COMPILES WITHOUT ANY ERROR
can any one give me a logical explanation?
also
A Java file without any class or interface definitions can also be compiled.
AMIT

<I>Chance Favours the Prepared minds"</I>
Ramesh Kadur
Greenhorn

Joined: Nov 13, 2000
Posts: 11
Amit,
See whether you get any class file when you compile an empty file. You don't get any. That means there is nothing to compile. To answer your second part, in Java, everything has to be in a class. You can not have free standing methods or variables as in C. If you have some variable or method not inside any class, then compiler issues this error message:
Class or interface declaration expected
Ramesh.
Bob Lulyk
Greenhorn

Joined: Nov 05, 2000
Posts: 5
Dear Amit:
The Java Language Specification basically says that a Java
source file consists of the following 3 parts:
1. An OPTIONAL package statement
2. ZERO or more import statements
3. ZERO or more class definitions
Therefore, there's nothing stopping you from compiling
successfully an empty source file (of course, it's absolutely
useless -- but that's another matter entirely).
Hope that helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: !!!MOST UNBELIVEABLE!!!