next up previous
Next: 1.3 Java Notation and Up: 1. From Scheme to Previous: 1.1 Introduction

1.2 What is an Object?

Before discussing the specifics of Java's object system, let's define what an object is. Within a computer program, an object consists of

Typically no code other than the designated operations can modify object fields.

To make the notion of object more concrete, let's consider a simple example. Assume that we want to write an simple accounting program for a snack food cooperative run by graduate students. (Such a cooperative actually exists in Duncan Hall at Rice.) Every participant in the cooperative has an account.

A minimal accounting system could define an object to represent each account. Each such ``account'' object would consist of an integer field balance holding the balance for that account (in cents) and two void operations: charge(integer amt) which subtracts amt from the account balance and deposit(integer amt) which adds amt to the account.

Members of the cooperative can either deposit money in their accounts or purchase items by charging their accounts. You may have seen a similar example in Scheme in Comp 210.

Let's summarize the form of an account object as a table:

    Fields:
        integer balance

    Methods:
        void charge(integer amt)
        void deposit(integer amt)
This tabular description is NOT legal Java syntax, although it uses the Java keyword void. We will introduce the actual syntactic details later in our discussion.


next up previous
Next: 1.3 Java Notation and Up: 1. From Scheme to Previous: 1.1 Introduction
Robert Cartwright, Spring 1999