Web Design and Development MCQs with Answers
Practice important Web Design and Development MCQs with answers and explanations.
Chapter: 22
Q341:
What is the purpose of the Serializable interface in Java?
A. To define methods for object serialization
B. To indicate that a class can be serialized
C. To handle object input and output streams
D. To perform encryption on object data
Correct Answer:
B
Chapter: 22
Q342:
Which Java class is used to write objects to a file?
A. FileInputStream
B. FileOutputStream
C. ObjectInputStream
D. ObjectOutputStream
Correct Answer:
D
Chapter: 22
Q343:
What method is used to read an object from a file in Java serialization?
A. readObject()
B. writeObject()
C. readFile()
D. writeFile()
Correct Answer:
A
Chapter: 22
Q344:
In the provided WriteEx example, what is the name of the file where the PersonInfo object is serialized?
A. person.dat
B. ali.dat
C. object.dat
D. file.dat
Correct Answer:
B
Chapter: 22
Q345:
What keyword is used to prevent a field from being serialized?
A. static
B. transient
C. volatile
D. final
Correct Answer:
B
Chapter: 22
Q346:
How does the ClientWriteNetEx class send an object over a network?
A. Using FileOutputStream
B. Using Socket and ObjectOutputStream
C. Using DataOutputStream
D. Using PrintWriter
Correct Answer:
B
Chapter: 22
Q347:
What must be done when reading a serialized object from a stream?
A. Cast the object to the correct type
B. Decrypt the object
C. Convert the object to a string
D. Compress the object
Correct Answer:
A
Chapter: 22
Q348:
How does the ServerReadNetEx class handle incoming connections?
A. By creating a new Socket for each connection
B. By using ServerSocket to accept connections
C. By using ObjectOutputStream to receive objects
D. By handling FileInputStream
Correct Answer:
B
Chapter: 23
Q349:
What is the role of transient keyword in Java serialization?
A. To mark fields that are not part of the object’s state
B. To encrypt the fields during serialization
C. To ensure fields are serialized in binary format
D. To define methods for serialization
Correct Answer:
A
Chapter: 23
Q350:
What method is used to write an object to a network stream?
A. writeObject()
B. sendObject()
C. writeStream()
D. sendStream()
Correct Answer:
A
Chapter: 23
Q351:
In PersonInfo class, which field is marked transient to prevent serialization?
A. name
B. address
C. phoneNum
D. age
Correct Answer:
C
Chapter: 23
Q352:
What is the main benefit of multithreading in an application?
A. Increased execution speed
B. Reduced memory usage
C. Concurrent execution
D. Simplified code
Correct Answer:
C
Chapter: 23
Q353:
What does a thread in Java refer to?
A. A lightweight process
B. A heavy process
C. A type of exception
D. A network protocol
Correct Answer:
A
Chapter: 23
Q354:
Which method is used to start a thread in Java?
A. run()
B. start()
C. execute()
D. begin()
Correct Answer:
B
Chapter: 23
Q355:
What is the default priority of a thread in Java?
A. 1
B. 5
C. 10
Correct Answer:
B
Chapter: 23
Q356:
In Java, which interface must be implemented to create a thread using the interface approach?
A. Thread
B. Runnable
C. Callable
D. Executor
Correct Answer:
B
Chapter: 23
Q357:
How do you change the priority of a thread in Java?
A. setPriority()
B. changePriority()
C. updatePriority()
D. adjustPriority()
Correct Answer:
A
Chapter: 23
Q358:
What does the run() method in a Runnable implementation contain?
A. Thread creation code
B. Code to be executed by the thread
C. Code to start the thread
D. Code to stop the thread
Correct Answer:
B
Chapter: 23
Q359:
How many threads are created in the given example with the Runnable approach in ThreadTest.java?
A. One
B. Two
C. Three
D. Four
Correct Answer:
C
Chapter: 23
Q360:
In the provided code examples, which class is used to implement the thread behavior directly?
A. Worker
B. Runnable
C. Thread
D. Executor
Correct Answer:
C