Java Chapter 7

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Search Algorithm

A____is a method of locating a specific item in a larger collection of data. (page 498)

Two-Dimensional Array

A____is an array of arrays. It can be thought of as having rows and columns. To declare a____, two sets of brackets and two size declarators are required. The first one is for the number of rows and the second one is form the number of columns. double [][] scores = new double [3][4]; (page 509)

Sorting Algorithm

A____is used to arrange data in some order. (page 501)

Capacity

An ArrayList object has a____, which is the number of items it can store without having to increase its size. When an ArrayList object is first created, using the no-arg constructor, it has an initial____of 10 items. You can also specify a different starting____. Example: ArrayList<String> list = new ArrayList<String>(100);

**Take Note**

An array can be passed as an argument to a method. To pass an array, you pass the value in the variable that references the array. (page 472)

**Take Note**

An array's size declarator can be either a literal value or a variable. It is common practice to use a final variable as a size declarator.(page 451)

Array

An____is an object that can store a group of values, all of the same type. (page 449)

**Take Note**

Arrays have a field name length and String objects have a method named length. When working with arrays, do not confuse the two. Because the array's length member is a field, you do not write a set of parentheses after its name. You do write the parentheses after the name of the String class's length method. (page 494)

Off-By-One Error

Because array subscripts begin at 0 rather than 1, yo have to be careful not to perform an____. (page 457)

**Take Note**

Bounds checking occurs at runtime. The Java compiler does not display an error message when it processes a statement that uses an invalid subscript. Instead, when the statement executes, the program throws an exception and terminates. (page 456)

**Take Note**

In memory, an array of string objects is arranged differently than an array of a primitive data type. To use a string object, you must have a reference to the string object. (page 491)

**Take Note**

Java does not limit the number of dimensions that an array may have. (page 521)

Variable length argument lists

Java provides a mechanism known as____, which makes it possible to write a method that takes a variable number of arguments. (page 523)

Enhanced for loop

Java provides a specialized version of the for loop that, in many circumstances, simplifies array processing. It is known as the____. The general format is: for(datatype elementVariable : array) statement; (page 465)

vararg parameter

The elipsis (three periods) that follows the data type indicates that the parameter is a special type of parameter known as a____. A____can take a variable number of arguments. (page 524)

Initialization List

The series of values inside the braces and separated with commas is called an____(page 458)

Diamond Operator

The set of empty angled brackets (<>), the____, caused the compiler to infer the required data type from the reference variable declaration. Example: ArrayList<InventoryItem> list = new ArrayList<>(); (page 534)

Binary Search

The____is a clever algorithm that is much more efficient that the sequential search. Its only requirement is that the values in the array must be sorted in ascending order. Instead of testing the array's first element, it begins with the element in the middle. (page 505)

Sequential Search Algorithm

The____uses a loop to sequentially step through an array, starting with the first element. It compares each element with the value being searched fro and stops when the value is found or the end of the array is encountered.(page 498)

Selection Sort

The____works like this: the smallest value in the array is located and moved to element 0. Then the next smallest value is located and moved to element 1. The process continues until all of the elements have been placed in the proper order.

**Take Note**

To access one of the elements in a two-dimensional array, you must use both subscripts. scores [2][1] = 95; (page 511)

import java.util.ArrayList;

What import statement is required to use the ArrayList?

**Take Note**

When an entire array is passed into a method, it is passed just as an object is passed: The actual array itself is not passed, but a reference to the array is passed into the parameter. Consequently, this means that the method has direct access to the original array. (page 473)

**Take Note**

When you create an unitialized array of string objects, you must assign a value to each element in the array. (page 493).

**Take Note**

When an array is created that references String objects, but is not initialized, they are set to null. (page 492)

**Take Note**

When initializing a two-dimensional array, you enclose each row's initialization list in its own set of braces. int[][] numbers = { {1, 2, 3 }, {4, 5, 6 }, {7, 8, 9 } };

Ragged Array

When the rows of a two-dimensional array are of different lengths, the array is known as a____. You create a____ by first creating a two-dimensional array with a spcific number of rows, but no columns. int[][] ragged = new int[4][]; (page 520)

**Take Note**

You can overload the .add() method to add an item at a certain index point: nameList.add(1, "Mary"); adds Mary to the index 1 spot and pushes everything else one index number upwards. (page 531)

new

You declare a reference variable and use the____keyword to create an instance of the array in memory. (page 449)

**Take Note**

You do not use the 'new' keyword when you use an initialization list. Java automatically creates the array and stores the values in the initialization list. (page 458)

ArrayList

____is a class in the Java API that is similar to an array and allows you to store objects. Unlike an array, an ____object's size is automatically adjusted to accommodate the number of items being stored in it. (page 526)

**Take Note**

int[] numbers; Declares an array reference variable. This does not create an actual array. numbers = new in[6] creates an array and assigns its address to the numbers variable. You may also declare a numbers variable and create an instance of an array with one step. int[] numbers = new int[6]; (page 449)

**Take Note**

Here is an example of how to create an ArrayList oject: ArrayList<String> nameList = new ArrayList<String>(); To add items, use the add method: nameList.add("James"); To report the number of items stored us the size method: nameList.size. Use the get method to return items stored at a specific index: nameList.get(1); Use the toString method to return all the item. Use the remove() method to remove an item at a specific index: nameList.remove(1); Use the set() method to replace an item at a certain index: nameList.set(1, "Becky");

Subscript

Each element is assigned to a number known as a____. A____is used as an index to pinpoint a specific element within the array. The first element assigned is the____ 0. (page 451)

Size Declarator

The number inside the brackets of an array declaration is called the array's____. It indicates the number of elements that an array has. (page 450)


Set pelajaran terkait

Partnering with Families: Overview

View Set

Chapter 1: The night sky from Earth, Earth in Space, Gravity and Motion, The Moon phases and Eclipses, Tides

View Set

Hornung, innervation membre inférieur

View Set

Day 1 kinesiology: head, neck and face

View Set

chp. 11: The Renaissance / section 1

View Set

Бухгалтерський облік (тести)

View Set

basics of capital budgeting 2: WACC

View Set

Operations Management Smartbook Study Guide

View Set