Writing a main() method

// Zoo.java <-- 1) Each file can contain only one public class
public class Zoo { // <-- 2) The filename must match the class nam
   public static void main(String[] args) { // <-- 3) An entry point
      System.out.println(args[0]);
      System.out.println(args[1]);
   }
}

Declared type on variable args

String[] args
String options[]
String.. friends

Passing Parameters to Java Program

java Zoo.java Bronx Zoo
..
Bronx
Zoo

Order for declaring a class

package structure;      // package must be first non-comment
import java.util.*;     // import must come after package
public class Meerkat {  // then comes the class (Required!!!)
   double weight;       // fields and methods can go in either order
   public double getWeight() {
      return weight; }
   double height;    // another field - they don't need to be together
}

Defining Text Blocks

Leave a Reply

Your email address will not be published. Required fields are marked *