java ch7 Part2

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/24

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:18 AM on 4/22/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

25 Terms

1
New cards

Enhanced for statement:

Iterates through the elements of an array without using a counter.Avoids the possibility of “stepping outside” the array. Also works with the Java API’s prebuilt collections.

2
New cards

Enhanced for statement Syntax:

  for (parameter : arrayName) {
   statement
}

where parameter has a type and an identifier and arrayName is the array through which to iterate.

3
New cards

Enhanced for statements Parameter type must be

consistent with the array’s element type.

4
New cards

The enhanced for statement simplifies

the code for iterating through an array.

5
New cards

The enhanced for statement can be used only to

obtain array elements. It cannot be used to modify elements. To modify elements, use the traditional counter-controlled for statement.Can be used in place of the counter-controlled for statement if you don’t need to access the index of the element.

6
New cards

To pass an array argument to a method,

specify the name of the array without any brackets. Since every array object “knows” its own length, we need not pass the array length as an additional argument.

7
New cards

To receive an array, the method’s parameter list must

specify an array parameter.

8
New cards

When an argument to a method is an entire array or an individual array element of a reference type, the called method receives

a copy of the reference.

9
New cards

When an argument to a method is an individual array element of a primitive type, the called method receives

a copy of the element’s value. Such primitive values are called scalars or scalar quantities.

10
New cards

Pass-by-value (sometimes called call-by-value):

A copy of the argument’s value is passed to the called method. The called method works exclusively with the copy. Changes to the called method’s copy do not affect the original variable’s value in the caller.

11
New cards

Pass-by-reference (sometimes called call-by-reference):

The called method can access the argument’s value in the caller directly and modify that data, if necessary. Improves performance by eliminating the need to copy possibly large amounts of data.

12
New cards

All arguments in Java are passed by

value.

13
New cards

A method call can pass two types of values to a method

Copies of primitive values, and Copies of references to objects. (Objects cannot be passed)

14
New cards

If a method modifies a reference-type parameter so that it refers to

another object, only the parameter refers to the new object. The reference stored in the caller’s variable still refers to the original object.

15
New cards

Although an object’s reference is passed by value, a method can still interact with the referenced object by calling

its public methods using the copy of the object’s reference. The parameter in the called method and the argument in the calling method refer to the same object in memory.

16
New cards

Two-dimensional arrays are often used to represent

tables of values with data arranged in rows and columns. Identify each table element with two indices. By convention, the first identifies the element’s row and the second its column.

17
New cards

Multidimensional arrays can have

more than two dimensions. Java does not support ________ arrays directly. Allows you to specify one-dimensional arrays whose elements are also one-dimensional arrays, thus achieving the same effect.

18
New cards

In general, an array with m rows and n columns is called

an m-by-n array.

19
New cards

Multidimensional arrays can be initialized with

array initializers in declarations.

20
New cards

A two-dimensional array b with two rows and two columns could be declared and initialized with nested array initializers as follows:

int[][] b = {{1, 2}, {3, 4}};

The initial values are grouped by row in braces. The number of nested array initializers (represented by sets of braces within the outer braces) determines the number of rows. The number of initializer values in the nested array initializer for a row determines the number of columns in that row. Rows can have different lengths.

21
New cards

The lengths of the rows in a two-dimensional array are not required to be the same:

int[][] b = {{1, 2}, {3, 4, 5}};

Each element of b is a reference to a one-dimensional array of int variables. The int array for row 0 is a one-dimensional array with two elements (1 and 2). The int array for row 1 is a one-dimensional array with three elements (3, 4 and 5).

22
New cards

A multidimensional array with the same number of columns in every row can be created with an array-creation expression.

int[][] b = new int[3][4]; 3 rows and 4 columns.

23
New cards

The elements of a multidimensional array are initialized when

the array object is created.

24
New cards

A multidimensional array in which each row has a different number of columns can be created as follows:

int[][] b = new int[2][]; // create 2 rows

b[0] = new int[5]; // create 5 columns for row 0

b[1] = new int[3]; // create 3 columns for row 1

Creates a two-dimensional array with two rows. Row 0 has five columns, and row 1 has three columns.

25
New cards

ended on page 39