131-140 Flashcards

1
Q

What is the difference between error and exception?

A

An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory error. The cause the application to come to a halt.

Exceptions are conditions that occur because of a bad input or human error. E.g. FileNotFoundException. In most cases it is possible to recover from an exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you handle Java exceptions?

A

Keywords are:
try
catch
finally
throw
throws

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the differences between a checked and unchecked exception?

A

Checked exception:
- The classes that extend Throwable class except for RuntimeException
- They are checked at compile time

Unchecked Exception:
- The classes that extend RuntimeException
- They are not checked at compile time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does an exception propagate in the code?

A

If an exception is not caught, it is thrown from the top of the stack and falls down the call stack to the previous procedure, and so on until it is caught or the call stack reaches the bottom. This is known as Exception propagation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you create a custom exception?

A

To create a new exception you extend the exception class or any of its subclasses.
E.g.
checked Exception -> class New1Exception extends Exception {}
unchecked Exception -> class New2Exception extends NullPointerException {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Can we write multiple catch blocks under a single try clock?

A

Yes we can, but the approach should be from specific to general

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the differences between processes and threads?

A

Process - An executing instance of a program
Thread - A subset of the process

Process - must use inter-process communication to communicate with sibling processes
Thread - can communicate with any thread within its process

Process - can only exercise control over child processes
Thread - can exercise considerable control over other threads

Process - Run in separate memory spaces
Thread - Run in shared memory space

Process - Are controlled by the operating system
Thread - Are controlled by a programmer in a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly