Most of the necessary introduction to arrays is in the last section of Chapter 4, which shows how you define and initialize an array. Holding objects is the focus of this chapter, and an array is just one way to hold objects. But there are a number of other ways to hold objects, so what makes an array special?
Latest Thinking In Java Articles - Page 6
To summarize what we’ve seen so far, your first, most efficient choice to hold a group of objects should be an array, and you’re forced into this choice if you want to hold a group of primitives. In the remainder of the chapter we’ll look at the more general case, when you don’t know at the time you’re writing the program how many objects you’re going to need, or if you need a more sophisticated way to store your objects. Java provides four types of collection classes to solve this problem: Vector , BitSet , Stack , and Hashtable . Although compared to other languages that provide collections this is a fairly meager supply, you can nonetheless solve a surprising number of problems using these tools.
Polymorphism means “different forms.” In object-oriented programming, you have the same face (the common interface in the base class) and different forms using that face: the different versions of the dynamically-bound methods.
In Chapter 6 you saw how an object can be used as its own type or as an object of its base type. Taking an object handle and treating it as the handle of the base type is called upcasting because of the way inheritance trees are drawn with the base class at the top.
Latest Developer VideosMore...
Latest CodeGuru Developer Columns
It's essential to know the differences in these libraries and use them correctly. This brief tutorial will guide you.
With facilities to search, copy, extract segments, and more, the array class can handle pretty much any task you need to perform with ease.
Enhance your development skills and make your users' lives easier.
If you have written solid code, you have accomplished one half of the objective. Solid code is the protagonist, or hero, of our story, but testing is the more sedate side kick that often saves the day after the hubris of the hero has almost certainly lead to calamity.