CSCI111: Chapter 4

CSCI311: Writing Classes


Summary


Java programs that do not run on a browser (i.e., not Applets) need a main method to get them started. The main method

is the top-level method that initiates execution of a system.
Note that the main code needs to explicitly instantiate the class and call a method to get it started (applets don't have to do this).

The book focuses on these (applications), but I will continue to show both.

Applets and JApplets need .html pages with applet tags to be shown on browsers

Here is a Class template:


imports ... 

public class ClassName extends  super  {

             // Declare and possibly set values for variables

  Instance and Class Variable declarations 

  private int instanceVariable;
  public static int classVariable;

             // Define Constructors (if none - looks at supers.  No return type)

   public ClassName (formal parameters) {

     code

  }
            // Define methods with no returned values

  public void methodName (formal parameters) {

     code

  }
            // Define methods with return values

  public returnType methodName (formal parameters) {

     code
     return ...   // returnType of value returned must match method signature

  }
}


Java 1.5 API

OK, we have Classes and their Instance/Class variables and methods

Note then, when we look at packages (e.g. java.lang), we see other Summaries: Interface, Class, Exception, and Error