C Programming Multiple Choice Questions (MCQ) | IT Developer <?php echo $page_title; ?>
IT Developer

Java Programming Multiple Choice Questions (MCQ)

Introduction to Java - Multiple Choice Questions (MCQ) - Set 4



Share with a Friend

Multiple Choice Questions


Java - Introduction to Java - Multiple Choice Questions (MCQ) - Set 4

16. JVM is part of:
A). JDK
B). JRE
C). Both
D). None
View Answer
Correct: C

 

Explanation

The correct answer is C). Both

  • JVM (Java Virtual Machine)is the core engine that executes Java bytecode.
  • JRE (Java Runtime Environment)is a package that includes the JVM and class libraries, allowing Java applications to run.
  • JDK (Java Development Kit)is a full-featured software development kit that includes the JRE (and thus the JVM), along with tools like the compiler (javac) and debuggers. 

Therefore, the JVM is a component within the JRE, and because the JRE is included in the JDK, the JVM is part of both. 


Hierarchical View:


JDK > JRE > JVM 

 

 



17. Which tool compiles Java code?
A). javac
B). java
C). jvm
D). jre
View Answer
Correct: A

 

Explanation

The tool that compiles Java code is A). javac


Summary of Java Tools:


A. javac (Java Compiler):The primary tool used to read Java source files (.java) and compile them into platform-independent bytecode (.class files).

B. java (Java Launcher):The tool used to launch and run Java applications by starting a Java Virtual Machine.

C. JVM (Java Virtual Machine):The abstract engine that executes Java bytecode on a specific hardware platform.

D. JRE (Java Runtime Environment):A software bundle that provides the libraries and JVM needed to run Java programs, but does not include development tools like a compiler.





18. Which command runs Java program?
A). javac
B). java
C). run
D). compile
View Answer
Correct: B

 

Explanation

The correct command to run a Java program is B). java

In the Java development process, there are two distinct steps involving different commands:

  • Compilation:The javac command (Java Compiler) is used to translate source code (.java files) into bytecode (.class files).
  • Execution:The java command (Java Launcher) starts the Java Virtual Machine (JVM), loads the compiled .class file, and runs the program.

 

Example of the process:

  1. Compile:javac HelloWorld.java (creates class).
  2. Run:java HelloWorld (executes the program)

 

 




19. Java supports multithreading?
A). Yes
B). No
View Answer
Correct: A

 

Explanation

A). Yes

Java supports multithreading natively, allowing a program to run multiple threads simultaneously to execute tasks in parallel and utilize CPU resources more efficiently. This support is built into the language through the Thread class and the Runnable interface, allowing developers to create independent paths of execution that share the same memory space.

 

Key Aspects of Multithreading in Java:

  • Built-in Support:Java provides built-in mechanisms for creating, managing, and synchronizing threads, such as synchronized blocks, wait(), and notify().
  • Two Primary Ways to Create Threads:Extending the Thread class or implementing the Runnable
  • Concurrency Utilities:The util.concurrent package provides advanced tools like ExecutorService for managing thread pools, which are preferred for creating scalable applications.
  • Parallelism:On multi-core processors, Java threads can run in true parallel, improving application performance.

 



20. Which is not part of JDK?
A). Compiler
B). JVM
C). JRE
D). Browser
View Answer
Correct: D




Explanation

 

The correct answer is D). Browser.

Here is the breakdown of why:

  • JDK (Java Development Kit) is a comprehensive software development kit used for creating Java applications.
  • JDK includes JRE (C), which in turn includes the JVM (B).
  • Compiler (A), specifically javac, is a key tool included in the JDK to turn source code into bytecode.
  • Browser (D) is not part of the JDK. While browsers used to run Java applets using a browser plugin, that plugin was separate from the JDK and has been deprecated/removed in modern versions.