This section contains carefully selected MCQs and Previous Year Questions with explanations to help students understand concepts and prepare effectively for examinations, interviews, and competitive tests.
Q: 1In Java, which one of the following is used to perform clean up processing just before garbage collection?
Option B
In Java, Garbage Collection is the process that automatically reclaims memory used by objects that are no longer reachable. Before actually freeing the memory of an object, the Java runtime may give the object a chance to clean up resources such as files, network connections, or database handles.
This cleanup is done by a special method, the finalize() method, which is defined in the Object class. When an object becomes eligible for garbage collection, the garbage collector calls finalize() on that object so it can perform cleanup just before being destroyed.
Q: 2What is the role of content Providers in Android?
Option C
In Android, Content Providers are mainly used to share data between applications in a secure and structured way. They provide a standard interface for accessing and managing data like contacts, images, videos, etc., and apps can query or modify this data using URIs.
Q: 3A class which cannot be inherited is called?
Option D
In Object-Oriented Programming (Java), a final class is a class that cannot be extended or inherited by any other class.
When a class is declared using the keyword final, it prevents other classes from inheriting it.
final class A
{
void displayMessage()
{
System.out.println("Suraku Academy");
}
}
class B extends A { } //Error.
Q: 4Which protocol does RMI use to communicate between objects distributed across a network?
Option B
In Java, RMI (Remote Method Invocation) is a technology that allows an object running in one Java virtual machine (JVM) to invoke methods on an object located in another JVM, possibly on a different machine over a network.
To enable this communication, RMI relies on a network protocol that provides reliable, ordered, and error-checked delivery of data between applications.
The protocol used for this purpose is TCP/IP (Transmission Control Protocol / Internet Protocol), which is a standard suite of communication protocols used for transmitting data over networks, including the Internet.
Q: 5What is the primary purpose of using Intents in Android?
Option C
In Android, Intents are used as a messaging object that allows communication between different components of an app such as Activities, Services, and Broadcast Receivers, or even between different apps.
Intents can be used to start a new activity, launch a service, deliver a broadcast, or request an action like opening a web page or sharing content.
Q: 6Which of the following streams is used to deserialize the primitive data and objects in Java?
Option D
In Java, streams are used to handle input and output of data. The core concept here is serialization and deserialization:
Serialization: Converting an object into a byte stream so it can be saved to a file or sent over a network.
Deserialization: Reconstructing the object from the byte stream back into a Java object.
To handle deserialization of primitive data types and objects, Java provides the ObjectInputStream class.
Q: 7What is the correct way to close a file in Java after writing to it?
Option C
The correct way to close a file in Java after writing to it is to use the close() method of the FileWriter class. This method is called on the FileWriter object after all writing operations are complete.
Closing the file writer releases any system resources associated with it, flushes buffers, and ensures that data is properly saved to the file. For example, fileWriter.close(); is the standard way to close the file after writing.
Q: 8Which of the following class in Java is responsible for handling files in Java?
Option C
In Java, the File class (java.io package) is responsible for handling operations related to files and directories. It allows you to create files, check whether a file exists, delete files, get file information (size, name, path), and work with folders as well.
Although File does not directly read or write data, it plays the key role in managing and accessing files. For reading or writing content, Java uses other classes like FileInputStream, FileOutputStream, FileReader, and FileWriter.
You have reached the end of this topic. Continue learning with the next topic below.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.