Next:
Lecture 2
Lecture 1 Handouts
-
Course outline
-
Assignment 0
-
Doing your work in CSC108S
Announcements
The Faculty of Arts and Science wants me remind you that they have to
have either a "registration card" or a U of T photo library card. To get
an Arts and Science photo ID "registration card", students can come to
Ramsay Wright room 429 either during the regular hours (MW 9-12, R 2-5)
or during special evening hours:
5-7 p.m. on May 19, May 20, or July 14.
Because of overcrowding, in fairness to enrolled students, auditing
is discouraged.
IF THE COURSE IS FULL AT THE END OF THE FIRST WEEK OF CLASSES, NO LATER
ENROLMENTS WILL BE PERMITTED. That's a Faculty rule.
Readings
-
On the course Web page read:
-
General advice on assignments
-
Program and debugging advice
-
How to print ``Print Java Assignment''.
-
In the text read
-
Chapters 1 and 2
-
motivation for encapsulation p 145
-
Read Guide to VisualAge
-
Handouts
-
Course outline
-
Assignment 0
-
Doing your work in CSC108S
Humans versus Computers
-
computers are quicker at logic, sequence, selection and iteration but can't
easily be made to shift context.
-
people are better at establishing and changing context but attention sometimes
wavers and logic is faulty.
-
People naturally think in an object oriented way.
-
People have a working memory limit of 7+-2 objects.
-
Black box
-
class versus object
-
syntax versus semantics
-
algorithm versus program
Why use Java?
-
Java (capital J) is a high-level, third generation PL, like C, Fortran,
Smalltalk, Perl etc.
-
special about Java - it lets you write programs called applets that
can be downloaded from the Internet and played safely within a web browser.
-
Java is a platform for application development. A platform is a loosely
defined computer industry buzzword that typically means some combination
of hardware and system software that will mostly run all the same software.
What is Java?
-
The javac compiler, the java interpreter, the Java programming language,
and more are collectively referred to as Java.
-
Java was designed to make it much easier to write bug free code.
-
object oriented programming
-
data is represented by objects
-
Objects have two sections, fields (instance variables) and methods.
-
Fields tell you what an object is.
-
Methods tell you what an object does or can be done to it.
object oriented programming
-
These fields and methods are closely tied to the object's real world characteristics
and behavior.
-
When a program is run messages are passed back and forth between
objects.
-
When an object receives a message it responds accordingly as defined
by its methods.
Why Object Oriented?
-
Object oriented programming has a number of advantages
-
Simpler, easier to read programs
-
More efficient reuse of code
-
More robust, shorter, error-free code
Consider this java program
class HelloWorld {
public static void main (String[] args) {
System.out.println("Hello World!");
}
}
There are three steps to create a Java program:
In a command line environment (Unix or Dos) do this
| # |
Step |
Comment |
| 1 |
writing the code |
Use an editor on HelloWorld.java. The file name must match the class name, HelloWorld. |
| 2 |
compiling the code |
javac HelloWorld.java |
| 3 |
running the code |
java HelloWorld |
Computer Session at the PC site.
-
Login : h108xxxx
-
Passwd : Student number
-
run Visual Age for Java - double click
-
goto Workbench
-
create a new project - dialog box
-
type in class with main method
-
click on FILE & SAVE
-
click on Run Button
-
create data file - in scrapbook editor
-
FILE/export - programs to H: drive !!!
-
FILE/quit
-
Logout
Comments are to make code easier for people to understand Comments
are ignored by the computer:
/* use this anywhere
even splitting comments
over multiple lines */
// use this for end of line comments only
// This is the Hello World program in Java
class HelloWorld {
public static void main (String[] args) {
/* Now let's print the line Hello World */
System.out.println("Hello World!");
} // main ends here
} // HelloWorld ends here
What is a class? Fields say what an object is
Methods say what an object does
class Point {
double x;
double y;
}
What is an object? Create objects with the new keyword followed by a constructor:
Point origin = new Point();
origin.x = 0.0;
origin.y = 0.0;
System.out.println("The origin is at (" +
origin.x + ", " + origin.y +")");
Next:
Lecture
2.
Craig MacDonald
Fri May 15 16:09:12 EDT 1998