IO / Serialization Flashcards

1
Q

How do you serialize an object in Java?

A

Serialization is a mechanism of converting the state of an object into a byte stream.

To make a Java object serializable we implement the java.io.Serializable interface.
The ObjectOutputStream class contains writeObject() method for serializing an Object.

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

How deserialize an object in Java?

A

Deserialization is the reverse process where the byte stream is used to recreate the actual Java object in memory.

The ObjectInputStream class contains readObject() method for deserializing an object.

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

What does Serializable interface do?

A

It is used to “mark” Java classes so that the objects of these classes may get a certain capability.

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

What is a Marker interface?

A

A marker interface is an interface that has no methods or constants inside it. It provides run-time type information about objects, so the compiler and JVM have additional information about the object.

also called a tagging interface.

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

What are transient variables?

A

A transient variable is a special type of variable which we create by using the transient keyword. It is a special type of variable which have a non-serialized value at the time of serialization.

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

What is a FileReader

A

The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user’s computer, using File or Blob objects to specify the file or data to read.

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

What is a BufferedReader?

A

Java BufferedReader is a public Java class that reads text, using buffering to enable large reads at a time for efficiency, storing what is not needed immediately in memory for later use.

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

Explain the try-with-resources syntax

A

The try -with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try -with-resources statement ensures that each resource is closed at the end of the statement.

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

List some methods in the Scanner class

A

This class is used to obtain input from the user during runtime

Methods List:
next()
nextInt()
nextFloat()
nextBoolean()
nextLine()

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