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.
// 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 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.
- General Information
- Application Description
- Required Packages
- Application Class
- Demo
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.
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.
One can interpret the text fragmentIO.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:
- IO is the receiving object. A receiving object is an object to which a particular message is directed.
- println("The coffee is good!") is the message being sent to the receiving object. A message is a request made of an object to perform some behavior.
- In response to being sent the message println("The coffee is good!") the object IO displays the string "Coffee is good." followed by a return. This response is termed a behavior. A behavior is simply a response to a message. The term behavior is used at a level of conception above the Java language level. In Java, behaviors are realized by methods.
- There is a method called println associated with the IO class which implements the behavior of displaying a character string to the standard output file. A method is simply a program which implements a behavior.
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
Message Behaviors
- IO.println(<String>)
- IO.print(<String>)
- IO.println(<int>)
- IO.print(<int>)
- IO.println(<float>)
- IO.print(<float>)
- IO.println(<boolean>)
- IO.print(<boolean>)
- IO.println()
- Print the given <String> to the standard output file, followed by a new line.
- Print the given <String> to the standard output file.
- Print the given <int> to the standard output file, followed by a new line.
- Print the given <int> to the standard output file.
- Print the given <float> to the standard output file, followed by a new line.
- Print the given <float> to the standard output file.
- Print the given <boolean> to the standard output file, followed by a new line.
- Print the given <boolean> to the standard output file.
- Issue a new line command to the standard output file.