Synopsis
In this class a basic outline of how we will write java programs for this class was defined. This included introduction to the java-app-template which is a predefined template that we can use to setup the ``boiler-plate'' of a java program.
Also covered were variables and definition of object-oriented were introduced.
|
Definition
A COMPUTER is a general purpose machine which can be made to act like a special purpose machine by means of a program
REMARK
We want to write programs in Java to render the computer a special purpose problem solver.
The Approach We Will Adopt
We will write Java programs (texts) by means of a ``template based slot & filler'' scheme noted below
/ /General Information
/ / ---------------------------------------------------
/ /File: CLASS.java
/ /Type: java application file
/ /Date: Wed Aug 28, 2000
/ /Name: AUTHOR
/ /Line: LINE
/ /Application Description
/ / ---------------------------------------------------
/ \*
DESCRIPTION
\* /
/ /Required Packages
/ / ---------------------------------------------------
import blue.io. \*;
NEEDS
/ /Application Class
/ / ---------------------------------------------------
class CLASS
{
static public void main (String args [])
{
PROGRAM
}
}
/ /Demo
/ / ---------------------------------------------------
/ \*
DEMO
\* /
|
Definition
A JAVA APPLICATION TEMPLATE is a text which is a Java program except for ``slots'' which must be ``filled''. These templates contain five textual sections: General Information, App Description, Required Packages, Application Class, Demo.
REMARK
A concise way of presenting a program in class is simply to display slots & fillers - since most of the other stuff is invariant technical information.
A presentation of ``Hello World'' using slots & fillers.
Class - > HelloApp
Author - > Craig Graci
Line - > A Classical First Program
Description - > Description
Needs - > Classes needed (i.e. java.lang.object. \*)
Program - > IO.println ( ``Hello World'');
REMARK
One can interpret the line IO.println ( ``Hello World''); in the following way:
- IO is an object.
- println ( ``Hello World'') is a message
REMARK
The basic mechanism of computation in object-oriented programming is the sending of messages to objects which respond with some form of behavior.
REMARK
In the sole executable instruction of the ``Hello World'' program...
The message println ( ``Hello World! '' ) is sent to the object IO which responds behaviorally by printing the string ``Hello World! '' to the standard output file.
Definition
OBJECT-ORIENTED programming is a style of programming which features the modelling of objects in a hierarchical fashion and the sending of messages to appropriately behaving objects.
Definition
A MESSAGE SEND is a construct of the form
< object >. < message >
which tells the computer to ``send the message to the object (which knows how to process it) .''
Hypothetical message sends
- hand.display ()
- dime.area ()
A Java program to read two integers and display their sum.
Program - >
/ /Read the two integers and store them away
int n1 = IO.read_int ();
int n2 = IO.read_int ();
/ /Compute the sum
int sum = n1 + n2;
IO.print ( ``The sum is: ``);
IO.print (sum);
IO.println ();
|
Demo
javac SumOfTwoIntsApp.java
java SumOfTwoIntsApp
12
7
The Sum is:19
Environment (bindings in memory)
n1- > 12
n2- > 7
sum- > 19
There are 5 message sends to IO.
Definition
A VARIABLE is a name (identifier) which represents some concept and which may denote a value.
Example
temp- > 79
suppose this represents the current temperature.
Example
classCount- > 137
REMARK
In Java all variables must be introduced by specifying the type of value they can denote.
Definition
a VARIABLE DECLARATION is the introduction of a variable into a program which specifies the type of value which the variable can denote.
Specification of Variable Declaration
< type > < identifier >
Example
int n1 = IO.read_int (); - this is a variable declaration