1/117
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Late-Binding
Another term for Polymorphism.
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?
Exception
represents an error condition that can occur during the normal course of the program execution.
InputMismatchException
an error that occurs when we try to convert a string that cannot be converted to a numerical value.
Try block
where we put the statements we want to be executed in response to the thrown exception.
Catch block
where we throw the exceptions / receives the exception.
Throwable Class
The exception is represented as an instance of which class?
Error and Exception
The Throwable class has 2 subclasses, what are they?
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.
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.
throw
the keyword to invoke an Exception
The system itself.
If no matching catch block is found, then who will handle the thrown exception?
Exception Thrower
calling a method that throws an exception.
Exception Catcher
is an exception thrower that includes a matching catch block for the thrown exception.
Exception Propagator
Passing exceptions.
IOError, VirtualMachineError, OutofMemoryError
What are the error subclasses?
IndexOutOfBoundsException
ArrayIndexOutofBoundsException
IllegalArgumentException
NumberFormatException
NoSuchElementException
NullPointerException
ClassCastException
Subclasses of RuntimeException
FileNotFoundException
EOFException
Subclasses of IOException
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
Compile Time
Checked Exceptions are checked at what?
Runtime
Unchecked Exceptions are checked at what?
ArithmeticException
Thrown when an exceptional ______ condition has occurred such as when dividing integers by zero.
IndexOutOfBoundsException
Thrown to indicate that an index of some sort is out of range.
ArrayIndexOutOfBoundsException
StringIndexOutOfBoundsException
2 subclasses of IndexOutOfBoundsException
IllgealArgumentException
Thrown to indicate that a method has been passed an illegal or inappropriate argument.
A subclass is NumberFormatException
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.
NoSuchElementException
Thrown by various accessor methods to indicate that the element being requested does not exists.
A subclass is: InputMismatchException
InputMismatchException
Thrown by a scanner to indicate that the token retrieved does not match the pattern for the expected type.
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.
ClassCastException
Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance.
IOException
Signals that I/O exception of some sort has occurred.
FileNotFoundException
Signals that an attempt to open the file denoted by a specified pathname has failed.
EOFException
Signals that an end of file or end of stream has been reached unexpectedly during input.
Assertion
is a language feature we use to detect logical errors in a program.
AssertionError
Where
PreCondition
PostCondition
Control Flow Invariant
3 Types of Assertions
Generics
parameterized types.
Object
The superclass of all other classes, and its reference can refer to any object.
They lack type safety as well.
<>
We use this keyword to specify parameter types in generic class creation.
T - Type
E - Element
K - Key
N - Number
V- Value
The common type paremeters are as follows:
Code Reusability, Type Safety, No Need For Type Casting,
Code Readability and Maintenance, Generic Algorithms
Advantages of Generics
Complexity, Performance Overhead, No Support for Primitive Types
Disadvantages of Generics
Parallel Programming
writing a program as a set of several tasks that can be executed simultaneously.
Thread
refers to a "____ of execution" or "____ of control", it is a sequence of instructions that are executed one after another.
True
True or False?
Every Java program has at least one thread.
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.
True
In a GUI program, there is at least one additional thread, which is responsible for handling events and drawing components on the screen.
True
This GUI thread is creating when the first window is opened.
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?
extends Thread class, implementing Runnable interface
What are the two techniques for creating threads in a Java program?
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.
start() method
The purpose of this method is to create a new thread of control that will execute the Thread object's run() method.
false
In a multi-threaded program, there is no fundamental indeterminacy. You can't be sure what order things will happen in.
False
Calling thread.run() will execute the run() method in the same thread, rather than creating a new thread.
New
Runnable
Blocked
Waiting
Timed Waiting
Terminated
The Six Possible States in the JVM. (Thread States)
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.
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.
Runnable state
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.
Blocked
A thread is in this state as it wats to acquire a lock - a tool used for thread synchronization.
Waiting
A thread in this state is waiting for an action by another thread.
Timed Waiting
This state is similar to waiting, except a thread specifies the maximum amount of time it will wait.
Timed Waiting
prevents a thread from remaining in the waiting state indefinitely.
Terminated
A thread moves to this state when its run() method terminates.
isAlive()
getState()
sleep(ms)
The Thread class includes several useful methods in addition to the start() method. (Give The 3 Methods)
True
True or False?
A thread is "alive" between the time it is started and the time when it terminates.
InterruptedException
The sleep method can throw what exception?
interrupt()
A thread can be interrupted with this method.
False
If a thread is already dead when thread.join() is called, then it simply still has an effect.
InterruptedException
The method join() can throw this exception which must be handled.
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.
Synchronized statement
To fix the problem of race conditions, this is the way for a thread to get exclusive access for a shared resource.
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.
False
True or False?
In Java, mutual exclusion is not always associated with an object; we say that the synchronization is "on" that object.
Two threads cannot be synchronized on the same object at the same time.
The real rule of synchronization in Java.
Lock
Every object has this, and it can be "held" by only one thread at a time during synchronization.
True
It releases the lock after it finishes executing the synchronized code.
Deadlock
Synchronization can help to prevent race conditions, but it introduces the possibly of another type of error which is:
Deadlock
This occurs when a thread waits forever for a resource that it will never get.
Object class
Wait() and notify() methods are defined a instance methods in what class?
True
It is not an error to call notify() when no one is waiting; it just has no effect.
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,
True
Lock.wait() does not finish until lock.notify() is executed.
AWT
SWing
JavaFX
SWT
Examples of Java GUIs
Abstract Windowing Toolkit
What does AWT mean?
Standard Widget Toolkit
What does SWT mean?
JavaFX
A set of graphics and media packages that enables developers to design, create, test, debug and deploy rich client applications.
Cascading Style Sheets (CSS)
They separate appearance and style from implementation so that developers can concentrate on coding.
FXML scripting language
If you have a web design background, then you can develop the presentation aspects of the UI in where?
JavaFX Scene Builder
We can design UIs without writing code here.
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.
Nodes
In a Scene Graph, this must belong to a group or layout parent.
Stage
In GUI context, this extends window, handles UI-centric styling and behavior.
Scene
Holds all nodes in a Parent and direct events.
Node
A single element in a scene graph is called what?
Graphics System
It supports both 2-D and 3-D scene graphs.
Graphics System
Provides software rendering when the graphics hardware on a system is insufficient to support hardware accelerated rendering.
Prism
processes render jobs.
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.
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.