Term
object-oriented programming |
|
Definition
Designing a program by discovering objects, their properties, and their relationships |
|
|
Term
|
Definition
a programmer-defined data type |
|
|
Term
|
Definition
the features (methods, variables, and nested types) of a class that are accessible to all clients |
|
|
Term
|
Definition
the actions taken by an object when its methods are invoked |
|
|
Term
|
Definition
the current value of an object, which is determined by the cumulative action of all the methods that were invoked on it |
|
|
Term
|
Definition
a variable defined in a class for which every object of the class has its own value |
|
|
Term
|
Definition
a reserved word that indicates the accessibility of a feature, such as "private" or "public" |
|
|
Term
|
Definition
a named set of values and the operations that can be carried out with them |
|
|
Term
|
Definition
a method with an implicit parameter; that is, a method that is invoked on an instance of a class |
|
|
Term
|
Definition
a method that changes the state of an object |
|
|
Term
|
Definition
A method that accesses an object but does not change it |
|
|
Term
|
Definition
The object on which a method is invoked |
|
|
Term
|
Definition
A parameter of a method other than the object on which the method is invoked |
|
|
Term
|
Definition
A sequence of statements for initializing a newly instantiated object |
|
|
Term
|
Definition
A value that denotes the location of an object in memory. In Java, a variable whose type is a class contains a reference to an object of that class. |
|
|
Term
|
Definition
A variable defined in a class that has only one value for the whole class, and which can be accessed and changed by any method of that class |
|
|
Term
|
Definition
A method with no implicit parameter |
|
|
Term
|
Definition
A Java class that implements a dynamically resizable array of objects |
|
|
Term
|
Definition
A class that contains a primitive type value, such as Integer |
|
|
Term
|
Definition
Automatically converting a primitive type value into a wrapper type object |
|
|
Term
|
Definition
Automatically converting a wrapper type object into a primitive type value |
|
|
Term
difference between size and capacity of an ArrayList |
|
Definition
Size is the number of elements, capacity is the amount of space allocated |
|
|
Term
Default capacity of an ArrayList |
|
Definition
|
|
Term
when enhanced for loop cannot be used |
|
Definition
Algorithms that require indexing |
|
|
Term
|
Definition
Iterator iterator = list.iterator() where list is an ArrayList |
|
|
Term
|
Definition
1. Package data members and method implementations into a capsule
2. Hide data members and method implementations in the capsule |
|
|
Term
|
Definition
Providing a public interace and keeping data members, method implementations, or even entire methods (especially helper methods) hidden |
|
|
Term
|
Definition
Make things simpler and less error-prone for the client |
|
|
Term
If you provide public setters and getters, why not make data members public? |
|
Definition
1. You can choose which data members to provide setters and getters for
2. You can perform input validation inside setter methods |
|
|
Term
|
Definition
Changing the default toString(), equals(), and hashCode methods of Object |
|
|
Term
Parameter and return types for overriden toString() |
|
Definition
No parameters, return a String |
|
|
Term
parameter and return types for overriden equals() |
|
Definition
Object parameter, boolean return type |
|
|
Term
parameter and return type of overriden hashCode |
|
Definition
no parameter, int return type |
|
|
Term
|
Definition
Hashes the data members of the class |
|
|
Term
How many copies of a String literal found multiple times in a program will the String pool keep? |
|
Definition
-- One if aliasing -- Two if there is a new Scanner input |
|
|
Term
Do you print the toString() method? What is the syntax? |
|
Definition
No. When you call System.out.print, that method automatically calls toString().
System.out.print(foo) |
|
|
Term
What does toString() do? Syntax? |
|
Definition
Prints out all data members.
return "x = " + this.x + ", f = " + this.f; |
|
|
Term
Why is it safer to use an ArrayList instead of a built-in array? |
|
Definition
ArrayList can resize itself and built-in array can't, so you can accidentally assign elements out of bounds in a built-in array |
|
|
Term
Syntax of a hash map when it is printed out |
|
Definition
{hola = hello, adios = goodbye} |
|
|
Term
|
Definition
HashMap map = new HashMap <> (); |
|
|
Term
|
Definition
|
|
Term
how to get a value from a HashMap |
|
Definition
|
|
Term
What does getOrDefault() do, and what is its syntax? |
|
Definition
getOrDefault(key, defaultValue)
Returns the value to which the specified key is mapped, or defaultValue if this map contains no mapping for the key |
|
|
Term
how to check if a key is in a HashMap |
|
Definition
|
|
Term
|
Definition
Breaking your code into parts, then breaking those parts down into parts, and so on |
|
|
Term
|
Definition
Data members, constructor (optional), setter and getter methods (optional), toString(), equals(), hashCode() |
|
|
Term
|
Definition
Compares data members of "this" and "other" |
|
|
Term
Why use ArrayList(intial Capacity) constructor? |
|
Definition
ArrayList runs slower when it resizes, so if you know what your capacity is going to be, you should specify it |
|
|
Term
Can setter methods change a private data member? |
|
Definition
|
|
Term
|
Definition
-- Primitives use == to compare values -- In String and other library functions, equals() compares values -- But in programmer-defined objects, equals() acts like == -- We must override this default with code that makes equals() compare values |
|
|
Term
Differences between Java classes and C structs |
|
Definition
1) Structs don't have functions, you have to send the struct in explicitly as a parameter to the functions. A Java class has methods that use an object as a parameter implicitly.
2) C has a variable that is a struct, and also a variable that points to a struct. Java object variables are pointers to objects automatically.
3) A Java object can access a data member directly (object.value). A C pointer accesses the object it points to, which then accesses the value (pointer->value).
4) Java's main() is static, and C's is not because every function in C is static. |
|
|
Term
Three ways to set the value of public static int y, after initializing Foo foo = new Foo() |
|
Definition
1) Foo.y = 99; 2) y = 99; 3) foo.y = 99; |
|
|
Term
Why is main always static? |
|
Definition
1) There is no Main class, so you cannot create a Main object.
2) By being static, main() can work in the same way for every object
3) main() is the starting point for execution, so we haven't created any objects yet |
|
|
Term
What do all classes inherit from class Object? |
|
Definition
1) toString() 2) equals() 3) hashCode() |
|
|
Term
Why is Integer.valueOf(String s) static? |
|
Definition
Integer is a wrapper class with a primitive int as a data member. This int is not used in valueOf; instead, a new int is created, based solely on the information relayed by the String argument and not by the int data member. |
|
|
Term
String string1 = "cat"; String string2 = "cat";
What happens on the heap? |
|
Definition
There is only one String in the heap that both variables point to |
|
|
Term
String aString = "abc"; aString += "xyz";
What happens on the heap? |
|
Definition
The heap has a string "abc". The heap then creates a new string, "abcxyz". |
|
|
Term
How to tell if a method is a setter or a getter |
|
Definition
When you call the method twice in a row, a getter will return the same value |
|
|
Term
What happens in the heap when you use toUppercase()? |
|
Definition
A copy of the string is made and set to uppercase. The original string does not change or leave the heap. |
|
|
Term
|
Definition
Searching an array or list for an object by inspecting each element in turn |
|
|
Term
|
Definition
A search algorithm on a sorted array that narrows the search down to half of the array in every step. |
|
|
Term
|
Definition
A tabular arrangement of elements in which an element is specified by a row and a column index |
|
|
Term
What does it mean for a Java String to be immutable? Can its value ever be changed? |
|
Definition
1) It's characters cannot be directly changed.
2) But the value can be changed by concatenation.
3) And the value can be changed by new variable assignment. |
|
|
Term
What gets passed to a method implicitly as a parameter? |
|
Definition
An object. NOT an instance variable. |
|
|
Term
|
Definition
An argument is a parameter value given in the function call-- it is the “actual” data sent (and is sometimes called an “actual parameter”).
A parameter is defined in the function signature. It is a placeholder that receives the actual parameter. It is also called a “formal parameter” |
|
|
Term
When an object-oriented function call is made, how can the execution of the function change the information in the caller? In Java, what kinds of arguments are passed “by value” and which are passed “by reference”? |
|
Definition
Primitives are passed by value. No matter what you do to those parameters in the function, the corresponding actual parameter won’t change. Objects and arrays are sent by reference, meaning the address of the object/array is sent as the value which is placed in the formal parameter’s memory cell. If the function changes the object/array, it will affect the caller’s data. So if in the call obj and foo are objects, arr is an array, and x is an int, only obj, foo, and arr may be affected by the function. The function can also affect the world by returning a value (or printing something). |
|
|
Term
When is toString called? What is the job of toString? If you don’t provide a toString in your class, what is the default behavior? |
|
Definition
When you print an object, e.g., System.out.print(obj) print will call toString on obj. toString can also be called explicitly, e.g., s=obj.toString().
the job of “toString” is to serialize an object. It returns a string, typically including the name/value of all data members.
If you don’t provide a toString, the default toString, defined in class Object, returns the object’s class name and a hashcode. |
|
|
Term
What is the job of an equals method? If you don’t provide an equals in your class, what is the default behavior? |
|
Definition
equals is meant to compare the content of two instances of a class for equality. This often means comparing all of an object’s data members for equality, but it can be defined in other ways as well.
If you don’t provide an equals, the default behavior is to compare the addresses of the objects for equality (note: really the hashcodes are compared, and the hashcodes are based on address). |
|
|
Term
When do you need to use the keyword “this”? |
|
Definition
In an object-oriented method, “this” can be implicit. So you can refer to a data member directly, e.g., x = 5.
If there is a parameter or local variable defined with the same name as the data member, then you must refer to the data member using “this”, e.g., this.x
Otherwise, the parameter or local variable will be prioritized over the data member.
There is also another use of “this”. You can call one constructor from another using this. |
|
|
Term
What happens on a new call, e.g., foo = new Foo(x,y) |
|
Definition
1) object is allocated on the heap
2) constructor is called to initialize data members |
|
|
Term
How do you create an array of 4 Foo objects? |
|
Definition
Foo[] fooArray = new Foo[4];
fooArray[0]= new Foo() fooArray[1]= new Foo() fooArray[2]= new Foo() fooArray[3]= new Foo() |
|
|
Term
How is using an ArrayList simpler and less error-prone than using a built-in array? |
|
Definition
ArrayList will grow “automatically” when needed, array has a fixed size
You can append without considering size
You CAN still get an "index out of range" error with get() |
|
|
Term
What happens in ArrayList add -- how does ArrayList grow? |
|
Definition
add (int x) if numElements == capacity int [] temp = new int[capacity * 2] copy elements from data member arr into temp point arr to temp put new element in |
|
|
Term
What is iterative descent? What should each parseX function do? |
|
Definition
parseX should look at the next token to see if it is an x |
|
|
Term
The function call of the form: foo.func(x) is treated internally as func(foo, x). Explain. |
|
Definition
Object-oriented syntax is such that the object itself, "foo", is sent to the function as if it is a parameter and mapped to "this" in the function, even though "this" doesn't appear in the function signature. |
|
|
Term
When you construct a well-formed class in Java, what should be in it? |
|
Definition
data members constructors toString equals hashCode |
|
|
Term
When is a constructor called? What is the job of the constructor? |
|
Definition
A constructor is called when you "new" an object. The job of the constructor is to initialize data members. |
|
|
Term
What is stored on the stack? |
|
Definition
Activation records, the data for each active method starting with main. That includes "this", the function's parameters, and the function's local variables. |
|
|
Term
What is stored on the heap? |
|
Definition
Dynamically allocated data. This includes objects created with "new", String literals, and arrays. |
|
|
Term
|
Definition
a variable inside a class |
|
|
Term
|
Definition
|
|
Term
|
Definition
a function that is inside a class. Can modify the class's data members directly. |
|
|
Term
dynamically allocated data |
|
Definition
1) objects that get allocated with a "new" call
2) Strings |
|
|
Term
pass-by-value and pass-by-reference |
|
Definition
1) Pass-by-value passes the content of a variable. The variable itself does not change in the function, the function just makes a copy. Usually the value of the copy that is returned will be stored in a new variable in main.
2) Pass-by-reference passes the address, directly changing the variable.
3) If your parameter is an object, then you are sending a pointer to an object. |
|
|
Term
|
Definition
modifier return_type variable_name (parameter_list) |
|
|
Term
How big are addressable slots in memory? |
|
Definition
|
|
Term
What are primitive types and how much space is allocated for each? |
|
Definition
integer - 32 bits float - 32 bits char - 16 bits short - 16 bits long - 64 bits double - 64 bits boolean - 8 bits (only 1 bit is necessary, but the minimum size of an address slot is 1 byte) |
|
|
Term
How is an int represented in 0's and 1's? |
|
Definition
An int is represented in a base-two, or binary, number system, with the leftmost bit denoting the sign (0 is positive, 1 is negative) |
|
|
Term
How is a float represented in memory? |
|
Definition
A float is represented as a binary number with a sign bit, a whole number, and a fractional part.
In the IEEE system, the whole number part has 8 bits and the fractional part has 23 bits. |
|
|
Term
How is a string represented in memory? |
|
Definition
A string is represented in the string pool, a section of the heap. Each character in the string gets two bytes, and at the end of every string is \0, an invisible character that means null. |
|
|
Term
What does it mean for a value to overflow? |
|
Definition
There is not enough space in memory to hold it. This can happen if an integer is added to another integer and there isn't enough space to hold its sum (or its difference in the case of two negatives) |
|
|
Term
|
Definition
the space in memory for dynamically allocated data. This includes objects created with "new", String literals, and arrays. |
|
|
Term
|
Definition
The stack stores the activation record, the data for each active method, including main. This includes "this", function arguments, and a function's local variables. |
|
|
Term
What is an activation record? |
|
Definition
The record of the data for each active method, including main |
|
|
Term
|
Definition
the part of the heap where string literals are stored |
|
|
Term
What does it mean for a language to have static typing versus dynamic typing? |
|
Definition
Static -- the type of a variable or data member must be declared, and it usually does not change
Dynamic -- the type is not declared and can be changed at any time
In Java, a new varible can be created through casting of the original variable.
Types can also be changed by polymorphism. If suzy is an Animal, it could be a Bear, then be changed to a Cat because both Bear and Cat types are of type Animal. |
|
|
Term
Difference between an object and an object reference |
|
Definition
An object reference is the address of an object. Variables of a class type point to the address of an object. |
|
|
Term
What do javac and java do? |
|
Definition
Command-line: $ javac and $ java
javac is the compiler. It checks for errors and generates byte code.
Then the byte code goes to the Java Virtual Machine, which runs the program by changing the byte code to machine code. |
|
|
Term
How can a method affect the world? |
|
Definition
By returning a new value for a variable in main() or by modifying data members. |
|
|
Term
|
Definition
"This" is an implicit parameter of a method. It represents the object that the method will operate on.
It also distinguishes data members from method parameters and local variables with the same name.
You can also use it to call one constructor from another. |
|
|
Term
Static methods vs. instance methods -- what is the difference and how to access static data and methods (4) |
|
Definition
Static methods are class-based. They are the same for any object.
Static methods don't use data members and instance methods do. Static methods use local variables from main.
They can be accessed by Class.method.
Instance methods operate on one object of the class.
They can be accessed by object.method.
Static methods don't use data members and instance methods do. Static methods use local variables from main.
There are static data members (constants). |
|
|
Term
Understand the internals of ArrayList (3) |
|
Definition
1) Add: add() grows the capacity of the ArrayList if needed, then adds the value passed in to the end of the ArrayList's elements. The capacity is grown by creating a new array with a larger capacity, copying the elements of the original array to the new array, and assigning the original array variable to the new array.
2) Adding at an index does this, but before adding in the new value, the values at and after the index shift to the right (a[i] = a[i - 1])
3) Remove: the values after the index shift to the left (a[i] = a[i + 1]) |
|
|
Term
The difference between String and StringBuilder and how to use each (3) |
|
Definition
1) String is immutable and StringBuilder is mutable
2) String's characters cannot be changed directly, StringBuilder can use setCharAt()
3) String's value can be extended by concatenation, StringBuilder can extend with the append() method |
|
|
Term
|
Definition
ArrayList myArray = new ArrayList <> (); |
|
|
Term
|
Definition
int [] myArray = new int [10]; |
|
|
Term
When to declare data members and when to declare local variables |
|
Definition
Use data members to represent a property of the class, to directly modify objects, must be accessible across multiple methods within the class
Use local variables when the data is needed temporarily within a specific method or block of code (like a loop) or when it is only needed in main |
|
|
Term
What does a constructor do? |
|
Definition
Initializes an object's data members |
|
|
Term
|
Definition
Prints a string of the class's data members and their values |
|
|
Term
|
Definition
compares the content of one object to another |
|
|
Term
Give an example of a visibility error that can occur |
|
Definition
Trying to access one class's private data member from another class by using: variable = otherClass.dataMember |
|
|
Term
Why is it common practice to make all data members private? (3) |
|
Definition
We don't want private data members to be accessed and changed improperly. This could especially conflict with use of an object's methods.
When the data members are private, you can choose which ones you want to make setter methods for and which ones you don't.
You can use input validation in a setter method. |
|
|
Term
When to make a method private |
|
Definition
When it's a helper method. Calling a helper method on its own could cause an error when the method it helps is called. |
|
|
Term
How to use chars as numbers |
|
Definition
getNumericValue(ASCII character) |
|
|
Term
How to check if a char is a letter, a number, or either |
|
Definition
isLetter() isDigit() isLetterOrDigit() |
|
|
Term
How to check or change a character's case |
|
Definition
toLowerCase() toUpperCase() isLowerCase() isUpperCase() |
|
|
Term
How to check for whitespace |
|
Definition
Character.isWhitespace(char) |
|
|
Term
How to turn a character into a string |
|
Definition
|
|
Term
How to turn a string into an int |
|
Definition
Integer.parseInt(String s) |
|
|
Term
How to turn an int into a string |
|
Definition
|
|
Term
How to tell if there is more input from a Scanner |
|
Definition
hasNext() hasNextBoolean() hasNextDouble() hasNextInt() |
|
|
Term
How to access Scanner input |
|
Definition
next() nextLine() nextDouble() nextInt() |
|
|
Term
How to get the character at an index of a string |
|
Definition
|
|
Term
How to tell if a substring exists in a string |
|
Definition
|
|
Term
How to get the index of a certain string character |
|
Definition
|
|
Term
|
Definition
substring(int i) substring(int i, int j) |
|
|
Term
How to convert a character to an integer |
|
Definition
int newInt = (int) character; |
|
|
Term
Turn an integer into a character |
|
Definition
char aCharacter = (char) integer; |
|
|
Term
|
Definition
|
|
Term
|
Definition
A = 65 Z = 90 a = 97 z = 122 |
|
|
Term
How to sort a dictionary by key |
|
Definition
sorted_dict = dict(sorted(my_dict.items()) |
|
|
Term
How to sort a dictionary by descending value |
|
Definition
sorted_dict = dict(sorted(my_dict.items(), key = lambda item: item[1], reverse = True) |
|
|
Term
How to get the first key from a dictionary |
|
Definition
|
|
Term
|
Definition
The is-a relationship between a more general superclass and a more specialized subclass. |
|
|
Term
|
Definition
A general class from which a more specialized class (a subclass) inherits |
|
|
Term
|
Definition
A class that inherits variables and methods from a superclass but adds instance variables, adds methods, or redefines methods |
|
|
Term
|
Definition
The principle that a subclass object can be used in place of any superclass object. |
|
|
Term
|
Definition
redefining a method in a subclass |
|
|
Term
|
Definition
Giving more than one meaning to a method name |
|
|
Term
|
Definition
Selecting a method to be invoked at run time. In Java, dynamic method lookup considers the class of the implicit parameter object to select the appropriate method. |
|
|
Term
|
Definition
Selecting a method among several methods that have the same name on the basis of the actual types of the implicit parameters |
|
|
Term
|
Definition
A value that is computed by a hash function |
|
|
Term
|
Definition
A type with no instance variables, only abstract methods and constants |
|
|
Term
implementing an interface |
|
Definition
Implementing a class that defines all methods specified in the interface |
|
|
Term
|
Definition
A class that is defined inside another class. |
|
|