<< Chapter < Page Chapter >> Page >

These are the objects that you instantiate in you code by applying the new operator to a constructor for a class in order to create a new instance (object) of that class. (There are also a couple of other ways to create ordinary objects, but I'm not going to get into that atthis time.)

Array objects

I haven't discussed array objects thus far in this collection. (I will discuss them in a future module.)

Suffice it for now to say that array objects are objects whose purpose is to encapsulate a one-dimensional array structure that can contain either primitivevalues, or references to other objects (including other array objects).

I will discuss Class objects in this module.

Discussion and sample code

Class objects

Let me emphasize at the beginning that the following discussion is conceptual in nature. In this discussion, I will describe how the Java system behaves, not necessarily how it is implemented. In other words,however it is implemented, it behaves as though it is implemented in the manner described below.

The class named Class

There is a class whose name is Class . The purpose of this class is to encapsulate information about some other class (actually, it can also be used to encapsulate information about primitive types as well as classtypes).

Here is part of what Sun has to say about this class:

"Instances of the class Class represent classes and interfaces in a running Java application. ...

Class has no public constructor. Instead Class objects are constructed automatically by the Java Virtual Machine as classes areloaded ..."

What does this mean?

As a practical matter, when one or more objects are instantiated from a given class, an extra object of the Class class is also instantiated automatically. This object contains information about the class from which theobjects were instantiated. (Note that it is also possible to cause a Class object that describes a specific class to be created in the absence of objects of that class, but that is a topic that will be reserved formore advanced modules.)

A real-world analogy

Here is an attempt to describe a real-world analogy. Remember that a class definition contains the blueprint for objects instantiated from that class.

A certain large construction company is in the business of building condominium projects. This contractor builds condos of many different sizes,types, and price ranges. However, each different condo project contains condos of only two or three different types or price ranges.

A library of blueprints

There is a large library of blueprints at the contractor's central office. This library contains blueprints for all of the different types of condos thatthe contractor has built or is building. (This library is analogous to the class libraries available to the Java programmer.)

A subset from the blueprint library

When a condo project begins, the contractor delivers copies of several sets of blueprints to the construction site. The blueprints delivered to that sitedescribe only the types of condos being constructed on that site.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask