SPRING '25 FINAL Flashcards

(70 cards)

1
Q

What are method modifiers?

A

Modifiers define the visibility or accessibility of the method

Examples include public, private, and protected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the return type of a method that does not return a value?

A

void

Indicates that the method does not return any value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is included in a method’s definition?

A

Return type, method name, parameter list in parentheses

The method definition outlines how the method operates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when a method is called in terms of memory?

A

A new memory space is created for the method

This allows for the method to execute without affecting the caller’s memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In the context of memory, what does ‘max gets a new value X’ imply?

A

The variable max receives a new value during method execution

This indicates the method’s ability to change local variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the return statement in a method?

A

To return a value if there is a return type

If the method is void, no value will be returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is meant by ‘PassByReference’?

A

Refers to passing a reference to the original data, not a copy

Modifications to the data affect the original data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between shallow copy and deep copy?

A

Shallow copy creates a new reference to the same object, deep copy creates a new object with its own data

Shallow copy shares the same elements, deep copy duplicates them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the operation ‘newArray = originalArray’ signify?

A

newArray references the same array object as originalArray

This is an example of shallow copying.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Does modifying originalArray affect newArray?

A

Yes, if newArray is a shallow copy of originalArray

Changes to the original array will reflect in the new array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Fill in the blank: A block of code that performs a specific task is called a _______.

A

method

Methods are fundamental building blocks in programming.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does ‘workspace for main method’ refer to?

A

The memory space allocated for executing the main method

Each method has its own workspace to manage variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

True or False: The originalArray has random numbers filled by default.

A

False

By default, an array is filled with default values (e.g., 0 for integers).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the significance of the ‘temp’ variable in swapping?

A

It temporarily holds a value to facilitate the swap

This is a common technique in variable swapping.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do you call the method that executes code to find the maximum value?

A

findMax

This method is likely designed to compare two values and return the larger one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the initial state of numA and numB in memory?

A

numA = 10, numB = 15

These are example values that would be used in operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does ‘workspace for findMax method’ indicate?

A

Memory space allocated for the execution of the findMax method

Each method’s execution is isolated in its own workspace.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is an array?

A

A container object that holds a fixed number of values of a single type

Each item in an array is called an element and is accessed by its numerical index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the default value for elements in a primitive type array?

A

0

For reference types, the default value is null.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the syntax to declare an array of integers with a size of 5?

A

int[] scores = new int[5];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a 2D array?

A

An array that holds data points in a matrix format

It can be visualized as having rows and columns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you access an element in a 2D array located at row 0, column 1?

A

data[0][1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the declaration syntax for a 2D array with 5 rows and 6 columns?

A

int[][] data = new int[5][6];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What does data.length represent in a 2D array?

A

The size of the 1st dimension, which is the number of rows.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What does data[i].length represent in a 2D array?
The size of the 2nd dimension, which is the number of columns.
26
What is a jagged array?
An array of arrays where each sub-array can have different lengths ## Footnote This allows for a more flexible structure compared to a traditional rectangular array.
27
What are parallel arrays?
A solution for problems with table-like data using several 1D arrays, one for each column.
28
How do parallel arrays keep track of observations?
By using an index for each array to represent rows.
29
Fill in the blank: A 2D array can be thought of as a _______.
matrix
30
True or False: A parallel array is a language concept.
False ## Footnote It is a solution for managing data rather than a specific type in a programming language.
31
What is the purpose of using parallel arrays in programming?
To calculate stats such as average score or max score from table-like data.
32
What is the significance of the players.csv file in the context of parallel arrays?
It contains data lines after a header line, which can be used to populate parallel arrays.
33
What is an ArrayList?
A resizable array of objects
34
What type of elements can an ArrayList hold?
Any type of object, as long as the type is specified at declaration
35
True or False: An ArrayList itself is an object.
True
36
What happens to the size of an ArrayList when items are added or removed?
Automatically expands when a new item is added and shrinks when items are removed
37
What interface does ArrayList implement?
List interface
38
What is the syntax to declare an ArrayList for String objects?
ArrayList nameList = new ArrayList<>();
39
What must be included when using ArrayList in Java?
import java.util.ArrayList;
40
Fill in the blank: The type of the object to hold by the ArrayList is placed inside _______.
angled brackets <>
41
What will happen if you try to put an object of a different type into an ArrayList?
An error will occur
42
How do you print the contents of an ArrayList?
Using System.out.println(nameList) or System.out.println(nameList.toString())
43
How can you determine what methods can be used with an ArrayList?
Consult the Java API documentation for ArrayList
44
What are wrapper classes for primitive data types?
Classes that allow primitive types to be treated as objects
45
List the primitive data types in Java.
* int * char * float * double
46
List the corresponding wrapper classes for the primitive types.
* Integer * Character * Float * Double
47
What is autoboxing?
Automatic conversion between primitive types and their corresponding object wrapper classes
48
What is unboxing?
Converting an object of a wrapper type to its corresponding primitive value
49
What is an object in Java?
An instance of a class that holds data fields and methods.
50
What attributes does a 'Person' object typically have?
* ssn * name * age * gender * address
51
What keyword is used to create an instance of an object in Java?
new
52
What is a constructor in Java?
A method automatically called when an object is created, having the same name as the class with no return type.
53
What does the default constructor do?
Sets all numerical fields to 0, boolean fields to false, and reference variables to null.
54
What is the purpose of an instance field?
To store data specific to an object instance.
55
What are instance methods?
Methods that operate on an instance of a class and are not declared with static.
56
What is the difference between a setter and a getter?
* Setter: Stores or changes value in a field * Getter: Returns value from a field
57
Why can't you directly access a private field outside its class?
Private fields are only visible to their own class.
58
What is data hiding in Java?
Making class fields private to protect the object's privacy.
59
What is the purpose of public methods in a class?
To provide access to private fields.
60
What is the main advantage of encapsulation?
It protects an object's data and maintains integrity.
61
What does UML stand for?
Unified Modeling Language
62
What symbols are used in UML for access specifiers?
* + for public * - for private
63
What is the typical order of elements in a class layout?
* Fields * Constructors * Setters and getters * Other methods
64
Fill in the blank: A class can be considered a _______ data type.
custom
65
What is the role of a no-arg constructor?
Overrides the default constructor to set sensitive defaults.
66
How can you generate constructors, setters, and getters in Eclipse?
By using the Source menu to generate them after writing the data fields.
67
True or False: Instance fields are shared among all instances of a class.
False
68
What is the output of person1.getName()?
Returns the name of person1.
69
What does the PrintWriter class do?
Used for writing formatted text to a file or output stream.
70
What is the significance of a class being a blueprint?
It defines the structure and behavior of objects that can be instantiated.