Java, OOP, and Array Objects: Part 1 Los Angeles CA

Creating array objects is not done in the same manner as ordinary objects. Learn how array objects fit into the grand scheme of things in Object-Oriented Programming (OOP) using Java.

Local Companies

Moyea Software
92295612365
Hot building, ring street
LA, CA
Interneer Inc.
8005586832 x85
6101 W. Centinela Ave.
Culver City, CA
Cornerstone Concepts Inc
818-247-3909
600 W Broadway
Glendale, CA
Greene Computer Corporation
(818) 956-4961
200 S. Louise Street
Glendale, CA
Corticalx Inc Software Solutions & Technology
818-500-0881
425 E Colorado St
Glendale, CA
Alphatier Systems
818-409-8920
517 Griswold St
Glendale, CA
TimeTECH - Customizable Time and Attendance / Workforce Management Solutions
905-677-7009
7420 Airport Rd 203
Mississauga, CA
Hutchinson & Bloodgood, LLP
(818) 637-5000
101 N. Brand Blvd. #1600
Glendale, CA
Telsoft Solutions
818-545-8680
100 N Brand Blvd
Glendale, CA
Abraxas Technologies Inc
818-502-9100
450 N Brand Blvd
Glendale, CA

provided by: 
Originally published at Internet.com


Java Programming Notes # 1622 * Preface * Preview * Discussion and Sample Code * Summary * What's Next * Complete Program Listing -----------------------------------

Preface

This series of lessons is designed to teach you about the essence of Object-Oriented Programming (OOP) using Java.

The first lesson in the series was entitled The Essence of OOP Using Java, Objects, and Encapsulation. The previous lesson was entitled The Essence of OOP using Java, Static Members.

You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different listings while you are reading about them.

For further reading, see my extensive collection of online Java tutorials at Gamelan.com. A consolidated index is available at Baldwin's Java Programming Tutorials.

Preview

This lesson explains how array objects fit into the grand scheme of things in Object-Oriented Programming (OOP) using Java.

A different syntax is required to create array objects than the syntaxnormally used to create ordinary objects.

Array objects are accessed via references. Any of the methods of the Object class can be invoked on a reference to an array object.

Array objects encapsulate a group of variables. The variables don't have individual names. They are accessed using positive integer index values. The integer indices of a Java array object always extend from 0 to (n-1) where n is the length of the array encapsulated in the object.

All array objects in Java encapsulate one-dimensional arrays. The component type of an array may itself be an array type. This makes it possible to create array objects whose individual components refer to other array objects. This is the mechanism for creating multi-dimensional or ragged arrays in Java.

Discussion and Sample Code

Three kinds of objects

In an earlier lesson, I told you that, from a conceptual viewpoint, there are at least three kinds of objects involved in a Java program: * Ordinary objects * Class objects * Array objects

Ordinary objects

Most of the discussion up to that point in the miniseries dealt with what I have referred to in the above list as ordinary objects.

These are the objects that you instantiate in your code by applying the new operator to a constructor for a class in order to create a new instance (object) of that class.

Class objects

In that lesson, I emphasized that my discussion of Class objects was conceptual in nature and did not necessarily represent an actual implementation. I went on to discuss the class named Class, and discussed how the use of that class fits into the grand scheme of OOP in Java. I explained how the existence of class variables and classs methods tends to complicate the rather simple OOP structure consisting only of ordinary objects.

Array objects

I haven't discussed array objects up to this point in this miniseries. That is the purpose of this lesson.

Also tends to complicate

The existence of array objects also tends to complicate the OOP structure of a Java program consisting only of ordinary objects. Even if you don't consider array objects to be a different kind of object, you must at least consider them to be a special kind of object. A completely different syntax is required to create array objects than the syntax normally used to instantiate ordinary objects.

References to array objects

Arrays are objects in Java (at least, arrays are always encapsulated in objects). Array objects are dynamically created. Like ordinary objects, array objects are accessed via references. The reference to an array object may be assigned to a reference variable whose type is specified as:

TypeName[]

For example, Listing 1 shows some unrelated declarations for variables that are capable of storing references to array objects. int[] x1; Button[] x2; Object[] x3; Listing 1

Note the empty square brackets that are required in the variable declarations in Listing 1.

The special case of type Object

In addition, a reference to an array object may be assigned to a reference variable of type Object as shown in Listing 2. Object x4; Listing 2

Note that there are no square brackets in the statement in Listing 2.

What does this mean?

This means that like ordinary objects, a reference to an array object can be treated as type Object (with no square brackets).

This further means that any of the methods defined in the Object class (such as the toString and getClass methods) can be invoked on a reference to an array object.

The String representation of an array object's reference

For example, when the toString method is invoked on a reference to an array object containing data of type int, the resulting string will be similar to the following:

[I@73d6a5

Pretty ugly, huh?

You may recognize this as being similar to the default String returned by invoking the toString method on an ordinary object with the name of the class for the ordinary object being replaced by [I.

For example, the String returned by invoking the toString method on an object of the class named Array04, (with no overridden toString method), looks something like the following.

Array04@73d6a5

(Note that the hexadecimal numeric values following the @ in both of the above examples will change from one case to the next.)

Invoking the getClass method

Similarly, invoking the getClass method on references to arrays containing data of the types Array04, Button, and int, respectively, and then invoking the toString method on the Class objects returned by the getClass method, produces

Author: Richard G. Baldwin

Read article at Internet.com site

Featured Local Company

Moyea Software

92295612365
Hot building, ring street
LA, CA

Related Local Events
Automation Technology Expo West (ATX West)
Dates: 2/9/2010 - 2/11/2010
Location: Anaheim Convention Center
Anaheim, CA
View Details

SOLAR POWER - Exhibition and Conference
Dates: 10/12/2010 - 10/14/2010
Location: Los Angeles Convention & Exhibition Center
Los Angeles, CA
View Details

REAL-TIME & EMBEDDED COMPUTING CONFERENCE - LONG BEACH 2009
Dates: 10/1/2009 - 10/1/2009
Location: Marriott Long Beach
Long Beach, CA
View Details

2009 IEEE Petroleum and Chemical Industry Technical Conference (PCIC 2009)
Dates: 9/14/2009 - 9/16/2009
Location:
Anaheim, CA
View Details

Medical Design & Manufacturing - Trade
Dates: 6/9/2009 - 6/11/2009
Location: CANON COMMUNICATIONS LLC
Los Angeles, CA
View Details