Programming Essentials Using Java by McAllister William & Fritz S. Jane

Programming Essentials Using Java by McAllister William & Fritz S. Jane

Author:McAllister, William & Fritz, S. Jane
Language: eng
Format: epub
Publisher: Mercury Learning and Information
Published: 2017-02-22T05:00:00+00:00


CHAPTER 6

ARRAYS

6.1 The Origin of Arrays

6.2 The Concept of Arrays

6.3 Declaring Arrays

6.4 Arrays and Loops

6.5 Arrays of Objects

6.6 Passing Arrays Between Methods.

6.7 Parallel Arrays

6.8 Common Array Algorithms

6.9 Application Programming Interface Array Support

6.10 Multi-dimensional Arrays

6.11 Additional Searching and Sorting Algorithms

6.12 Deleting, Modifying, and Adding Disk File Items

6.13 Chapter Summary

In this chapter

In this chapter, we will introduce the concept of an array and the powerful features of the construct that make it a part of most programs. These features include the ability to store and retrieve large data sets, and, when combined with the concept of a loop, these data sets can be processed with only a few instructions. Array processing algorithms such as sorting, searching, and copying will be discussed and implemented, as will algorithms introduced in Chapter 4 for inserting and deleting items stored in a disk text file. We will also explore the API methods that implement many of the classical array processing algorithms.

One-dimensional arrays, which can be used to store a list of items, will be discussed as well as multi-dimensional arrays, and we will use two-dimensional arrays to organize data in tables as rows and columns.

After successfully completing this chapter you should:

• Understand the advantages and importance of using arrays

• Be familiar with the Java memory model used to store arrays

• Be able to construct and use arrays of primitives and objects

• Understand and be able to implement the algorithms used to search an array, sort it, and find the minimum and maximum values stored in it

• Be familiar with and be able to use the array-processing methods in the API

• Understand the concept of parallel arrays and use them to process data sets

• Know how to use arrays to insert, delete, or update data items stored in a disk file

• Be able to apply array techniques to game programs

6.1 THE ORIGIN OF ARRAYS

The machines we call computers received their name because the first operational versions of these machines were primarily used by mathematicians to perform rapid computations on large data sets. They were machines whose task was to compute; they were computers. However, long before computers were operational, mathematicians were using subscripted variables, such as x2 or x4, to represent the data used in their formulas and calculations, so it was natural for them to want to use these subscripted variables in the formulas evaluated by these early computing machines.

To facilitate the writing of these subscripted variables into a program, the designers of FORTRAN (which stands for Formula Translation), the first high level programming language used by mathematicians, included a construct that modeled subscripted variables. The construct was named array. Thus, the computer concept of an array has its roots in the mathematical model of subscripted variables.

6.2 The Concept of Arrays

Consider a program that processes five people’s ages stored in the integer memory cells age0, age1, age2, age3, and age4. The declaration of these variables would be rather straightforward:

int age0, age1, age2, age3, age4;

But suppose that instead of processing five people’s ages, the program processed five million people’s ages.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.