Claude 2205

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

1/87

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:21 PM on 10/16/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

88 Terms

1
New cards

What is a compile-time error?

An error the compiler catches before the program runs, so no bytecode is produced.

2
New cards

Name 3 common causes of compile-time errors.

Syntax errors (missing semicolon), type mismatches (int x = "hi";), using an undeclared variable.

3
New cards

What is a runtime error?

An error that happens while a program that compiled successfully is running, because it tries an operation that can't be done.

4
New cards

What is a logic error?

The program compiles and runs without crashing but produces the wrong result.

5
New cards

Compile or runtime error? int x = "hello";

Compile error. Type mismatch: a String can't be assigned to an int.

6
New cards

Compile or runtime error? int[] a = new int[3]; a[3] = 1;

Runtime error: ArrayIndexOutOfBoundsException. Valid indices are 0 to 2.

7
New cards

Compile or runtime error? int z = 0; int x = 10 / z;

Runtime error: ArithmeticException (integer division by zero).

8
New cards

Compile or runtime error? String s = null; s.length();

Runtime error: NullPointerException.

9
New cards

What is a wrapper class?

A class that wraps a primitive so it can be used as an object. int → Integer, double → Double, char → Character, boolean → Boolean.

10
New cards

What is autoboxing?

Java automatically converting a primitive into its wrapper object. Example: Integer x = 5;

11
New cards

What is unboxing?

Java automatically converting a wrapper object back into its primitive. Example: int y = x; where x is an Integer.

12
New cards

Why can't you write ArrayList?

Generics only accept reference types, so you use the wrapper: ArrayList.

13
New cards

What happens? Integer x = null; int y = x;

Runtime NullPointerException, because Java tries to unbox null.

14
New cards

What is a recursive method?

A method that calls itself to solve a smaller version of the same problem.

15
New cards

What is the base case in recursion?

The condition where the method returns directly without calling itself. It stops the recursion. A method can have more than one.

16
New cards

What is the recursive case?

The part where the method calls itself on a smaller input that moves toward the base case.

17
New cards

What happens if a recursive method never reaches a base case?

It keeps calling itself until the call stack runs out: StackOverflowError.

18
New cards

What is the depth of recursion?

The number of times a method calls itself before reaching the base case.

19
New cards

Why does recursion use more memory than a loop?

Every call adds a new frame (its parameters and local variables) to the call stack, and it stays there until that call returns.

20
New cards

Is recursion ever required to solve a problem?

No. Any recursive solution can also be written iteratively with a loop.

21
New cards

Iteration vs recursion: how does each one repeat work?

Iteration repeats a block with a loop until its condition is false. Recursion repeats by the method calling itself until it hits the base case.

22
New cards

What does factorial(3) return? static int factorial(int n) { if (n <= 1) return 1; return n * factorial(n - 1); }

  1. factorial(3) = 3 * factorial(2) = 3 * 2 * factorial(1) = 3 * 2 * 1.


23
New cards

What is a generic class?

A class written with a type parameter so the same code works with different reference types.

24
New cards

What is the main benefit of generics?

Compile-time type safety: the compiler catches the wrong types, and you don't need casts.

25
New cards

Type parameter vs type argument?

Type parameter: the placeholder in the declaration (T in class Box). Type argument: the real type you plug in when you use it (String in Box).

26
New cards

Write the header of a generic class Box with one type parameter.

public class Box

27
New cards

Class vs object?

A class is the blueprint. An object is an instance created from that blueprint with new.

28
New cards

What does it mean for a class to be public?

Any other class can access it, including classes in other packages.

29
New cards

Can a class be private?

Only if it's nested inside another class. Then only the enclosing class can use it. Top-level classes can only be public or package-private (no modifier).

30
New cards

What does static mean?

The member belongs to the class itself, not to any one object. There is one shared copy for all instances.

31
New cards

How do you call a static method?

ClassName.methodName(), with no object needed. Example: Math.sqrt(16).

32
New cards

Why can you call Math.max(3, 5) without writing new Math()?

max is a static method, so it belongs to the Math class, not to an object.

33
New cards

Can a static method directly use an instance variable?

No. A static method has no object (no this), so it can only directly access static members.

34
New cards

3 objects of a class share a static int count. How many copies of count exist?

One, shared by all objects.

35
New cards

What does void mean as a return type?

The method doesn't return a value. You can still use return; to exit early.

36
New cards

Array vs ArrayList: size

An array's size is fixed when created (new int[5]). An ArrayList grows and shrinks automatically as you add and remove.

37
New cards

Array vs ArrayList: what types can they hold?

An array can hold primitives or objects. An ArrayList holds only objects, so primitives go in as wrappers (ArrayList).

38
New cards

How do you get the size of an array, an ArrayList, and a String?

arr.length (a field, no parentheses), list.size(), str.length().

39
New cards

What is an exception?

An object representing an error event at runtime that disrupts the normal flow of the program.

40
New cards

What happens when an exception is not handled?

The program terminates and prints the exception and its stack trace.

41
New cards

What does exception handling let you do?

Catch the exception and decide how to respond, so the program can keep running instead of crashing.

42
New cards

What are the 3 parts of exception handling?

Declaring (throws in the method header), throwing (throw new SomeException()), and catching (try/catch).

43
New cards

throw vs throws?

throw actually throws an exception object inside a method. throws in the method header declares that the method might throw it.

44
New cards

What is a checked exception?

An exception the compiler forces you to deal with: catch it with try/catch or declare it with throws, otherwise it won't compile. Example: IOException.

45
New cards

What is an unchecked exception?

A RuntimeException or one of its subclasses. Handling is optional. Examples: NullPointerException, ArrayIndexOutOfBoundsException, ArithmeticException.

46
New cards

Does this compile? public void read() { throw new IOException(); }

No. IOException is checked, so it must be caught or the method needs "throws IOException" in its header.

47
New cards

Does this compile? public void get(int[] a) { int x = a[10]; }

Yes. ArrayIndexOutOfBoundsException is unchecked, so the compiler doesn't require handling. It may fail at runtime.

48
New cards

What is try-catch used for?

Write the code

Try catch is a general method for EH

If it throws an exception it automatically just jumps to a predefined catch block that has the right solution alr built in

If no exceptions occur the catch blocks are just ignored

<p>Try catch is a general method for EH<br><br>If it throws an exception it automatically just jumps to a predefined catch block that has the right solution alr built in<br><br>If no exceptions occur the catch blocks are just ignored </p>
49
New cards
50
New cards
51
New cards
52
New cards
53
New cards
54
New cards
55
New cards
56
New cards
57
New cards
58
New cards
59
New cards
What does the finally block do?
It always runs after the try (and catch, if one ran), whether an exception happened or not.
60
New cards
Name 3 factors to consider when choosing a data structure.
What information will be stored, how it will be used, and how memory and storage should be managed. (Also: where data is kept, the best way to organize it.)
61
New cards
Which can be traversed in a single run: linear or non-linear structures?
Linear. Non-linear structures (trees, graphs) can't be traversed in a single run because they have multiple levels.
62
New cards
Where are linear vs non-linear data structures typically applied?
Linear: mainly general software development. Non-linear: AI and image processing.
63
New cards
What makes an array a "concrete" data structure?
It stores same-type elements in consecutive memory locations, and it's the only concrete data structure a language provides by default.
64
New cards
In Java, what is an array, and what is its direct superclass?
An array is an object stored in the heap. Its direct superclass is Object, so all Object methods can be called on it.
65
New cards
char[] x, y; What does this declare?
Two char array reference variables, x and y. Each can point to a different char array.
66
New cards
double[] a = {1.9, 2.9, 3.4}; is equivalent to what?
double[] a = new double[]{1.9, 2.9, 3.4};
67
New cards
Why use an array instead of separate variables?
One array reference can store many values (e.g. 100 ints) and be processed with a loop, instead of declaring 100 variables.
68
New cards
Linear search on {55, 93, 65, 70, 74} for key 70. What does it return?
3, the index of the first match.
69
New cards
Linear search compares Integer objects with ma[i] == vtf. Why is this risky?
== on Integer compares references, not values. It only works reliably for values from -128 to 127 because Java caches those. Use .equals() instead.
70
New cards
Does Java check array bounds at compile time or run time?
Run time only. The code compiles, then accessing an invalid index throws ArrayIndexOutOfBoundsException.
71
New cards
Insert 35 at index 2 into {25, 14, 56, 15, 36}. Resulting array?
[25, 14, 35, 56, 15, 36]
72
New cards
Which best describes an array: same-type elements, generally 2D, or a data type not a data structure?
A data structure that contains elements of the same type.
73
New cards
Integer[] arr = {10, 23, 13, 47, 65}; What is printed by printf("%d and %d", arr[1], arr[3])?
23 and 47
74
New cards
Integer[] arr = new Integer[15]; How many elements does the array in the heap hold?
15
75
New cards
What is a data structure?
A way of organizing data in memory so it can be stored, accessed, updated, and retrieved efficiently.
76
New cards
Linear vs non-linear data structure?
Linear: elements in sequential order, each connected to the previous and next, single level. Non-linear: elements connected hierarchically across multiple levels.
77
New cards
Examples of linear and non-linear data structures?
Linear: array, stack, queue, linked list. Non-linear: tree, graph.
78
New cards
Which wastes more memory, linear or non-linear structures?
Linear. Non-linear structures use memory more efficiently but are more complex to implement.
79
New cards
Static vs dynamic data structure?
Static: fixed size decided when created (array). Dynamic: can grow and shrink while running (stack, queue, linked list).
80
New cards
Homogeneous vs heterogeneous data structure?
Homogeneous: all elements are the same type (array). Heterogeneous: elements of different types (fields in a class).
81
New cards
Default values of a new array's elements?
0 for numeric types, '\u0000' for char, false for boolean, null for any object type.
82
New cards
Student[] s = new Student[3]; s[0].getName(); What happens?
NullPointerException. The array holds 3 null references; each element needs s[i] = new Student() first.
83
New cards
In double[] a = new double[5]; where do a and the elements live?
The reference a is on the stack. The array elements are in the heap. a points to the array's first location in the heap.
84
New cards
How does linear search work?
Compare the key with each element in order. Return the index of the first match, or -1 if the list ends with no match.
85
New cards
How do you "resize" an array in Java?
You can't. Create a new array of the new size and copy elements over with System.arraycopy, or use ArrayList.
86
New cards
What are the 5 parameters of System.arraycopy, in order?
(source array, source start index, destination array, destination start index, number of elements to copy)
87
New cards
Steps to insert a value at index i in an array?
Make a new array of size length+1. Copy elements from i onward into new positions i+1 onward. Copy elements before i. Put the new value at index i.
88
New cards
What does System.arraycopy(arr, 1, newArr, 0, newArr.length) do if newArr is 1 shorter than arr?
Copies everything except arr[0] into newArr, which removes the first element.