Here are some corrections/comments to the
Maha
reply.
You can create an empty file (example EmptyClass.java) with no code and compile, it works!!!. It will not create any class files, since no class definition. Hey What is the use???
Noting. But adds the completeness to definition of Java program skeleton.
You can have only one package statement per Java source file.
You will get the following error message:
<pre>
F:\Java\EmptyClass.java:2: Class or interface declaration expected.
package xyz;
^
1 error
</pre>
If you comment out any one of the package statement, it complies fine.
You does not need to have import statement always.
You does not required to have class in a Java source file, but does not make any sense when you have no class definition. I will complete agree with you on 'maximum one public class per Java source'.
You can not declare the class to both abstract and final. You might already know it, but overlooked at it while posting. It should abstract or final. Here is an example.
extends is optional in the class declaration. If noting is specified it extends from Object class.
implements is optional in the class declaration.
When no constructors are specified for a class, at the compile time Java compiler inserts a default constructor for the class.
You can have 0 or more instance and/or static methods.
Note: My changes are in
green color.
<pre>
//comments can come anywhere
package ... ( 0 to 1 statement )
import ... (0 ... n statements)
class ....( 0 ... n classes but maximum 1 public class )
Inside pacakge-level class
--------------------------
(public/default) abstract/final <ClassName> extends <OtherClassName> implements <InterfaceType1>, <InterfaceType2>, ... {
class variables declaration and initialization
instance variables declaration and initialization
inner class declaration (both static and non-static)
inner interface (both static and non static)
//static floating block
static {
}
//instance floating block
{
}
//constructors (0 ... n constructors)
class level (static) methods (0 ... n methods)
instance level (without static keyword) (0 ... n methods)
} </pre>
Any comments are most welcome.
[This message has been edited by Manju Swamy (edited April 18, 2000).]