Shared Flashcard Set

Details

Java: Beginning of Semester
Java concepts from the beginning of the semester
37
Computer Science
Graduate
12/01/2024

Additional Computer Science Flashcards

 


 

Cards

Term
LOAD (op code and description)
Definition
0
Adds the value at the address in operand to the accumulator
Term
LOADI (op code and description)
Definition
1
Adds the value of the operand to the accumulator
Term
STORE (op code and description)
Definition
2
Stores the value in the accumulator to the address of the operand, sets accumulator to 0
Term
Bytecode, symbol table, and main memory for "x = 3 y = x + 2"
Definition
1, 3, 2, 0, 0, 0, 1, 2, 2, 1
x = 0, y = 1
3, 5
Term
How will the Interpreter code modify Parser? (4)
Definition
1) Parser has a data member that is a ByteCodeInterpreter object

2) parseExpression generates bytecode for loading ID and integer tokens

3) parseAssignment generates bytecode for storing the value of the expression on the right side of the assignment operator into the ID on the left side of the assignment operator
Term
How big are addressable slots in memory?
Definition
One byte
Term
What are the primitive types and how much space is allocated for each? (7)
Definition
Primitive types are not programmer-defined.

1) char: 16 bits
2) boolean: 8 bits
3) short: 16 bits
4) int: 32 bits
5) float: 32 bits
6) long: 64 bits
7) double: 64 bits
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
Term
How is a float represented in memory?
Definition
A binary number with a sign bit, a whole number part, and a fractional part. In the IEEE system, the whole number part has eight bits and the fractional part has 23 bits.
Term
How is a String represented in memory?
Definition
In the String pool, a section of the heap. Each character gets two bytes. At the end of every String is the null character, '\0', which is invisible.
Term
What does it mean for a value to overflow? (example)
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
What is the heap? (2)
Definition
The space in memory for dynamically allocated data. This includes objects created with "new", String literals, and arrays.
Term
What is the stack? (2)
Definition
1) Stores the data for each active method, including main

2) "This", function arguments, and a function's local variables
Term
What is an activation record?
Definition
A record of the data for each active method, including main()
Term
What is the String pool?
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? (2)
Definition
1) Static typing means that the type of a variable or data member must be declared, and it usually does not change (except under some specific circumstances). Dynamic typing means that the type is not declared and can be changed at any time.

2) In Java, a new variable can be created through casting of the original variable.
Term
Difference between an object and an object reference (2)
Definition
1) An object reference is the address of an object.

2) Class variables point to the address of an object.
Term
What do javac and java do?
Definition
Javac is the compiler. It checks for errors and generates bytecode. Then the bytecode goes to the Java Virtual Machine (JVM), which runs the program by changing the bytecode to machine code.
Term
How can a method affect the world? (2)
Definition
1) Returning a new value for a variable in main

2) Modifying data members
Term
"this" (3)
Definition
1) "This" is an implicit paramter of a method. It represents the object that the method will operate on.

2) Distinguishes data members from method parameters with the same name

3) Can call one constructor from another
Term
Static methods vs. instance methods: what is the difference, how to access (4)
Definition
1) Static methods are class-based. They are the same for any object. Instance methods operate on one object of the class.

2) Static accesss: Class.method. Instance access: object.method.

3) Static methods don't have data members other than constants.

4) Static methods use local variables from main().
Term
Understand the internals of ArrayList and how add() works. (3)
Definition
1) ArrayList has add() and remove(). Add grows teh 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 after the index shift to the right (a[i] = a[i - 1]).

3) To remove, the values after the index shift to the left (a[i] = a[i + 1]).
Term
Understand the difference between String and StringBuilder and how to use each. (3)
Definition
1) String is immutable. Its characters cannot be changed directly. StringBuilder is mutable.

2) You can use the append() method to add to the end of a StringBuilder and setCharAt() to change a value.

3) String values can be changed by concatenation.
Term
How is a Java class different from a struct in C? (3)
Definition
1) A struct only contains data members. A class contains data members, a constructor, and methods.

2) When accessing the data member of a struct, a pointer variable must be dereferenced. The pointer accesses the object it is pointing to, which then accesses the data member. The syntax is explicit: pointer->value. In Java, a variable is a pointer to an object, but this is implicit, so the syntax is variable.value.

3) Structs don't have functions, you have to send the struct in explicitly as a parameter to functions (Java does this implicitly).
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?
Definition
1) We don't want private data members to be accessed adn changed improperly. This could especially conflict with use of an object's methods.

2) When the data members are private, you can choose which ones you want to make setter methods for and which ones you don't.

3) You can use input validation in a setter method.
Term
When is it appropriate to mark a method as private?
Definition
When that method is a helper method. Calling a helper method on its own could cause an error when the method it helps is called.
Term
How to print the contents of an int array?
Definition
Arrays.toString(arr)
Term
Describe the additional information in the Java function signatures compared to those in Python, and vice versa. (3)
Definition
1) Java allows you to make some data members and methods private or protected.

2) Python is more explicit about passing an object of the class to a class method. Every method has "self" as a parameter (although "self" does not have to be passed when you call the method).

3) Java has return types and parameter types
Term
What happens if your class doesn't have a constructor?
Definition
Null data members, empty String, empty character, numbers and booleans set to 0
Term
What is a programmer-defined type? (2)
Definition
1) A programmer-defined type is a type declared as a class.

2) A class is a composite of different types. It has data members, methods, and a constructor to create an object of that class type.
Term
Is a String a primitive or a programmer-defined type? (3)
Definition
1) It is a programmer-defined type
2) It can hold a literal
3) Concatenation can be performed
Term
What is a bit? (2)
Definition
1)A single 0 or 1.
2) It corresponds to a single electric current either on (1) or off (0).
Term
What does byte-addressable mean? (2)
Definition
Everything in memory is stored in byte-sized slots, and these slots can be accessed by their numerical address
Term
How would foo.f1(5) be coded in a non-OO language?
Definition
f1(foo, 5)
Term
pass-by-value and pass-by-reference (4)
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.

2) Usually, the value of the copy that is returned will be stored in a new variable in main().

3) Pass-by-reference passes the address, directly changing the variable in memory.

4) If your parameter is an object, you are sending a pointer to an object.
Term
Encapsulation and information hiding
Definition
-- Encapsulation means putting data members and methods together in a capsule (a class). This hides the class's data members and method implementations.

-- Information hiding provides a public interface and keeps data members, method implementation, and some entire methods (especially helper methods) hidden.
Supporting users have an ad free experience!