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: 1Which of the following is the most important feature that makes Java suitable for Internet applications?
Option C
Java is widely used for Internet and web-based applications because of several important features. One of the key requirements for Internet applications is that programs must run on different platforms without modification and support networked or distributed computing.
Java fulfills these requirements through its Portability, meaning compiled Java bytecode can run on any system with a Java Virtual Machine (JVM), and its ability to work in a Distributed environment, allowing objects and programs to communicate over networks.
Q: 2What is the main role of Java Development Kit (JDK)?
Option D
The Java Development Kit (JDK) is a software development kit provided by Java to help programmers develop Java applications. It contains tools for writing, compiling, and running Java programs.
The JDK includes the Java Compiler (javac) to convert source code into bytecode, the Java Runtime Environment (JRE) to execute Java programs, and other development tools such as debuggers and documentation generators.
Q: 3Which of the following is a commonly used Object-Oriented Programming Language?
Option C
Java is a widely used Object-Oriented Programming (OOP) language that supports core OOP principles such as classes, objects, inheritance, polymorphism, abstraction, and encapsulation.
Q: 4Which of the following statement is true about public and private members in Java?
Option D
In Java, access modifiers determine the visibility of class members. The two commonly used modifiers are public and private.
Private members are accessible only within the same class in which they are declared, they cannot be accessed from subclasses or other classes.
Public members are accessible from any other class, regardless of the package or subclass relationship.
MEMBER ACCESS RULE TABLE:
| ACCESS MODIFIER → ACCESS LOCATION ↓ | PUBLIC | PROTECTED | DEFAULT | PRIVATE |
|---|---|---|---|---|
| Same class. | Yes | Yes | Yes | Yes |
| Subclass in same package. | Yes | Yes | Yes | No |
| Other classes in same package. | Yes | Yes | Yes | No |
| Subclass in others package. | Yes | Yes | No | No |
| Non-subclasses in others package. | Yes | No | No | No |
Q: 5Which one of the following is true for Virtual Machine like JVM?
Option A
While Java as a language is platform-independent, the Java Virtual Machine (JVM) itself is hardware and platform dependent.
Every operating system (Windows, Linux, MacOS) and hardware architecture (x86, ARM) requires its own specific implementation of the JVM to bridge the gap between Java's bytecode and the host's native environment.
Q: 6Consider the following Java program
class Test
{
public static void main(String args[])
{
public int x=3;
protected int y=6;
private int z=9;
System.out.println(x+y+z);
}
}
What will be result of attempting to compile and run the program?
Option C
In Java, access modifiers like public, protected, and private cannot be used for local variables inside a method. These modifiers are only allowed for class-level variables (instance or static variables), not inside the main() method.
Q: 7What output is produced for the command: “java cmd a b c d”, when following code is run?
class cmd {
public static void main(String args[]) {
System.out.println(args[2]);
}
}
Option A
Command Line Argument are parameters that are supplied to the application program at the time of invoking it for execution. We can customize the behavior of the main() method using command-line arguments.
When command line arguments are supplied to JVM, JVM wraps these and supply to args[ ]. It can be confirmed that they are actually wrapped up in args array by checking the length of args using args.length.
For the command java cmd a b c d the arguments are assigned as follows:
The statement System.out.println(args[2]); will print the value stored at index 2, which is "c".
Q: 8Which command is used to convert the code written in Java to bytecode?
Option D
Compilation : Converting the Java source code (.java file) into bytecode (.class file) that can run on the Java Virtual Machine (JVM). The javac command is used to compile Java source code into bytecode.
javac FirstExample.java
Execution : Running the bytecode on the JVM. The java command is used to run the bytecode on the JVM.
java FirstExample
| COMMAND | USED FOR |
|---|---|
| javac | Compiles Java source code (.java) into bytecode (.class). |
| java | Runs the compiled Java bytecode on the Java Virtual Machine (JVM). |
| javadoc | Generates HTML documentation from Java source code comments. |
| javap | Disassembles bytecode (.class file) to view class structure, methods, and fields. |
| jar | Creates, views, or extracts Java Archive (.jar) files. |
| jdb | Java debugger. Used to debug Java programs. |
| jconsole | Java monitoring and management console for running Java applications. |
| jshell | Java REPL (Read-Eval-Print Loop) for running snippets of Java code interactively. |
Q: 9Which component of Java platform is responsible for converting bytecode into machine-specific code?
Option D
Java is a platform-independent programming language, which means Java programs can run on any operating system without modification. This is possible because Java does not compile code directly into machine-specific instructions.
Instead, Java source code (.java files) is first compiled by the Java Compiler into an intermediate form called bytecode (.class files). Bytecode is platform-independent and cannot be executed directly by the operating system. To run a Java program, the Java Virtual Machine (JVM) is used.
The JVM is a part of the Java Runtime Environment (JRE), and it is responsible for interpreting or converting the bytecode into machine-specific code that the operating system can execute.
Q: 10What is bytecode in Java?
Option C
In Java, when you compile a .java file using the javac compiler, it does not directly generate machine code. Instead, it produces an intermediate code known as bytecode, stored in .class files.
This bytecode is platform-independent, meaning it can run on any device that has the Java Virtual Machine (JVM). The JVM then converts this bytecode into machine-specific instructions depending on the operating system and hardware. This is the main reason Java is called Write Once, Run Anywhere (WORA).
| TYPE OF CODE | DESCRIPTION |
|---|---|
| Source Code | Human-readable, high-level program written by the developer using programming languages like Java, C, C++, Java, Python. It contains logic, statements, and comments. It cannot be executed directly by the computer and must be compiled or interpreted. |
| Bytecode | Intermediate, platform-independent code generated by the Java compiler. It is stored in .class files. Bytecode is not machine code, but it can run on any system that has a Java Virtual Machine (JVM), which converts bytecode into machine code at runtime. |
| Object Code | Low-level code produced by a compiler. It contains machine instructions plus unresolved references, placeholders, and symbol tables. Object code is not executable on its own and must be linked with other object files and libraries.
|
| Machine Code | The final binary instruction set understood directly by the CPU. Produced after linking all object files. It contains fully resolved addresses and ready-to-execute commands. Represented in 0s and 1s.
|
| Executable Code | The complete, linked, and ready-to-run program created by combining machine code, libraries, and metadata. This is the file that users can double-click or run from the terminal. It loads directly into memory and executes on the operating system.
|
Q: 11Which of the following is NOT an advantage of Java bytecode?
Option D
Java programs are compiled into bytecode, which is an intermediate, platform-independent code. This bytecode is executed by the Java Virtual Machine (JVM), which interprets [Just-In-Time (JIT)] compiles it for the underlying hardware. The advantages of Java bytecode include:
However, bytecode is generally slower than native machine code because it must be interpreted or compiled at runtime.
Q: 12Which of the following is not an access modifier in Java language?
Option D
In Java, access modifiers are keywords used to define the visibility and accessibility of classes, methods, and variables. They control which parts of a program can access a particular class member. Java provides four main access levels, public, private, protected, and the default (no modifier).
The public modifier allows access from anywhere, private restricts access to within the same class, and protected allows access within the same package and subclasses.
Q: 13Which of the following is a function of the Java Virtual Machine?
Option B
The Java Virtual Machine (JVM) is responsible for running compiled Java programs, but it does not compile the source code itself. The compilation of .java files into .class bytecode is done by the Java compiler (javac), not by the JVM.
Once Java bytecode exists, the JVM mainly performs three related class‑handling steps, Loading, Linking, and Initialization.
Loading: The JVM loads class files (bytecode) into memory by reading them from the file system, network, or other sources.
Linking: The loaded class is linked with already‑loaded classes (symbolic references are resolved, verification may happen).
Initialization: Static variables are set to their initial values and static blocks are executed.
Therefore, among the given options, Loading is the most appropriate single answer.
Q: 14______________ is a standard machine language into which Java source is compiled.
Option C
In Java programming, the Java source code (.java) is first compiled by the Java Compiler into Byte Code (.class). Byte Code is a standardized machine-independent code that can be executed on any platform using the Java Virtual Machine (JVM).
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.