Contents Index Subclasses in Java Class constructors

ASA Programming Guide
  Introduction to Java in the Database
    A Java seminar

Understanding Java objects


A class is a template that defines what an object is capable of doing, just as an invoice form is a template that defines what information the invoice should contain.

Classes contain no specific information about objects. Rather, your application creates, or instantiates, objects based on the class (template), and the objects hold the data or perform calculations. The instantiated object is an instance of the class. For example, an Invoice object is an instance of the Invoice class. The class defines what the object is capable of but the object is the incarnation of the class that gives the class meaning and usefulness.

In the invoice example, the invoice form defines what all invoices based on that form can accomplish. There is one form and zero or many invoices based on the form. The form contains the definition but the invoice encapsulates the usefulness.

The Invoice object is created, stores information, is stored, retrieved, edited, updated, and so on.

Just as one invoice template can create many invoices, with each invoice separate and distinct from the other in its details, you can generate many objects from one class.

Methods and fields 

A method is a part of a class that does something—a function that performs a calculation or interacts with other objects—on behalf of the class. Methods can accept arguments, and return a value to the calling function. If no return value is necessary, a method can return void. Classes can have any number of methods.

A field is a part of a class that holds information. When you create an object of type JavaClass, the fields in JavaClass hold the state unique to that object.


Class constructors

Contents Index Subclasses in Java Class constructors