1/47
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
What is the purpose of the new operator?
It creates an object and associates it with a variable.
What is the general syntax for declaring a variable that will refer to an object?
ClassName classVar;
What is the syntax for creating an object after declaring its variable?
classVar = new ClassName();
Can declaration and object creation be combined?
Yes, ClassName classVar = new ClassName();
What does Student JS = new Student(); do?
It declares JS as a Student variable and creates a new Student object associated with it.
What is an instance variable?
A variable declared inside a class but outside the constructor and methods.
When are instance variables created?
When an object is instantiated.
Which methods can access an instance variable?
All methods in the class.
How do you refer to an instance variable belonging to a particular object?
objectName.variableName
What does JS.studentName mean?
It refers to the studentName instance variable belonging to the object JS.
What is an ArrayList?
A type of Java list.
What must be specified when declaring an ArrayList?
The type of elements it will contain.
Can an ArrayList contain elements of multiple types?
No, an ArrayList can only contain elements of one specified type.
What do the angle brackets in ArrayList<String> specify?
The type of elements stored in the list.
How do you create an empty ArrayList of Strings?
ArrayList<String> strList = new ArrayList<String>();
Does Java ArrayList support Python's w[i] notation?
No, named methods are used instead.
What does get(i) do?
It returns the item at index i.
What does set(i, value) do?
Sets the item at index i to the specified value.
What does add(value) do?
It adds an item to the list.
What does size() do?
Returns the number of items in the list.
What does indexOf(x) return?
The index of the first occurrence of x, or -1 if it isn’t found.
What does addAll(w2) do?
Adds all elements of w2 to the list.
What does contains(x) do?
Test whether the list contains x.
What does isEmpty() do?
Test whether the list is empty.
What does clear() do?
Removes all items from the list.
What does remove(i) do?
Removes and returns the item at index i.
What does subList(2,4) do?
Produces a sub-list corresponding to the specified range.
What does Collections.sort(w) do?
Sorts the list according to natural ordering.
What is a wrapper type?
An object type corresponding to a primitive type.
What is boxing?
Converting a primitive value into an object.
What is unboxing?
Converting an object back into a primitive value.
What is autoboxing?
Automatic conversion between primitive types and their corresponding object/wrapper types.
Is ArrayList<int> legal?
No.
What should be used instead of ArrayList<int>
ArrayList<Integer>
Why can't ArrayList<int> be used?
ArrayList requires an object type rather than a primitive type.
What happens when nums.add(7) is called on an ArrayList<Integer>?
The primitive int value 7 is automatically converted to an Integer object through autoboxing.
What is a major difference between a Java array and an ArrayList?
A Java array has a fixed number of elements while an ArrayList can change size.
When is the size of a Java array fixed?
When the array is created.
Can the number of elements in an existing Java array be changed?
No.
How is an array of type T represented in Java?
T[]
What does String[] mean?
An array of Strings.
How can an array be initialized in its declaration?
Using curly braces.
Give an example of an initialized String array.
String[] fruit = {“apple“, “pear“, “plum“};
How do you access an element of an array?
Using indexing, e.g. fruit[1]
How do you obtain the length of a Java array?
Using the length field.
Is length for arrays a method or a field?
A field.
What is the syntax for creating an array with a specified size?
new elementType[arraySizeExpression]
What does new String[n] create?
A String array containing n positions initially containing null references.