Moment 4 Flashcards
Ch 6 Arrays and ArrayLists Kapitel 6 (6.1 - 6.12)
Arrays (p. 246) are?
fixed-length data structures consisting of related data items of the same type.
Types in Java are divided into two categories, which?
—primitive types and reference types.
The primitive types are?
boolean, byte, char, short, int, long, float and double.
All other types are reference types, so classes, which specify the types of objects, are reference types.
A primitive-type variable can store?
exactly one value of its declared type at a time.
Reference-type variables (called references; p. 247) store the?
location of an object in the computer’s memory. Such variables refer to objects in the program.
A reference to an object (p. 247) is required to invoke an?
object’s methods. A primitive-type variable does not refer to an object and therefore cannot be used to invoke a method.
An array is a group of variables (called elements or components; p. 247) containing values that?
all have the same type. Arrays are objects, so they’re considered reference types.
A program refers to any one of an array’s elements with an array-access expression (p. 248) that includes?
the name of the array followed by the index of the particular element in square brackets ([]; p. 248).
The first element in every array has index?
zero (p. 248) and is sometimes called the zeroth element.
An index must be a nonnegative?
integer. A program can use an expression as an index.
An array object knows its own length and stores this information in a?
“length” instance variable
To create an array object, specify the array’s?
element type and the number of elements as part of an array-creation expression (p. 249) that uses keyword new.
When an array is created, each element receives a default value, which?
zero for numeric primitive-type elements, false for boolean elements and null for references.
In an array declaration, the type and the square brackets can be combined at the beginning of the declaration to indicate that?
all the identifiers in the declaration are array variables.
Every element of a primitive-type array contains a?
variable of the array’s declared type.
Every element of a reference-type array is a reference to an?
object of the array’s declared type.
A program can create an array and initialize its elements with an?
array initializer (p. 251).
Constant variables (p. 253) are declared with keyword?
final, must be initialized before they’re used and cannot be modified thereafter.
An exception indicates a?
problem that occurs while a program executes.
Exception handling (p. 259) enables you to?
create fault-tolerant programs.
When a Java program executes, the JVM checks array indices to ensure that?
they’re greater than or equal to 0 and less than the array’s length.
If a program uses an invalid array index, Java generates an?
exception (p. 259) to indicate that an error occurred in the program at execution time.
To handle an exception, place any code that might throw an exception (p. 259) in a?
“try” statement.
The “try” block (p. 259) contains the code that might throw an exception, and the “catch” block (p. 259) contains the
code that handles the exception if one occurs.