Computer Science Java Style
Introduction
Fundamental Notions and First Constructs

A First Java Program

The following is a first Java program. It simply prints the character string "The Coffee is good!" to the standard output file. Please don't be daunted by all of the documentation. You might ignore the "comments" on first glance, and just look at the instructions Java looks at, the ones which I have placed in bold. I plan to introduce you to a few elements of Java by way of "notes" pertaining to the program.

The Program - CoffeeApp

// General Information
// ------------------------------------------------------------

// File:  CoffeeApp.java
// Type:  java application file
// Date:  Sun Aug 27, 1995
// Name:  BLUE
// Line:  Variation "Hello world!", the traditional starter


// Application Description
// ------------------------------------------------------------

/*
   Program to display "The coffee is good!" to the standard 
   output file.
*/


// Required Packages
// ------------------------------------------------------------

   import blue.io.IO;


// Application Class
// ------------------------------------------------------------

   class CoffeeApp
   {
      static public void main (String args[])
      {
         IO.println("The coffee is good!");
      }
   }


// Demo
// ------------------------------------------------------------

/*
   indigo> javac CoffeeApp.java
   indigo> java CoffeeApp
   The coffee is good!
   indigo> 

*/

Comments

Comments are placed in a program for the benefit of the reader of the program. In Java, there are two fundamental varieties of comments, "remainder of line comments" and "multiple line comments".

// the computer disregards the chars to the end of line

/* this is a one
   two
   three line comment */
The simple application programs that you will write at the outset of this course of study conform to a well defined textual structure consisting of five clearly marked parts, as shown in the CoffeeApp program. That is, each will consist of the following five sections of text.
  1. General Information
  2. Application Description
  3. Required Packages
  4. Application Class
  5. Demo

Packages

A package is a collection of classes. The package blue.io includes an object called IO which responds appropriately to messages having to do with reading from the "standard input file" and writing to the "standard output file". The packages which begin with the word blue are provided for use with this text, and are intended to ease your transition from novice Java programmer to mature Java programmer.

Rule of Punctuation

A program is essentially a sequence of instructions. In Java, a sequence of instructions can be represented syntactically as some number of instructions, each terminated by a semicolon. The sequence of instructions in CoffeeApp is of length 1. The rule of punctuation in Java is that a semicolon terminates each statement.

The Object-Oriented Flavor

One can interpret the text fragment
IO.println("The coffee is good!")
as a message send. A message send is a construct which communicates a message to an object which, in turn, responds with some behavior. In Java, a message send has the form
<Object>.<Message>
Relative to the particular message send which appears in the example program, the basic ideas are instantiated as follows:

Specification - The IO Class of the blue.io Package (Output)

The IO class is one of three classes provided in the blue.io package. The others will be discussed and used at a later time. For now, I merely specify output methods associated with the IO class. There are nine methods which perform certain actions of information display to the standard output file.

Message Forms

  1. IO.println(<String>)
  2. IO.print(<String>)
  3. IO.println(<int>)
  4. IO.print(<int>)
  5. IO.println(<float>)
  6. IO.print(<float>)
  7. IO.println(<boolean>)
  8. IO.print(<boolean>)
  9. IO.println()
Message Behaviors
  1. Print the given <String> to the standard output file, followed by a new line.
  2. Print the given <String> to the standard output file.
  3. Print the given <int> to the standard output file, followed by a new line.
  4. Print the given <int> to the standard output file.
  5. Print the given <float> to the standard output file, followed by a new line.
  6. Print the given <float> to the standard output file.
  7. Print the given <boolean> to the standard output file, followed by a new line.
  8. Print the given <boolean> to the standard output file.
  9. Issue a new line command to the standard output file.

Craig Graci
Last modified: Tue Jan 21 12:49:13 EST