Laboratory Exercises For Computer Science 153

Notes on Elementary Java

Summary: The following notes highlight the in-class discussion of a Course class, as defined in ~walker/public_html/courses/153.sp02/Course.java. These notes are not designed to be comprehensive. Rather, they provide a brief commentary on the program -- starting at the first lines of code and proceeding through to the end.

Comments

Java programs identify comments in two ways:

Class Definitions

Java supports object-oriented problem solving, and all programs in Java begin with classes and objects. Thus, each program component is a class, and a file begins with the declaration of one class. In the example, the class Course is identified as public, meaning that any application is allowed to utilize this class in its work.

Fields

Constructors

Whenever objects are created from classes, all fields are initialized.

Extractor and Modifier Methods

Extractor methods return data from various fields, while modifier methods change the values stored in those fields.

Brackets

In Java, the brackets { and } serve as begin and end markers, just as parentheses do in Scheme.

Strings and String Operations

Java contains strings and string operations that are analogous to those in Scheme.

Java's main Method

Once we defined classes in Scheme, we tested and used them in separate code, and Java also allows classes to be used by other classes and programs. In addition, Java allows any class to have a main method, which can be used to run a program based on the given class.


This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~walker/courses/153.sp02/lab-intro-java-2.html

created April 8, 2001 by Henry M. Walker
last revised March 28, 2002
Valid HTML 3.2!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.