Uploaded by championtraxstar

Java II Finals SG

advertisement
Justin DeJesus
Java II Study Guide
------------------------------------------------------------------------------------------------------------1. What is inheritance?
Inheritance in Java is a mechanism where a class can inherit attributes and
methods from another class. It allows for code reusability and the creation of a
hierarchical relationship between classes.
2. The original class can be referred to in three different ways, what are they?
The original class can be referred to as the parent class, superclass, or base class.
3. The derived class can be referred to in two different ways, what are they?
The derived class can be referred to as the child class or subclass.
4. What type of relationship does proper inheritance create?
Proper inheritance creates an "is-a" relationship between classes.
5. When we say inheritance is transitive, what does that mean?
When inheritance is transitive, it means that if class C extends class B, and class B
extends class A, then class C also inherits from class A.
6. What is an abstract method?
An abstract method is a method that is declared without an implementation.
7. What is an abstract class?
An abstract class is a class that cannot be instantiated and may contain abstract
methods.
8. What does polymorphism allow us to do?
Polymorphism allows us to perform a single action in different ways. It enables
objects of different classes to be treated as objects of a common superclass.
9. What can happen to a method if it is called through a polymorphic reference?
When a method is called through a polymorphic reference, it may be overridden by
a subclass implementation.
10. What is sorting?
Sorting is the process of arranging data items into ascending or descending order.
11. What is the strategy we use for selection sort?
The strategy for selection sort is to repeatedly select the smallest (or largest)
element from the unsorted portion of the list and move it to the sorted portion.
12. What does the compareTo method do?

a. What does it return if input1 < input2?
o

b. What does it return if input1==input2?
o

The compareTo method returns a negative integer if input1 is less
than input2.
The compareTo method returns zero if input1 is equal to input2.
c. What does it return if input1>input2?
o
The compareTo method returns a positive integer if input1 is greater
than input2.
13. What is the strategy for insertion sort?
The strategy for insertion sort is to build the final sorted array one item at a time,
by repeatedly inserting a new element into the already sorted portion of the array.
14. What is a search pool?
A search pool is the set of elements that are being searched to find a specific item.
15. What is an exception?
An exception is an event that occurs during the execution of a program that
disrupts the normal flow of instructions.
16. List scenarios that may cause an exception to be thrown
Scenarios include division by zero, out-of-range values, null pointer exceptions, file
not found, network errors, etc.
17. What is the call stack trace?
The call stack trace is a list of the method calls that led to the exception being
thrown.
18. What does each line of the call stack trace represent? Like what is the data it
gives us?
Each line of the call stack trace represents a method call, providing information
such as the method name, class name, and line number where the method was
called.
19. Explain the purpose of a try-catch statement?
The purpose of a try-catch statement is to handle exceptions by enclosing code
that might throw an exception in a try block and catching the exception in a catch
block to prevent the program from terminating abruptly.
20. What is exception propagation?
Exception propagation is the process by which an exception is passed from one
method to another until it is caught or reaches the main method.
21. What is the throwable class? What reserved word does it give us access to?
The Throwable class is the superclass of all exceptions and errors in Java. It gives us
access to the throws reserved word, which is used to declare that a method may
throw an exception.
22. What are the three standard I/O streams?
The three standard I/O streams are System.in (standard input), System.out
(standard output), and System.err (standard error).
23. What is system.in, system.out, and system.err?

System.in: The standard input stream.

System.out: The standard output stream.

System.err: The standard error stream.
24. In general, recursion is the process of what?
In general, recursion is the process of solving a problem by breaking it down into
smaller subproblems of the same type.
25. We continue to break the problem down into smaller subproblems until we reach
what?
We continue to break the problem down into smaller subproblems until we reach
the base case.
26. What is a base case?
A base case is the simplest form of the problem that can be solved directly without
further recursion.
28. What happens if we do not have a base case?
If we do not have a base case, the recursion will continue indefinitely, leading to a
stack overflow error.
29. When working with recursion, each call to the method creates a new
environment in which to work, what does that mean? Explain
Each recursive call creates a new stack frame, which includes the method's
parameters, local variables, and return address. This allows each recursive call to
operate independently without interfering with the state of other calls.
30. What is the difference between direct recursion and indirect recursion? Explain
both

Direct Recursion: A method calls itself directly. For example, a method
factorial calls itself to calculate the factorial of a number.

Indirect Recursion: A method calls another method, which in turn calls the
original method. For example, methods A and B call each other.
32. What is a collection?
A collection is an object that groups multiple elements into a single unit.
33. What are some collections you can think of that would add, remove, or manage
elements?
Examples include lists, sets, maps, queues, and stacks.
34. What is stable sorting?
Stable sorting is a sorting algorithm that maintains the relative order of equal
elements after sorting.
35. What is unstable sorting?
Unstable sorting is a sorting algorithm that does not maintain the relative order of
equal elements after sorting.
36. What is an abstract data type? What are the attributes of an abstract data type?
An abstract data type (ADT) is a high-level description of a data structure that
specifies its behavior without detailing its implementation. Attributes include the
operations that can be performed on the data type and the constraints on those
operations.
37. A static data structure has a fixed what?
A static data structure has a fixed size.
38. Based on question 37, why can this be an issue?
This can be an issue because it limits the flexibility of the data structure, as it
cannot adapt to changes in the amount of data.
39. What is a dynamic data structure?
A dynamic data structure is one whose size can change during the execution of the
program.
40. What do we use to link objects in dynamic data structures?
We use references (or pointers) to link objects in dynamic data structures.
41. What is a reference (pointer)?
A reference (or pointer) is a variable that holds the memory address of another
variable.
42. What type of data structures can we make with references? List 3
Examples include linked lists, trees, and graphs.
43. What is a linked list?
A linked list is a linear data structure where elements are stored in nodes, and each
node points to the next node in the sequence.
44. Nodes in a singly linked list are composed of what? What about a doubly linked
list?

Singly Linked List: Nodes are composed of data and a reference to the next
node.

Doubly Linked List: Nodes are composed of data and references to both the
next and previous nodes.
45. Each element of a list is an object with?
Each element of a list is an object with data and possibly references to other
elements.
46. Understand how the three linked list functions work
The three main functions are:

Insert: Adds a new node to the list.

Delete: Removes a node from the list.

Search: Finds a specific node in the list.
47. What is the main benefit that we gain with linked lists compared to arrays?
The main benefit is that linked lists allow for efficient insertion and deletion of
elements at any position, unlike arrays which require shifting elements.
48. What is a stack?
A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle.
49. What is the policy of a stack?
The policy of a stack is that the last element added to the stack will be the first one
to be removed.
50. How are stacks represented? Draw one, which direction does it grow?
Stacks are typically represented vertically, with the top element at the top of the
stack. The stack grows upwards.
51. What are the two functions to build/maintain a stack?
The two main functions are:

Push: Adds an element to the top of the stack.

Pop: Removes the top element from the stack.
52. What does top do?
The top function returns the top element of the stack without removing it.
53. What is a queue?
A queue is a linear data structure that follows the First-In-First-Out (FIFO) principle.
54. What is the policy for a queue?
The policy for a queue is that the first element added to the queue will be the first
one to be removed.
55. What are the insertion and deletion operations for a queue?

Enqueue: Adds an element to the end of the queue.

Dequeue: Removes the front element from the queue.
56. What does the head do? What does the tail do?

Head: The front of the queue, where elements are removed.

Tail: The end of the queue, where elements are added.
57. Be able to explain Enqueue and Dequeue

Enqueue: The process of adding an element to the end of the queue.

Dequeue: The process of removing the front element from the queue.
58. What are two forms of non-linear data structures?
Two forms are trees and graphs.
59. What is a tree?
A tree is a hierarchical data structure consisting of nodes connected by edges.
60. What are all the attributes of a tree?
Attributes include:

Root: The topmost node.

Edges: Connections between nodes.

Leaf Nodes: Nodes with no children.

Internal Nodes: Nodes with children.
61. Please know how to fill in this tree with the appropriate attributes
This involves identifying the root, edges, leaf nodes, and internal nodes.
62. What is a binary tree?
A binary tree is a tree data structure in which each node has at most two children,
referred to as the left child and the right child.
63. What is a graph?
A graph is a non-linear data structure consisting of vertices (or nodes) and edges
that connect these vertices.
64. Typically what are the two types of graphs?
The two types are undirected graphs and directed graphs.
65. Explain a undirected graph vs a directed graph

Undirected Graph: Edges do not have direction and can be traversed in both
directions.

Directed Graph: Edges have direction and can only be traversed in one
direction.
66. Know how to convert a graph to an adjacency matrix / or an adjacency matrix to
a graph
Converting involves representing the graph using a matrix where entries indicate
the presence of edges between vertices, or vice versa.
67. What is a map? Explain why they are efficient. Are maps one way or two way?
A map is a data structure that stores key-value pairs. They are efficient for lookups
because they allow direct access to values using keys. Maps are typically one-way
(from key to value).
68. Make an example of a map
An example could be a dictionary where words are keys and their meanings are
values.
69. What are two ways to implement a map?
Two ways are using a TreeMap and a HashMap.
70. Explain a treemap, draw an example
A TreeMap is a sorted map implementation that uses a red-black tree. It maintains
the keys in sorted order.
71. Explain a hashmap, draw an example
A HashMap is an implementation of the Map interface that uses a hash table for
storing key-value pairs. It does not maintain any order.
72. What is a key and what is a value?

Key: A unique identifier used to access a value.

Value: The data associated with a key.
73. What is the method to add a new entry to a map?
The method to add a new entry is typically put(key, value).
74. What is the method to look up a value using a key?
The method to look up a value is typically get(key).
75. What can the var keyword be used for?
The var keyword can be used for local variable type inference, allowing the
compiler to determine the type of a variable based on its initializer.
76. What is a lambda function? Why are they useful?
A lambda function is a short block of code which takes in parameters and returns a
value. They are useful for creating simple function objects.
77. What is the form of a lambda expression?
The form of a lambda expression is (parameters) -> {body}.
78. What are the limitations of a lambda expression?
Limitations include the inability to declare local variables with the same name as
variables in the enclosing scope, and the inability to use break or continue
statements.
79. What can a lambda expression be applied to? What is a stream?
Lambda expressions can be applied to functional interfaces. A stream is a sequence
of elements supporting parallel and functional-style operations.
Download