//Comments begin with a “//”.  Note that all keywords are written in red

//in the comments.

 

 

//*******************************************************************

// Lincoln.java         Author: Lewis and Loftus

//

// Demonstrates the basic structure of a Java class

//*******************************************************************

 

//the Java interpreter or compiler ignores all of the characters after “//”

//the syntax for a class definition is “modifer class class-identifer”.  In

//this case, the modifer is public and the identifier is “Lincoln”.

//Identifiers like “Lincoln” are chosen by the person who writes the

//program, but the name chosen must follow the rules of Java.

//public means that the whole world has access to this class.

 

 

 

public class Lincoln

{           //Again, notice that the class is contained in

            //a opening brace “{“ and

            // a closing brace “}”

 

      //---------------------------------------------------

      //    A class to print a presidential quote

      //---------------------------------------------------

 

            //A method has the format modifier returnType identifierName.

            //The modifier is public, meaning it is accessible to the

            //world.  It does not return anything, so it has the void as

            //the return type. void means nothing is returned.

 

      public void quote()

      {     //The method’s definition is contained between

            //the opening brace “{“ and

            //the closing brace “}”

 

            System.out.println("A quote by Abraham Lincoln:");

 

            System.out.println("Whatever you are, be a good one.");

      }

}

 

//The System.out.println is a call to a Java supplied class (an API)

//”System”, which contains a class of type PrintStream called “out”, which

//has a method called “println”.  This sends whatever is in the quotes

//to the standard output, which is the console window.

 

//So “System.out.println” is a simple way for the program to communicate

//with the outside world.  It sends output to the console window.  It

//only sends “Strings” to the outside world. 

 

 

 

 

 

//*******************************************************************

// testLincoln.java           Author: Lewis and Loftus

//

// Demonstrates the basic structure of a Java application

//*******************************************************************

 

 

 

public class TestLincoln

{                 // the class definition is contained

// between “{“

// and “}”

 

 

      //---------------------------------------------------

      //    Calls class to print a presidential quote

      //---------------------------------------------------

 

      public static void main(String[] args)

      {           //the definition of the method “main is

                  //also contained between “{“

                  // and “}”

 

            Lincoln example = new Lincoln();

 

            example.quote();

      }

}

 

//Insider the class we have one method, whose name is “main”.

//All java programs start at the method called “main”, so there can

//be at most one method called “main” in a Java program.  This program

//creates an object of type “Lincoln”, defined above.  The object is

//given a name of “example”, a user defined name.  The keyword new

//means create a new object of this class.  “main” returns nothing

//so its return type is void, and it is public so that the world has

//access to it.  The term static attached to the method “main” 

//signifies that “main” is class method and is not attached to any

//object. 

 

//Finally, the method “quote” of the object “example” is called

//from the class Lincoln.  The method “quote” then prints out the

//quote from Abraham Lincoln.  The method “quote” is not a static

//method, and hence can only be called though an object of the class.