zuai-logo

Glossary

A

ArrayIndexOutOfBoundsException

Criticality: 3

A runtime error that occurs when a program attempts to access an array element using an index that is outside the valid range of indices for that array.

Example:

Trying to access myArray[5] when myArray was created with new int[5] (meaning valid indices are 0-4) will result in an ArrayIndexOutOfBoundsException.

Arrays

Criticality: 3

A data structure used to store a fixed-size sequential collection of elements of the same data type. In Java, arrays are reference types.

Example:

To store the high scores of 5 players, you could use int[] highScores = {980, 1020, 875, 1100, 950}; where highScores is an array.

B

Bracket notation

Criticality: 3

The use of square brackets `[]` with an index inside to retrieve or modify a specific element at a particular position within an array.

Example:

To get the second element from an array int[] scores = {100, 95, 80};, you would use scores[1] with bracket notation, which would return 95.

C

Constructor (for arrays)

Criticality: 3

A specific syntax used to initialize an array by specifying its data type and the number of elements it will hold, allocating memory for the array.

Example:

double[] dailyTemps = new double[7]; uses a constructor to create an array capable of holding 7 double values, all initialized to 0.0.

F

Fixed size

Criticality: 2

A characteristic of arrays meaning their capacity to hold elements is determined at the time of creation and cannot be changed later.

Example:

An array created with new boolean[5] has a fixed size of 5 elements; you cannot add a sixth element without creating an entirely new, larger array.

P

Pre-initialized arrays

Criticality: 3

A method of creating an array where elements are directly provided within curly braces at the time of declaration, automatically setting the array's size and initial values.

Example:

String[] weekdays = {"Mon", "Tue", "Wed", "Thu", "Fri"}; creates a pre-initialized array named weekdays with five String elements.

R

Reference types

Criticality: 2

In Java, a data type that stores a memory address pointing to an object, rather than the actual data value itself. Arrays are a prime example of reference types.

Example:

When you declare String[] names;, names is a reference type variable that will hold the memory address of an array of String objects, not the strings themselves.

Z

Zero-indexed language

Criticality: 3

A programming language characteristic where the first element in a sequence (like an array or string) is accessed using an index of 0, rather than 1.

Example:

In Java, if you have an array char[] alphabet = {'a', 'b', 'c'};, the character 'a' is at index 0, demonstrating that Java is a zero-indexed language.

a

arrayName.length

Criticality: 3

An instance variable (not a method) that returns the total number of elements an array can hold, representing its fixed size.

Example:

If String[] fruits = {"apple", "banana", "cherry"};, then fruits.length would evaluate to 3, indicating the arrayName.length.

i

import java.util.Arrays;

Criticality: 1

A Java import statement required to use utility methods provided by the `Arrays` class, such as sorting or printing array contents.

Example:

To easily print an array's contents for debugging, you might use System.out.println(Arrays.toString(myArray)); which requires the **import java.util.Arrays;** statement at the top of your file.