Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Serialization and File Handling

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is Java serialization?

a)

It is the process of converting an object into a string of characters

b)

It is the process of converting an object into a stream of bytes

c)

It is the process of converting an object into a stream of integers

d)

It is the process of converting a stream of bytes into an object

2.

How is Java serialization achieved?

a)

By using the java.io.Serialization class

b)

By calling the serialize() method

c)

By implementing the java.io.Serializable interface

d)

By setting the serialization flag to true

3.

What is the purpose of using Fileinputstream in Java?

a)

To delete a file

b)

To create a new file

c)

To read data from a file

d)

To write data to a file

4.

How do you create a Fileinputstream object in Java?

a)

FileInputStream input = new FileInputStream(file.txt);

b)

FileInputStream input = new FileInputStream(file);

c)

FileInputStream input = new FileInputStream("file.txt");

d)

FileInputStream input = new FileInputStream();

5.

What is the purpose of using Fileoutputstream in Java?

a)

To create a new file

b)

To write data to a file

c)

To read data from a file

d)

To delete a file

6.

How do you create a Fileoutputstream object in Java?

a)

FileOutputStream.open("filename.txt")

b)

FileOutputStream.write("filename.txt")

c)

FileOutputStream.create("filename.txt")

d)

new FileOutputStream("filename.txt")

7.

How do you create a new file using the File class in Java?

a)

file.addNewFile()

b)

file.createFile()

c)

file.makeNewFile()

d)

file.createNewFile()

8.

What is the difference between FileWriter and Fileoutputstream in Java?

a)

FileWriter is used to read bytes from a file, while FileOutputStream is used to write characters to a file.

b)

FileWriter and FileOutputStream are not related to file handling in Java.

c)

FileWriter is used to write characters to a file, while FileOutputStream is used to write bytes to a file.

d)

FileWriter and FileOutputStream are used interchangeably in Java.

9.

How do you read data from a file using Fileinputstream in Java?

a)

Create a FileInputStream object and use its read() method to read the data from the file.

b)

Open the file in a text editor and manually copy the data

c)

Use a PrintWriter object to read the data from the file

d)

Use a Scanner object to read the data from the file

10.

How do you write data to a file using Fileoutputstream in Java?

a)

Use BufferedWriter to write data to the file

b)

Use PrintWriter to write data to the file

c)

Create an instance of FileOutputStream and use its write() method to write data to the file.

d)

Use FileReader to write data to the file

11.

What is the significance of using serialization in Java?

a)

It allows objects to be converted into a string for storage

b)

It helps in sorting arrays in Java

c)

It is used for creating random numbers in Java

d)

It allows objects to be converted into a byte stream for storage or transmission

12.

What are the advantages of using Fileinputstream and Fileoutputstream in Java?

a)

They are not compatible with Java serialization

b)

They provide high-level access to the file system, making file handling more complicated

c)

They provide low-level access to the file system, allowing for efficient and flexible file handling.

d)

They are slower and less efficient than other file handling methods

13.

How do you handle exceptions while working with Fileinputstream and Fileoutputstream in Java?

a)

Use try-catch blocks to catch and handle IOException

b)

Use if-else statements to handle IOException

c)

Throw a new custom exception instead of catching IOException

d)

Ignore the exception and continue with the program

14.

What are the different modes of opening a file using Fileoutputstream in Java?

a)

Delete mode

b)

1. Create mode 2. Append mode

c)

Update mode

d)

Read mode

15.

How do you serialize and deserialize an object in Java?

a)

Use the Serializable class to write the object to a database

b)

Use ObjectOutputStream to write the object to a network socket

c)

Use ObjectOutput to write the object to a text file

d)

Implement the Serializable interface and use ObjectOutputStream to write the object to a file, then use ObjectInputStream to read the object from the file.