CS180 Final Exam

0.0(0)
studied byStudied by 0 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/205

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 8:16 PM on 12/15/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

206 Terms

1
New cards

Name 8 primitive types in Java

int, double, short, long, float, byte, boolean, char

2
New cards

Strings are...

immutable, Objects, Not Primitive Types, Made up of letters

3
New cards

default int

0

4
New cards

default char

\u0000

5
New cards

default double

0.0d

6
New cards

default byte

0

7
New cards

default float

0.0f

8
New cards

default long

0L

9
New cards

default boolean

false

10
New cards

default short

0

11
New cards

Which of the following is the data type used for holding a single character?

a) Strings

b) char

c) int

d) all of the above

d) all of the above

12
New cards

what does immutable mean in terms of Strings?

Once you set a String to a specific value, you cannot change it character by character

13
New cards

Assume you have this line of code in your project:

String eclipse = "Not IntelliJ!";

What would invocation of eclipse.length() return?

13

14
New cards

How to write switch statement?

switch(str) {

case "CS180":

//print something

break;

default;

//print something

break;

}

15
New cards

-> switch statements

switch(number) {

case 0 -> System.out.println("zero");

case 1 -> System.out.println("one");

default -> {

case 11, 13, 15 -> System.out.println("An odd number");

case 12, 14, 16 -> System.out.println("An even number");

}

}

16
New cards

when is && used?

when both or all conditions must be evaluated as true in order for the conditional to evaluate true

17
New cards

when is || used?

when one or both conditions must be evaluated as true in order for the conditional to evaluate true

18
New cards

What can boolean evaluation in if statements use?

logical operations (AND &&, OR ||) or Bitwise (AND &, OR ^, OR |)

19
New cards

What does bitwise return?

1 - if results are different

0 - otherwise

20
New cards

What will the following block of code print?

for(int i = 0; i < 3; i++) {

switch(i) {

case 1:

System.out.println("1");

case 2:

System.out.println("2");

case 3:

System.out.println("3");

}

}

12323

21
New cards

What will the following block of code do?

if (0b10 != 0b1)

System.out.println("false");

false

22
New cards

What are the four different types of loops?

while, do-while, for, Enhanced for loop (also called for-each loop)

23
New cards

Does while loop execute at least once or upon entry of the loop?

upon entry of the loop

24
New cards

Does do-while loop execute at least once or upon entry of the loop?

At least once, this is due to the condition being checked at the end of the loop, rather than the beginning like a while loop

25
New cards

Does for loop execute at least once or upon entry of the loop?

execute at least once except if the conditions in the for(int i = 0...) is not executable

26
New cards

what is an enhanced for loop?

The enhanced for loop can be used to iterate over a set of data, like a list or an array. It can also be used for any class that implements the Iterable interface

public void enhancedForLoop() {

int[] arrayOfNumbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

for (int i : arrayOfNumbers) {

System.out.println(i);

}

}

27
New cards

Which of the following is not a loop in Java?

a) for-each

b) for-every

c) for

d) while

b) for-every

28
New cards

Which of the following is the loop where at least one execution is guaranteed?

a) for-each

b) for

c) while

d) do-while

d) do-while

29
New cards

Which of the following loops is best for handling large data sets with an unknown size?

a) for-each

b) for

c) while

d) do-while

a) for-each

for (int i : array){}

30
New cards

What is in a methods signature?

Their name, their number, order and types of their parameters

31
New cards

define static

static, for making methods accessible without object declaration, In other words, they are class level methods.

32
New cards

define final

final, for making methods or fields, non modifiable. The values there are considered final, and once initiated, cannot be modified.

33
New cards

define transient

transient, if an object is going to be serialized, fields marked with the transient modifier will be excluded when the object is written. In other words, it indicates a field that should not be persistent between serialization.

34
New cards

define serialization

allows us to convert an Object to stream that we can send over the network or save it as a file or store in a database for later usage

35
New cards

what does using final in a field mean?

if a field is final, it cannot be modified in a method, and must be initialized at the time of declaration

You can also assign final fields inside a constructor, barring the fact that their value cannot be changed at a later time in the program

36
New cards

what does using static in a field mean?

using static with fields means that the field is at a class level an can be accessed without creation of an object

37
New cards

Should methods and fields be public or private by convention?

fields should be private and methods should be public

38
New cards

write a setter method or mutator method

public void setAnInt(int value) {

anInt = value;

}

39
New cards

write a getter method or accessor method

public int getAnInt() {

return anInt;

}

40
New cards

Which of the following is considered to be part of the method signature?

a) throws declaration

b) access modifier

c) final modifier

d) method name

d) method name

41
New cards

Which of the following is the modifier to determine an unchangeable, final, value?

a) default

b) public

c) final

d) static

c) final

42
New cards

What is the default access modifier for a method?

a) public

b) private

c) static

d) package-private

d) package-private

43
New cards

Getter and Setter methods are also called ______ and ______.

a) access modifier and deaccess modifier

b) grabbers and placers

c) accessor and mutator

d) mutator and accessor

c) accessor and mutator

44
New cards

what are three ways to initialize an array?

int[] array1 = {1, 2, 3, 4, 5};

int[] array2 = new int[20];

int[] array3 = new int[]{1, 2, 3, 4, 5};

45
New cards

What is the last position in the following array?

int[] array2 = new int[20];

19

46
New cards

what is an example of a 2D array?

String[][] array = new String[10][10];

47
New cards

what is used to loop through a 2D array?

matrix.length and matrix[0].length

48
New cards

what is a ragged or jagged array?

When the columns are not the same amount for each row

int[][] raggedArray = new int[3][];

raggedArray[0] = new int[5];

raggedArray[1] = new int [3]

raggedArray[2] = new int[4];

49
New cards

what are two ways to initialize an arrayList?

ArrayList<type> someList = new ArrayList<type>();

Or you can have Java infer it:

ArrayList<type> someList = new ArrayList<>();

50
New cards

What are the two most common methods to use for ArrayLists?

set(): changing a value at a specific index

add(): add an element in between specific indicies, implicitly shifting all elements right by one.

51
New cards

What does the <> brackets in a definition of an ArrayList mean?

a) Inferred data types from the initialization

b) Part of the ArrayList class

c) Defines something as a list

d) Generic brackets defining data type

d) Generic brackets defining data type

52
New cards

True or False - Arrays can only be a maximum of 3 dimensions.

False

53
New cards

True or False? Arrays have set sizes.

True

54
New cards

What is a pattern that should be followed when using FileIO?

Java -----> Open -> Read

\

> Write

55
New cards

A file needs to exist in order to read it (FileIO)

True

56
New cards

A file needs to exist in order to write in it (FileIO)

false

the file doesn't have to exist, and once the data is flushed to the file, the files will be created.

57
New cards

What are the three levels of FIle I/O?

Low Level

High Level

Object Level

58
New cards

What is a Low Level File I/O?

- Raw data - byte oriented

- Mainly used FileOutputStream and FileInputStream to process data in and out of the file.

59
New cards

What is a High Level File I/O?

- Primitive types, for File I/O such as int, long, short, double, char and even String

- Normally use DataOutputStream and DataInputStream

60
New cards

What is a Object I/O (Serialization)?

- Objects that you create or objects from a Java package

- Done using ObjectOutputStream and ObjectInputStream

- If it's done using your own class, you must include the implements Serializable keyword in the class header

61
New cards

Why would an OptionalDataException be thrown?

If the data was not received in the same order that it was sent

62
New cards

Which reader type is best for high volumes of data?

BufferedReader

63
New cards

What do you have to do to ensure that data is written to a file every time?

a) Make sure the file exists

b) Ensure that you flush after every write statement

c) Verify that the file is empty before writing to it

b) Ensure that you flush after every write statement

64
New cards

When reading from a file what do you have to do before reading?

a) Make sure the file exists

b) Attempt to read data from the file before writing

c) Ensure that you flush every write statement

d) Verify that the file is empty before writing to it

a) Make sure the file exists

65
New cards

When performing an append operation on a file during the writing process, which are valid ways of doing this?

a) Read all the data into an ArrayList, and append the data into the list, which you would then overwrite the file with.

b) Write to the file using the append operation of a writer that supports this.

c) Write to the file, and hope the writer doesn't delete past data.

d) Do a check on whether the file already has data in it - if it does, read that in, and then write new data to the file, including the old data.

a) Read all the data into an ArrayList, and append the data into the list, which you would then overwrite the file with.

b) Write to the file using the append operation of a writer that supports this.

d) Do a check on whether the file already has data in it - if it does, read that in, and then write new data to the file, including the old data.

66
New cards

What is the name of the exception that is thrown is the file cannot be found, when writing data?

a) ArrayIndexOutOfBoundsException

b) FileNotFoundException

c) OptionalDataException

d) No exceptions are thrown

d) No exceptions are thrown

67
New cards

What is the name of the exception that is thrown if the file does not exist, when reading data from the file?

a) ArrayIndexOutOfBoundsException

b) FileNotFoundException

c) OptionalDataException

d) No exceptions are thrown

b) FileNotFoundException

68
New cards

What does the class extend when writing a custom exception?

extends Exception

69
New cards

What is the name of errors that are reported in the code?

stack trace

70
New cards

What is an example of a try catch?

try {

//code

} catch (Exception e) {

//do something

}

71
New cards

what does final do in a try catch block?

the code in final clause will run everytime

72
New cards

example of a try-with-resources block

try (PrintWriter writer = new PrintWriter(new File("Test.txt"))) {

writer.println("Hello World")

}

Resources are allocated inside the parenthesis of the try block, and are automatically close at the ends of the try block or if the catch blocks executes

73
New cards

Which of these exception(s) is unchecked almost always?

a) NullPointerException

b) IOException

c) StackOverflowException

d) All of the above are checked exceptions

a) NullPointerException

74
New cards

How can you ensure that resources are shut off before program ends?

a) Use the reader's close() method, or the equivalent.

b) Use a try-wtih-resources statement

c) Hope that your program closes all resources

d) A and B

d) A and B

75
New cards

When using a try-with-resources statement, what block is implied?

a) Catch Block

b) Finally Block

c) No code blocks are implied

d) Try Block

b) Finally Block

76
New cards

When using a standard try-catch clause, what is guaranteed to run after every try-catch statement?

a) Try Block

b) The throws statement

c) Catch Block

d) Finally Block

d) Finally Block

77
New cards

(Should be known for the Exam) What does implements Serializable do?

Marks a class as something that will be transferred over a stream, such as a FileOutputStream or a Socket connection.

78
New cards

(Should be known for the Exam) What does implements Iterable do?

Defines a class that can be iterated over, in a loop for example

79
New cards

What does having a default method in an interface mean?

This defines the method to contain code that does not have to be implemented every time.

public interface anInterface {

default public void displayNameDefault(String name) {

System.out.println("Your name is " + name);

}

public void displayName(String name);

public void displayNameAndJobTitle(String name, String jobTitle);

}

80
New cards

Can you extend more than one super class?

No

81
New cards

Can you implement multiple interfaces?

Yes

82
New cards

If you extend a class what must you put in the sub classes constructor?

The first line must be an explicit call to the super class's constructor, via the super() call

83
New cards

How do you use instanceof in terms of inheritance?

public class Employee extends Person{}

By using the instanceof keyword here , you would be able to tell if an object of the Person class is an instance of an Employee

84
New cards

What is the difference between Overloading and Overriding?

Overloading is when you have two methods of the same name, but different signature - that is, different(number and types of) parameters and return type.

Overriding is when you have a method in the super class that you are writing in a child class to perform something different than the super class. Think about equals() or toString() methods. For overriding, the signature and name must be identical.

85
New cards

Which of these interfaces require implementation of 0 methods?

a) Serializable

b) Iterator

c) Comparable

d) Runnable

a) Serializable

86
New cards

Suppose you have two constructors, one that takes an integer, and one that takes an integer and a String. How can you call the two parameter constructor from the one parameter constructor? Assume the integer is called num, and the String, str.

a) this(num, str)

b) super(str, num)

c) this(str, num)

d) super.this(str, num)

a) this(num, str)

87
New cards

Can you have two methods with the same name in the same class?

a) No, Java doesn't allow this and your code will not compile.

b) Yes, provided that each methods signatures are different

c) No, because Java will not know which method to go to upon call.

d) Yes, because Java is smart enough to decide which one to choose based on the program's execution

b) Yes, provided that each methods signatures are different

88
New cards

How do you define an abstract class?

By declaring all the abstract methods

abstract String getDetails();

abstract int getAmount();

89
New cards

What is happening in this code?

public void makeItRain(ArrayList myMoney) {

ArrayList bills = new ArrayList<>();

for(Money m : bills) {

m.tossInAirRecklessly();

}

}

Java will invoke the tossInAirRecklessly() method for each Money object, invoking the specific implementation of whichever class the Money object was instantiated to

90
New cards

When writing a method with the same name and same signature as that of the super class in a child class, what is this concept called?

a) Overloading

b) Method overloading

c) Method Overriding

d) This concept is not allowed in Java

c) Method Overriding

91
New cards

When working with super classes, what is the modifier used to indicate that a method must be written in a child class?

a) static

b) abstract

c) implements

d) super.methodNameHere();

b) abstract

92
New cards

What is the concept called for Java deciding which method to use when incorporating a list of an abstract class?

a) Static Binding

b) Dynamic Binding

c) Dynamic Decision Making

d) Static Decision Making

b) Dynamic Binding

93
New cards

When running a program normally what is this called?

You are running the program sequentially

94
New cards

What is it called when you are running the program with threads?

You are running the program concurrently

95
New cards

What are two ways of creating threads in java?

Implementing the Runnable() interface and through that, implementing the run() method

or extending the Thread class

96
New cards

What are the four most useful methods to you in thread management for a Thread object called t?

t.start(), which starts the Thread and invoke the run() method

t.join(), which waits for another Thread to finish before executing

t.yield(), which pauses the execution of the Thread

t.sleep(....), which pauses the Thread for a parameterized amount of time in milliseconds

97
New cards

When do Race conditions occur?

When shared data is accessed by different threads simultaneously

Another way of putting it is two threads racing to update a field or get the newest value of a field

98
New cards

How to avoid race conditions?

shared data should have synchronized keyword. Think of it like a gatekeeper, in where only one thread is allowed to modify the field or get the newest data at a time.

99
New cards

Which of these methods do you use for making a Thread wait until another one finishes? Assume your thread object is called t.

a) t.start()

b) t.join()

c) t.yield()

d)t.run()

b) t.join()

100
New cards

Which of these methods do you use for making a thread wait for a specified amount of time before resuming?

a) t.join()

b) t.sleep(....)

c) t.yield()

d) t.interrupt()

b) t.sleep(....)