CSIT228 Midterm Exam

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

1/117

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

118 Terms

1
New cards

Late-Binding

Another term for Polymorphism.

2
New cards

What makes Exception/Assertion important in programs?

Exceptions and assertions are important in programs because they help identify and handle errors efficiently. Exceptions allow programs to catch and manage runtime errors without crashing abruptly. Assertions help developers check for expected conditions during debugging, ensuring the program behaves correctly. Proper exception handling improves program stability and user experience by providing meaningful error messages. Using assertions can also prevent logical errors by enforcing constraints in critical parts of the code.

What makes Exception/Assertion important in programs?

3
New cards

Exception

represents an error condition that can occur during the normal course of the program execution.

4
New cards

InputMismatchException

an error that occurs when we try to convert a string that cannot be converted to a numerical value.

5
New cards

Try block

where we put the statements we want to be executed in response to the thrown exception.

6
New cards

Catch block

where we throw the exceptions / receives the exception.

7
New cards

Throwable Class

The exception is represented as an instance of which class?

8
New cards

Error and Exception

The Throwable class has 2 subclasses, what are they?

9
New cards

Exception and Error have the same kind of red concepts when it comes to a situational handling aspect in programming, but they serve different purposes in their entirety. Exception ensures the robustness and efficiency of the flow of the program, promoting proper handling of unexpected events that may occur during execution. It allows the program to recover gracefully from issues such as invalid inputs, file not found, or network failures. On the other hand, Error represents serious problems that are usually beyond the control of the program, such as system crashes, out-of-memory issues, or hardware failures. Unlike exceptions, errors are generally unrecoverable, meaning they should not be caught and handled but rather indicate critical failures that require fixing at the system level.

Difference between Error and Exception.

10
New cards

getMessage and printStackTrace

What are the 2 methods defined in the Throwable class that we can call to get some information about the thrown exceptions.

11
New cards

throw

the keyword to invoke an Exception

12
New cards

The system itself.

If no matching catch block is found, then who will handle the thrown exception?

13
New cards

Exception Thrower

calling a method that throws an exception.

14
New cards

Exception Catcher

is an exception thrower that includes a matching catch block for the thrown exception.

15
New cards

Exception Propagator

Passing exceptions.

16
New cards

IOError, VirtualMachineError, OutofMemoryError

What are the error subclasses?

17
New cards

IndexOutOfBoundsException

ArrayIndexOutofBoundsException

IllegalArgumentException

NumberFormatException

NoSuchElementException

NullPointerException

ClassCastException

Subclasses of RuntimeException

18
New cards

FileNotFoundException

EOFException

Subclasses of IOException

19
New cards

Checked exceptions must be handled with try-catch or declared with throws because they deal with expected problems like missing files. Unchecked exceptions happen during runtime, like dividing by zero or using a null value, and don't need to be declared. Checked exceptions help catch issues early, while unchecked ones usually come from coding mistakes. Both help make programs more stable.

Difference between Checked and Unchecked Exception

20
New cards

Compile Time

Checked Exceptions are checked at what?

21
New cards

Runtime

Unchecked Exceptions are checked at what?

22
New cards

ArithmeticException

Thrown when an exceptional ______ condition has occurred such as when dividing integers by zero.

23
New cards

IndexOutOfBoundsException

Thrown to indicate that an index of some sort is out of range.

24
New cards

ArrayIndexOutOfBoundsException

StringIndexOutOfBoundsException

2 subclasses of IndexOutOfBoundsException

25
New cards

IllgealArgumentException

Thrown to indicate that a method has been passed an illegal or inappropriate argument.

A subclass is NumberFormatException

26
New cards

NumberFormatException

Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.

27
New cards

NoSuchElementException

Thrown by various accessor methods to indicate that the element being requested does not exists.

A subclass is: InputMismatchException

28
New cards

InputMismatchException

Thrown by a scanner to indicate that the token retrieved does not match the pattern for the expected type.

29
New cards

NullPointerException

Thrown when an application attempts to use null in a case where an object is required, such as calling its method or accessing its fields.

30
New cards

ClassCastException

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.

31
New cards

IOException

Signals that I/O exception of some sort has occurred.

32
New cards

FileNotFoundException

Signals that an attempt to open the file denoted by a specified pathname has failed.

33
New cards

EOFException

Signals that an end of file or end of stream has been reached unexpectedly during input.

34
New cards

Assertion

is a language feature we use to detect logical errors in a program.

35
New cards

AssertionError

Where represents the value that passed an argument to the constructor of the __________ class.

36
New cards

PreCondition

PostCondition

Control Flow Invariant

3 Types of Assertions

37
New cards

Generics

parameterized types.

38
New cards

Object

The superclass of all other classes, and its reference can refer to any object.

They lack type safety as well.

39
New cards

<>

We use this keyword to specify parameter types in generic class creation.

40
New cards

T - Type

E - Element

K - Key

N - Number

V- Value

The common type paremeters are as follows:

41
New cards

Code Reusability, Type Safety, No Need For Type Casting,

Code Readability and Maintenance, Generic Algorithms

Advantages of Generics

42
New cards

Complexity, Performance Overhead, No Support for Primitive Types

Disadvantages of Generics

43
New cards

Parallel Programming

writing a program as a set of several tasks that can be executed simultaneously.

44
New cards

Thread

refers to a "____ of execution" or "____ of control", it is a sequence of instructions that are executed one after another.

45
New cards

True

True or False?

Every Java program has at least one thread.

46
New cards

Java Virtual Machine

controls this one thread as it runs the program, creating the thread that is responsible for executing the main routine of the program.

47
New cards

True

In a GUI program, there is at least one additional thread, which is responsible for handling events and drawing components on the screen.

48
New cards

True

This GUI thread is creating when the first window is opened.

49
New cards

Yes, when several threads are working together on a problem, a whole new category of errors is possible.

Is Parellel Programming difficult? If so, why?

50
New cards

extends Thread class, implementing Runnable interface

What are the two techniques for creating threads in a Java program?

51
New cards

run() method

defines the task that will be performed by the thread; that is when the thread is started, it is the method that will be executed in the thread.

52
New cards

start() method

The purpose of this method is to create a new thread of control that will execute the Thread object's run() method.

53
New cards

false

In a multi-threaded program, there is no fundamental indeterminacy. You can't be sure what order things will happen in.

54
New cards

False

Calling thread.run() will execute the run() method in the same thread, rather than creating a new thread.

55
New cards

New

Runnable

Blocked

Waiting

Timed Waiting

Terminated

The Six Possible States in the JVM. (Thread States)

56
New cards

New state

A thread is in this state when an object for the thread is created with the ___ command, but the thread has not yet started.

57
New cards

True

True or False?

Calling the start() method allocates memory for the new thread in the JVM and called the run() method for the thread object.

58
New cards

Runnable state

59
New cards

True

True or False?

Java does not distinguish between a thread that is eligible to run and a thread that is currently running. A running thread is still in this runnable state.

60
New cards

Blocked

A thread is in this state as it wats to acquire a lock - a tool used for thread synchronization.

61
New cards

Waiting

A thread in this state is waiting for an action by another thread.

62
New cards

Timed Waiting

This state is similar to waiting, except a thread specifies the maximum amount of time it will wait.

63
New cards

Timed Waiting

prevents a thread from remaining in the waiting state indefinitely.

64
New cards

Terminated

A thread moves to this state when its run() method terminates.

65
New cards

isAlive()

getState()

sleep(ms)

The Thread class includes several useful methods in addition to the start() method. (Give The 3 Methods)

66
New cards

True

True or False?

A thread is "alive" between the time it is started and the time when it terminates.

67
New cards

InterruptedException

The sleep method can throw what exception?

68
New cards

interrupt()

A thread can be interrupted with this method.

69
New cards

False

If a thread is already dead when thread.join() is called, then it simply still has an effect.

70
New cards

InterruptedException

The method join() can throw this exception which must be handled.

71
New cards

Race Condition

This occurs when one thread is in the middle of a multi-step operation, and another thread changes some value or condition that the first thread is depending upon.

72
New cards

Synchronized statement

To fix the problem of race conditions, this is the way for a thread to get exclusive access for a shared resource.

73
New cards

Mutual Exclusion

Synchronization in Java actually provides this, which means that exclusive access to resource is only guaranteed if every thread that needs access to that resources uses synchronization.

74
New cards

False

True or False?

In Java, mutual exclusion is not always associated with an object; we say that the synchronization is "on" that object.

75
New cards

Two threads cannot be synchronized on the same object at the same time.

The real rule of synchronization in Java.

76
New cards

Lock

Every object has this, and it can be "held" by only one thread at a time during synchronization.

77
New cards

True

It releases the lock after it finishes executing the synchronized code.

78
New cards

Deadlock

Synchronization can help to prevent race conditions, but it introduces the possibly of another type of error which is:

79
New cards

Deadlock

This occurs when a thread waits forever for a resource that it will never get.

80
New cards

Object class

Wait() and notify() methods are defined a instance methods in what class?

81
New cards

True

It is not an error to call notify() when no one is waiting; it just has no effect.

82
New cards

IllegalMonitorStateException

A thread can legally call obj.wait() or obj.notify() only if that thread holds the synchronization lock associated with the object obj. If it does not hold that lock,

83
New cards

True

Lock.wait() does not finish until lock.notify() is executed.

84
New cards

AWT

SWing

JavaFX

SWT

Examples of Java GUIs

85
New cards

Abstract Windowing Toolkit

What does AWT mean?

86
New cards

Standard Widget Toolkit

What does SWT mean?

87
New cards

JavaFX

A set of graphics and media packages that enables developers to design, create, test, debug and deploy rich client applications.

88
New cards

Cascading Style Sheets (CSS)

They separate appearance and style from implementation so that developers can concentrate on coding.

89
New cards

FXML scripting language

If you have a web design background, then you can develop the presentation aspects of the UI in where?

90
New cards

JavaFX Scene Builder

We can design UIs without writing code here.

91
New cards

Scene Graph

The starting point for constructing a JavaFX application. It is a hierarchical tree of nodes that represents all the visual elements of the application's user interface.

92
New cards

Nodes

In a Scene Graph, this must belong to a group or layout parent.

93
New cards

Stage

In GUI context, this extends window, handles UI-centric styling and behavior.

94
New cards

Scene

Holds all nodes in a Parent and direct events.

95
New cards

Node

A single element in a scene graph is called what?

96
New cards

Graphics System

It supports both 2-D and 3-D scene graphs.

97
New cards

Graphics System

Provides software rendering when the graphics hardware on a system is insufficient to support hardware accelerated rendering.

98
New cards

Prism

processes render jobs.

99
New cards

Quantum Toolkit

ties Prism and Glass Windowing Toolkit together and makes them available to the JavaFX layer above them in the stack.

It also manages the threading rules related to rendering versus events handling.

100
New cards

Glass Windowing Toolkit

The lowest level in the JavaFX graphics stack.

Its main responsibility is to provide native operating services, such as managing the windows, timers, and surfaces.