• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/15

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

15 Cards in this Set

  • Front
  • Back
What is the difference between an array of primitives and an array of objects?
An array of primitives stores the actual values of the primitives, while an array of objects stores references to those objects (their heap addresses). In both cases an array itself is an object.
How does an array store its values spacewise?
It's a big benefit of the array type, that it stores its values in continuous manner, so they are next to each other.
Explain mutlidimensional arrays
An x-dimensional array is a collection of arrays with x minus one dimensions. So a three-dimensional array is a collection of two-dimensional arrays.
What steps are involved in creating an array?
Declaration (type and variable with a single or double set of brackets at any position), Allocation of memory, and Initialization
When and how does allocation happen for arrays
Arrays cannot be allocated during declaration (it will cause compilation error). Allocation happens using the keyword new and defines the size of array which is immutable and must evaluate to an integer. If size is missing or placed on the left of assignment sign, the code will not compile. For multidimensional array at least the first pair of brackets should have array size. Once allocated arrays store default values for objects of those classes.
What's the difference between length in terms of array and String?
length() is a method for String objects, length is an instance variable for array objects.
How can an array be initialized?
1) Array values can be initialized using a loop, including nested loops for multidimensional arrays, 2) Array values can be initialized individually using indexes in square brackets.
Name two ways all three steps of array creation can be combined on one line?
1) Array type, variable name, either or both being followed by square brackets, assignment sign, array values listed between curly braces.2) Array type, variable name, either or both being followed by square brackets, assignment sign, keyword new, array type, square brackets, array values listed between curly braces. Size is not specified for either approach, rather calculated from the provided values.
What can be said about elements of array assigned to null
Those elements have no value assigned, however, the element does exist, but it's initialized to null. On the other hand of no element is initialized at a position, no value exists at that position, so run-time exception would occur if indexed.
Describe how an array can be of type Interface, Abstract Class, or Object.
1) an array can store objects of classes implementing the specified interface, 2) an array can store objects extending abstract classes, 3) an array can be declared with type Object, and store any type of Java objects, including an array of other objects/primitives.
What methods are available for array objects?
clone() method returns an array with the same type, and all other methods of java Object class.
Can an array of characters be assigned to an array of integers?
No, because arrays are objects, and an array of characters can only be assigned to a variable of the same type, which is characters.
If array 1 was assigned an existing array 2 object, what happens when values in either are changed (they both store primitives)?
If it's an array of primitives, then changes will be visible to both, because the 2 variables now reference the same array object.
Can an array of integers be cast to an array of Strings or Objects directly?
No. This code will not compile
Can an array of integers be cast to an array of Strings or Objects indirectly (meaning throw assignment to a variable of type Object first)?
Yes, the code will compile, but it will throw ClassCastException during runtime.