Java Flashcards

1
Q

Diagram of the exception hierarchy

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

What are the 3 categories for exceptions and errors

A

CUE

  • Checked Exceptions - Checked at compile time.
  • Unchecked Exceptions - Usually programmer error. RuntimeException and subclasses.
  • Errors - Not checked at compile time, but can be caught. E.g., AssertionError, ExceptionInInitializeError, OutOfMemoryError
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a required when you create a try block?

A

A try block must have at least one catch or finally block

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

Describe the 4 different access modifiers

A
  • public
  • protected - subclass and package
  • *default (package) - *package only
  • private
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the two ways to create a thread?

A

Either by extending java.lang.Thread or by implementing java.lang.Runnable

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

How do you create a thread using java.util.Thread

A
class Comet extends Thread {
    public void run( ) {
      System.out.println("Orbiting");
      orbit( );
    }
 }

Comet halley = new Comet( );

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

How an example of implementing the Runnable interface

A
class Asteroid implements Runnable {
    public void run( ) {
      System.out.println("Orbiting");
      orbit( );
    }
 }
Asteroid maja = new Asteroid( );
 Thread majaThread = new Thread(maja);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Name the 6 thread states

A

NEW - A thread that is created but not started

RUNNABLE - A thread that is available to run

BLOCKED - An “alive” thread that is blocked waiting for a monitor lock

WAITING - An “alive” thread that calls its own wait( ) or join( ) while waiting on another thread

TIMED_WAITING - An “alive” thread that is waiting on another thread for a specified period of time; sleeping

TERMINATED - A thread that has completed

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

Describe thread priorities

A

The valid range of priority values is typically 1 through 10, with a default value of 5.

Lower priority threads yield to higher priority threads.

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