Introduction to I/O and Networking Flashcards

1
Q

Exception

A

An exception is an object of type Exception

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

Checked exceptions

A

Compiler-checked exceptions. All other exceptions besides RuntimeException must be check

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

“finally” keyword

A

Where you put code that must run regardless of an exception

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

If the try block fails (an exception)

A

Flow control immediately moves to the catch block. When the catch block completes, the finally block runs, When the finally block completes, the rest of the method continues on

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

If the try block succeeds (No exception)

A

Flow control skips over the catch block and moves to the finally block. When the finally block completes, the rest of the method continues on

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

If the try or catch block has a return statement, finally will still run

A

Flow jumps to the finally, then back to the return

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

A method can throw more than one exception?

A

Yes, if it darn well needs to. But a method’s declaration must declare all the checked exceptions it can throw

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

Exception are polymorphic

A

Exceptions are objects. The benefit for exceptions is that a method doesn’t have to explicitly declare every possible exception it might throw

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

Exception rules

A
  1. You cannot have a catch or finally without a try
  2. A try must be followed by either a catch or a finally
  3. You cannot put code between the try and the catch
  4. A try with only a finally (no catch) must still declare the except
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Serialization

A

Write a file that holds flattened objects. Then have your program read the serialized objects from the file and inflate them back into living, breathing, heap-inhabiting objects

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

The mother of all catch argument is type Exception

A

It will catch any exception, including runtime exceptions, so you probably won’t use it outside of testing

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

Fundamental I/O tehcnique

A
  1. Write some data to something

2. Read some data from either a file on disk or a network connection

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

Connection

A

Streams represent a connection to a source or destination (file, socket) while chain streams can’t connect on their own and must be chained to a connection stream

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

Serialization saves the entire object graph

A

All objects referenced by instance variables, starting with the object being serialized

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

Serializable interface

A

Known as a marker or tag interface, because the interface doesn’t have any methods to implement

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

Transient

A

If an instance variable can’t be saved

17
Q

Deserialization

A

To restore it back to its original state at some later date, in a different ‘run’ of the JVM

18
Q

Are static variables serialized?

A

No. Static means “one per class” not “one per object”. Static variables are not saved, and when an object is deserialized, it will have whatever static variable its class currently has.

19
Q

java.io.File

A

represents a file on disk, but doesn’t actually represent the contents of the file

20
Q

File object

A

represents the name and path of a file or directory on disk. But it does NOT represent, or give you access to, the data in the file

21
Q

The difference between with bufferedWriter and without bufferedWriter

A

BufferedWriter hold all the stuff you write to it until it’s full. Without BufferedWriter, we would have to write each and everything we pass to the file each and every time

22
Q

How many can one method throw?

A

Multiple exceptions if it needs to

23
Q

What is the mother of all catch arguments?

A

Exception; it will catch any exception, including runtime (unchecked) exceptions, so you probably won’t use it outside of testing

24
Q

Why can’t you put bigger exceptions on top of smaller exception?

A

The compiler knowns there’s no point in adding any other exceptions

25
Q

MidEvent

A

An instruction for part of a song. It says what to do and when to do it.

26
Q

A try block must be followed by a catch and a finally block

A

False, either or both

27
Q

If you write a method that might cause a compiler-checked exception, you must wrap that risky code in a try / catch block

A

False, you can declare the exception

28
Q

Catch blocks can be polymorphic

A

True, because it’s impossible to identify all the exceptions

29
Q

Only ‘compiler checked’ exceptions can be caught

A

False, runtime exception can be caught

30
Q

If you define a try/catch block, a matching finally block is optional

A

True

31
Q

If you define a try block, you can pair it with a matching catch or finally block, or both

A

True, both are acceptable

32
Q

If you write a method that declares that it can throw a compiler-checked exception, you must also wrap the exception throwing code in a try/catch block

A

False, the declaration is sufficient

33
Q

The main method in your program must handle all unhandled exceptions thrown to it

A

False, but if it doesn’t the JVM may shut down

34
Q

Handling an exception is sometimes referred to as ‘ducking’

A

False, ducking is synonymous with declaring

35
Q

A method with a try block and a finally block, can optionally declare the exception

A

False, if you don’t have a catch block, you must declare