What Is An Array?


Introduction

The purpose of this chapter is to give you a solid foundational understanding of arrays and their usage. Since arrays enjoy special status in the Java language you will find them easy to understand and use. This chapter builds upon the material presented in chapters 6 and 7. Here you will learn how to utilize arrays in simple programs and manipulate them with program control-flow statements to yield increasingly powerful programs.

As you will soon learn, arrays are powerful data structures that can be utilized to solve many programming problems. However, even though arrays are powerful, they do have limitations. Detailed knowledge of arrays will give you the ability to judge whether an array is right for your particular application.

In this chapter you will learn the meaning of the term array, how to create and manipulate single- and multidimensional arrays, and how to use arrays in your programs. Starting with single-dimensional arrays of primitive data types, you will learn how to declare array references and how to use the new operator to dynamically create array objects. To help you better understand the concepts of arrays and their use I will show you how they are represented in memory. A solid understanding of the memory concepts behind array allocation will help you to better utilize arrays in your programs. I will then show you how to manipulate single-dimensional arrays using the program control-flow statements you learned in the previous chapter. Understanding the concepts and use of single-dimensional arrays will enable you to easily understand the concepts behind multidimensional arrays.

Along the way you will learn the difference between arrays of primitive types and arrays of reference types. I will show you how to dynamically allocate array element objects and how to call methods on objects via array element references.

Although you will learn a lot about arrays in this chapter, I have omitted some material I feel is best covered later in the book. For instance, I have postponed discussion of how to pass arrays as method arguments until you learn about classes and methods in the next chapter.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net