Valid XHTML 1.0!

Package Declaration, Import statements and class definition.



Package statement, import statements and class definition MUST appear in the order given. If this order is not maintained, the java file will fail to compile.
Please note that package declaration, import statements may/may not be present. However, if they are present they must appear in the order, i.e. package declaration, followed by import statements, followed by other class definitions.


1
 package com.witscale.scjp.examples;        // Package declaration
2
 import java.util.Vector;                   // import statement(s)
3
 public class Test {                        // class declaration.
4
5
   public static void main(String[] args) {
6
     Vector names =  new Vector();
7
     names.add("Mickey");
8
     names.add("Pluto");
9
     names.add("JarJar");
10
     System.out.println(names.elementAt(1));
11
   }
12
 }





The following code will fail to compile.


1
 import java.util.Vector;                   // import statements should come after package declarations
2
 package com.witscale.scjp.examples;        // Package declaration
3
 public class Test {                        // class declaration.
4
5
   public static void main(String[] args) {
6
     Vector names =  new Vector();
7
     names.add("Mickey");
8
     names.add("Pluto");
9
     names.add("JarJar");
10
     System.out.println(names.elementAt(1));
11
   }
12
 }