1/59
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What keyword is used to create a constant?
final
13/5
2
13%5
3
What syntax generates a random integer between 5 and 27 inclusive?
(int)Math.random()*(27-5+1) + 5
What syntax rounds a positive double x to the nearest integer value?
x = (int)(x+.5)
What syntax rounds a negative double x to the nearest integer value?
x=(int)(x-.5)
Arithmetic operations with two ints produces a result of what data type?
an int
Arithmetic operations with at least one double produces a result of what data type?
a double
exception that is thrown if you try to divide by 0
ArithmeticException
The fact that the operator “+” can be used for either addition or concatenation is an example of which OOP principle?
polymorphism
x++; is equivalent to what other line of code?
x=x+1
x*=3; is equivalent to what other line of code?
x=x*3
What are the three escape sequences with which we are required to be familiar?
newline: \n
quotation marks: \”
backslash: \\
How does short-circuit evaluation work with the operator &&?
if the first statement is false Java will automatically return false w/o checking the second statement
How does short-circuit evaluation work with the operator ||?
if the first statement is true Java will automatically return true w/o checking the second statement
State DeMorgan’s Laws
!(A||B) ≡ !A && !B
!(A&&B) ≡ !A||!B
What boolean expression returns true if int x and int y are equal?
x==y
What boolean expression returns true if String x and String y are equal?
x.equsls(y)
What information is included in a method’s signature?
methods name and parameter list
What is the term that refers to writing methods with same name but a different number, type, or sequence of parameters?
overloading methods
The ability to make use of a method without knowing its inner workings is an example of which OOP principle?
abstraction
What keyword is used to instantiate an object?
new
The use of classes is an example of which OOp principle?
encapsulation
What does the keyword public mean?
access is allowed to the declaring class
What does the keyword private mean?
restricts access to the declaring class
Identify whether each of the following should be public or private:
Class
Constructor
Instance Variable
Method
public
public
private
both
term that refers to methods that retrieve the values of class/instance variables
getters/accessor
term that refers to methods that change the values of class/instance variables
setters/mutator
keyword is used to call a constructor with a different number of parameters from within another constructor
this
keyword represents the fact that a variable intended to contain the memory address of an object does not currently contain a memory address
null
What keyword indicates that a single instance of a field is shared by all instances f the class that contains it?
static
How is the syntax for calling a class method (from a runner file) different from the syntax for calling an instance method?
A class method is called using ClassName.methodName() while an instance method is called using nameOfInstance.methodName()
exception that is thrown if you try to call a method on a variable declared to hold an object, but there is no memory address currently stored
NullPointerException
What does it mean when we say that Strings are immutable?
once a string is created they can’t be changed
What exception is thrown if you try to access the element of index -1 in a String?
StringIndexOutOfBoundsException
How do we access the number of characters in a String?
stringName.length()
What can arrays hold?
arrays can hold both objects and primitves
Show the syntax that instantiates an array of any appropriate data type
int [ ] arr = new int [ ]
How do we access the number of elements in an array?
by using a length field (arrayName.length)
What exception is thrown if you try to access the element of index -1 in an array?
ArrayIndexOutOfBoundException
If the contents of the 2-D array myArray are represented by the array below what is the value of myArray [1][2]?
{ 5 1 3 }
{ 4 2 6 }
{ 9 0 8 }
6
The ability of a subclass to automatically gain the attributes of its superclass is an example of which OOP princple?
inheritence
What keyword is used to indicate that a class is a subclass?
extends
Does a subclass inherit fields? constructors? methods?
Fields – generally no, but yes if public (but the subclass always has the fields
of the superclass as attributes!)
Constructors – no
Methods – yes if public, no if private
What keyword is used to call a constructor (or method) of a parent class from a child class?
super()
When calling the constructor of a parent class froma child class, what must you remember?
super should be the first line of code
What does Java do when the constructor of the parent is not called from the constructor of the child
calls the no argument constructors of parent class
What is the superclass of every other class?
Object
What is the term that refers to writing a method in a subclass with the same signature as a method in its superclass?
method overriding
If M in a subclass of N and both have a no-argument constructors, is:
a) M name = new N(); valid syntax?
b) N name = new M(); valid syntax?
a) no
b) yes
What is automatic conversion from a data type to its wrapper class called? What is the reverse called?
autoboxing and unboxing
Can an ArrayList hold (memory addresses) of Objects? Can it hold primitives?
can hold Objects not primitives
Show the syntax that instantiates an Arraylist of any appropriate data type?
ArrayList <String> arr = new ArrayList <String> ();
How do we access the number of elements in an ArrayList?
myArrayList.size();
What exception is thrown if the number of elements in an ArrayList is altered while traversing it with an enhanced for loop?
ConcurrentModificationException
How many iterations of linear/sequential search will it take to find 11 in the array [-3, -1, 0, 4, 11, 8, 5]
5
How many iterations of binary search will it take to find 11 in the array [-3, -1, 0, 4, 5, 8, 11]
3
Show the contents of the array [9, 2, -1, 3, -6, 0, 11, 5] after three iterations of selection sort
[-6, -1, 0, 3, 9, 2, 11, 5]
Show the contents of the array [9, 2, -1, 3, -6, 0, 11, 5] after three iterations of insertion sort
[-1, 2, 3, 9, -6, 0, 11, 5]
Show steps of merge sort on the array [9, 2, -1, 3, -6, 0, 11, 5]
The array is broken into arrays of single elements.
[9], [2], [-1], [3], [-6], [0], [11], [5]
[2, 9], [-1, 3], [-6, 0], [5, 11]
[-1, 2, 3, 9], [-6, 0, 5, 11]
[-6, -1, 0, 2, 3, 5, 9, 11]