CCNA What is Java Questions

41 questions · What is Java · All types, answers revealed

1
Matchingmedium

Match each OOP concept to its Java implementation.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Using private fields with public getters/setters

Using extends keyword to derive a class

Method overriding and overloading

Using abstract classes and interfaces

Using fields that reference other objects

Why these pairings

OOP principles are implemented in Java via specific constructs.

2
MCQmedium

A developer is tasked with deploying a Java application to a customer's server. The customer has only a JRE installed and no internet access. The application uses Java NIO and requires reading configuration files from the classpath. The application compiles and runs fine on the developer's machine which has JDK 11. However, when deploying the compiled JAR to the customer's JRE 11, it throws a 'NoClassDefFoundError' for a class that is part of the JDK's internal API (e.g., com.sun.nio.file.SensitivityWatchEventModifier). The developer is confused because the class is in the standard library. Which action should be taken to resolve the issue?

A.Recompile with a lower target version
B.Add the missing JAR file to the classpath
C.Modify the code to use a public API from the standard library
D.Install the JDK on the customer's server
AnswerC

Internal APIs are not accessible; use public alternatives.

Why this answer

Option A is correct. The issue is that the code uses an internal API that is encapsulated in Java 11. The correct solution is to replace it with a public API (e.g., using java.nio.file.StandardWatchEventKinds).

Option B is incorrect because installing the JDK would expose the internal classes but is not a proper solution and may violate encapsulation. Option C is incorrect because the missing class is not a separate JAR; it's part of the JDK internal API. Option D is incorrect because recompiling with a lower target version does not change the use of internal APIs and may introduce other issues.

3
MCQhard

A large enterprise application is experiencing intermittent crashes on a production server running Java 8. The crash logs show 'java.lang.OutOfMemoryError: Metaspace'. The application heavily uses frameworks like Hibernate and JasperReports, which generate many classes dynamically at runtime. The server is configured with default JVM options except for -Xmx2g. A junior administrator suggests increasing -Xmx to 4g. What is the most effective solution to prevent these crashes?

A.Enable -XX:+UseCompressedOops
B.Increase -Xmx to 4g
C.Switch to -XX:+UseParallelGC
D.Set -XX:MaxMetaspaceSize to a higher value
AnswerD

Directly increases the limit for class metadata storage.

Why this answer

Option B is correct. Metaspace is used for class metadata; dynamic class generation fills metaspace. The default MaxMetaspaceSize is unlimited but can be constrained by available native memory.

Increasing MaxMetaspaceSize (or leaving it unlimited) is the direct fix. Option A is incorrect because -Xmx increases heap, not metaspace. Option C is incorrect because UseCompressedOops optimizes heap memory, not metaspace.

Option D is incorrect because switching GC may not address the metaspace exhaustion.

4
MCQmedium

Given the javap output of a class file, which statement is correct about the Java version used to compile it?

A.Compiled with Java 11
B.Compiled with Java 8
C.This is a normal class file but does not indicate a specific Java version
D.Compiled with Java 9
AnswerA

Major version 55 indicates Java 11.

Why this answer

Option B is correct. Major version 55 corresponds to Java 11 (J2SE 11). Option A is wrong because Java 9 uses major version 53.

Option C is wrong because Java 8 uses major version 52. Option D is wrong because the output shows specific version info; it is not a normal class file but with known version.

5
MCQhard

In the Java memory model, where are primitive local variables declared inside a method stored?

A.Heap
B.Native method area
C.Stack
D.Method area
AnswerC

Local variables, including primitives, live on the stack.

Why this answer

Option D is correct because primitive local variables are stored on the stack. Option A (heap) stores objects and arrays. Option B (method area) stores class metadata.

Option C (native area) is for native method memory.

6
MCQeasy

A company wants to develop a Java application that can run on Windows, Linux, and macOS without any code changes. Which Java feature makes this possible?

A.Multithreading
B.Platform Independence via JVM
C.Garbage Collection
D.Object-Oriented Programming
AnswerB

The JVM allows bytecode to run on any device with a compatible JVM.

Why this answer

Option B is correct because Java achieves platform independence through the Java Virtual Machine (JVM), which interprets compiled bytecode. Option A is wrong because garbage collection manages memory but does not enable platform independence. Option C is wrong because object-oriented programming is a paradigm, not responsible for cross-platform execution.

Option D is wrong because multithreading is a concurrency feature, not a platform independence mechanism.

7
MCQmedium

What is the most likely cause of this error?

A.There is a memory leak in native code outside the heap.
B.The heap size is insufficient for the objects being created.
C.There is a stack overflow in the method being called.
D.Too many threads are running concurrently.
AnswerB

Heap space error occurs when object allocations exceed heap capacity.

Why this answer

Option B is correct because OutOfMemoryError: Java heap space indicates the heap is full. Option A (too many threads) would cause a different error (e.g., unable to create new native thread). Option C (stack overflow) would be StackOverflowError.

Option D (native memory leak) would typically show a different error.

8
MCQeasy

A developer says Java is platform-independent because of the JVM. Which statement best explains this?

A.Java source code is compiled directly into native machine code for each platform.
B.Java source code is compiled into bytecode, which runs on the Java Virtual Machine (JVM).
C.The JVM is written in platform-independent code, allowing it to run anywhere.
D.Java uses an interpreter only, so the source code is interpreted directly on any platform.
AnswerB

Bytecode is platform-independent and executed by the JVM.

Why this answer

Option B is correct because Java source code is compiled into bytecode, which runs on the JVM, making it platform-independent at the source level. Option A is incorrect because Java does not compile to native code for each platform; it compiles to bytecode. Option C is incorrect because Java uses both a compiler and interpreter/JIT.

Option D is incorrect because the JVM itself is platform-specific, but bytecode is not.

9
Matchingmedium

Match each Java term to its correct definition.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Java Virtual Machine that executes bytecode

Runtime environment including JVM and core libraries

Development kit including JRE and tools like javac

Just-In-Time compiler that optimizes bytecode at runtime

Garbage Collector that automatically manages memory

Why these pairings

These are fundamental Java platform components.

10
MCQhard

A team is designing a new system that requires deploying independent services communicating over a network. Which Java technology is most suitable for this architecture?

A.Java Applets
B.Java EE with EJB
C.Spring Boot with REST APIs
D.Java RMI
AnswerC

Spring Boot simplifies microservice development with embedded servers and REST support.

Why this answer

Option D is correct because Spring Boot with REST APIs is ideal for building microservices. Option A is wrong because Java EE with EJB is heavyweight and less suited for modern microservices. Option B is wrong because applets are deprecated and not for server-side.

Option C is wrong because RMI is for remote method invocation but not typically used for RESTful microservices.

11
Multi-Selecteasy

Which THREE of the following are key features of the Java programming language?

Select 3 answers
A.Use of pointers for direct memory access
B.Support for multiple inheritance of classes
C.Platform independence through bytecode and JVM
D.Automatic memory management (garbage collection)
E.Strong type checking at compile time
AnswersC, D, E

Java source code is compiled to bytecode, which runs on any JVM.

Why this answer

Java is platform independent via bytecode, has automatic garbage collection, and is strongly typed. It does not support multiple inheritance for classes (only interfaces) and does not have pointers.

12
Multi-Selecteasy

Which TWO statements are true about the Java programming language?

Select 2 answers
A.It is a purely procedural language.
B.It supports direct pointer manipulation for memory access.
C.It is a strongly-typed language.
D.It allows multiple inheritance of classes.
E.It provides automatic memory management through garbage collection.
AnswersC, E

All variables must have a declared type.

Why this answer

Options A and C are correct. Java is strongly typed (A) and uses automatic memory management via garbage collection (C). Option B is wrong because Java does not support multiple inheritance of classes (it uses interfaces).

Option D is wrong because Java does not use pointers (except through references). Option E is wrong because Java is not fully procedural; it is object-oriented.

13
Multi-Selecteasy

Which TWO are true about the Java Runtime Environment (JRE)? (Choose two.)

Select 2 answers
A.It is larger than the JDK
B.It includes the Java compiler
C.It includes the JVM
D.It includes development tools
E.It is required to run Java applications
AnswersC, E

The JVM is a core component of the JRE.

Why this answer

Options B and D are correct. The JRE includes the JVM and core libraries, and it is required to run Java applications. Option A is incorrect because the compiler is part of the JDK, not the JRE.

Option C is incorrect because development tools are included in the JDK. Option E is incorrect because the JDK is larger than the JRE.

14
Multi-Selectmedium

A developer has written a Java program that uses third-party libraries. Which TWO actions are necessary to run the program on a different machine? (Choose two.)

Select 2 answers
A.Copy only the .class files of the program
B.Install the JDK
C.Set the PATH environment variable to include the java executable
D.Install the JRE
E.Copy the .java source files
AnswersC, D

The system must find the java command.

Why this answer

Options B and C are correct. The JRE must be installed to run Java applications, and the PATH environment variable must include the java executable's directory. Option A is incorrect because the JDK is not required to run, only to compile.

Option D is incorrect because .class files alone are insufficient; third-party libraries (JARs) are also needed. Option E is incorrect because source files are not needed to run.

15
MCQmedium

An application is designed with private fields and public getter/setter methods. Which OOP principle does this exemplify?

A.Polymorphism
B.Inheritance
C.Encapsulation
D.Abstraction
AnswerC

Encapsulation bundles data with methods and restricts direct access.

Why this answer

Option C is correct because encapsulation hides internal state and exposes behavior through methods. Option A (inheritance) is about class hierarchy. Option B (polymorphism) is about multiple forms.

Option D (abstraction) is about hiding complexity, but encapsulation specifically involves access control.

16
Multi-Selecthard

Which THREE are benefits of Java's platform independence? (Choose three.)

Select 3 answers
A.Ability to run on any device with a JVM
B.Write once, run anywhere
C.Faster execution compared to native code
D.Automatic memory management
E.Enhanced security through sandboxing
AnswersA, B, E

Platform independence allows the same bytecode to run on any device that has a JVM implementation.

Why this answer

Options A, B, and D are correct. Platform independence enables write-once-run-anywhere (A), enhances security through sandboxing (B), and allows running on any device with a JVM (D). Option C is incorrect because automatic memory management (garbage collection) is a separate feature.

Option E is incorrect because Java is not necessarily faster than native code; it often requires compilation or interpretation.

17
MCQmedium

Refer to the exhibit. A developer runs the command java -version on a system. Which statement about this Java installation is correct?

A.This is a Java SE 17 installation.
B.This is a Java Runtime Environment (JRE) installation.
C.This is a Java SE 8 installation.
D.This is a Java Development Kit (JDK) installation.
AnswerB

The output explicitly says 'Runtime Environment' and lacks compiler information.

Why this answer

The output shows "Runtime Environment" and no compiler information, indicating a JRE. Version 11.0.12 is Java SE 11 LTS. Option C and D are wrong because the version is 11, not 8 or 17.

Option A is incorrect because JDK would include the compiler.

18
Drag & Dropmedium

Arrange the steps to overload a method in Java in the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order

Why this order

First define one method, then define another with same name but different parameters, ensure unique signatures, and then call with matching arguments.

19
MCQhard

A team deploys a Java application and observes frequent Full GC pauses. Which garbage collector is designed to minimize pause times?

A.Garbage-First (G1GC) (-XX:+UseG1GC)
B.Concurrent Mark Sweep (CMS) (-XX:+UseConcMarkSweepGC)
C.Serial GC (-XX:+UseSerialGC)
D.Parallel GC (-XX:+UseParallelGC)
AnswerA

G1GC aims to limit pause times and reduce Full GC frequency.

Why this answer

Option C is correct because G1GC (Garbage-First) is designed to provide predictable pause times and reduce Full GC occurrences. Option A (Parallel) focuses on throughput, not pause times. Option B (CMS) was deprecated and can cause fragmentation.

Option D (Serial) is for single-threaded environments and has long pauses.

20
MCQeasy

A junior developer writes a simple 'Hello World' program and saves it as HelloWorld.java. He compiles it successfully with 'javac HelloWorld.java', confirming that HelloWorld.class is created in the current directory. When he tries to run it with the command 'java HelloWorld', the system returns 'Error: Could not find or load main class HelloWorld'. The current directory is indeed the one containing HelloWorld.class. He has JAVA_HOME set to the JDK installation directory and has verified that java is in the PATH. What is the most likely cause?

A.The class file is corrupt
B.The classpath does not include the current directory
C.The main method is missing or incorrectly declared
D.The java command is not in the PATH
AnswerB

Java does not automatically search the current directory; use '-cp .' to include it.

Why this answer

Option C is correct. By default, the java command does not include the current directory in the classpath. The developer must explicitly add it using -cp . or set the CLASSPATH environment variable.

Option A is incorrect because a corrupt class file would typically cause a different error (e.g., ClassFormatError). Option B is incorrect because a missing or incorrect main method would yield 'Main method not found' error. Option D is incorrect because the java command ran (the error message indicates java executed), so it must be in the PATH.

21
MCQhard

Based on the command, which garbage collector is configured for this application?

A.Parallel GC
B.Garbage-First (G1GC)
C.Serial GC
D.Concurrent Mark Sweep (CMS)
AnswerB

The flag -XX:+UseG1GC enables G1GC.

Why this answer

Option C is correct because -XX:+UseG1GC explicitly sets G1GC. Option A is not enabled; Parallel GC would be -XX:+UseParallelGC. Option B is not enabled; CMS would be -XX:+UseConcMarkSweepGC.

Option D is not enabled; Serial would be -XX:+UseSerialGC.

22
Multi-Selecthard

Which TWO are characteristics of the Java Runtime Environment (JRE)?

Select 2 answers
A.It includes the Java compiler (javac) for compiling source code.
B.It is smaller in size compared to the JDK.
C.It provides a debugger for troubleshooting code.
D.It is necessary to run any Java application.
E.It contains the JVM and core class libraries.
AnswersD, E

JRE provides the runtime required to execute Java programs.

Why this answer

Options A and D are correct. JRE includes JVM and core libraries (A) and provides runtime support for Java applications (D). Option B is false because development tools like javac are in JDK, not JRE.

Option C is false because JRE is typically larger than JDK? Actually JDK contains JRE plus tools, so JRE is smaller. Option E is false because JRE does not have debugger; that's in JDK.

23
Multi-Selecthard

Which TWO statements correctly describe the Java language? (Choose two.)

Select 2 answers
A.Java supports multiple inheritance of implementation.
B.Java supports operator overloading.
C.Java supports object-oriented programming.
D.Java supports multiple inheritance of classes.
E.Java is a statically typed language.
AnswersC, E

Java is primarily object-oriented.

Why this answer

Option C is correct because Java is fundamentally an object-oriented programming language that supports encapsulation, inheritance, and polymorphism. Java's design revolves around classes and objects, and all code must be written inside a class, making OOP a core principle of the language.

Exam trap

Oracle often tests the distinction between multiple inheritance of implementation (not supported) and multiple inheritance of type (supported via interfaces), and candidates mistakenly think Java supports operator overloading because of the + operator for strings.

24
MCQhard

A company is developing a Java-based inventory management system. The system runs on a single server and processes up to 1000 concurrent requests. The development team has implemented the code using multiple threads to handle requests. Recently, the system has been experiencing intermittent data corruption in the inventory counts. After reviewing the code, the team suspects that the issue is related to thread safety. The team is considering the following solutions: (A) Use the 'synchronized' keyword on all methods that update inventory counts. (B) Use 'volatile' keyword on the inventory count variables. (C) Use 'AtomicInteger' for inventory counts. (D) Increase the number of threads to handle requests faster. Which solution should the team implement to fix the data corruption issue with minimal performance impact?

A.Use 'AtomicInteger' for inventory counts.
B.Increase the number of threads to handle requests faster.
C.Use 'volatile' keyword on the inventory count variables.
D.Use the 'synchronized' keyword on all methods that update inventory counts.
AnswerA

AtomicInteger provides lock-free, thread-safe operations with good performance.

Why this answer

Option A is correct because AtomicInteger provides thread-safe atomic operations (like incrementAndGet) without requiring synchronization, ensuring consistent inventory counts under concurrent access with minimal performance overhead compared to full method synchronization.

Exam trap

Oracle often tests the distinction between visibility (volatile) and atomicity (AtomicInteger), trapping candidates who think volatile alone solves read-modify-write race conditions.

How to eliminate wrong answers

Option B is wrong because increasing the number of threads does not fix thread safety issues; it can worsen data corruption by increasing race conditions. Option C is wrong because volatile only ensures visibility of changes across threads but does not provide atomicity for compound operations like read-modify-write (e.g., count++), which is the root cause of corruption. Option D is wrong because using synchronized on all methods that update inventory counts would fix the issue but introduces significant performance impact due to thread contention, making it less optimal than AtomicInteger.

25
Multi-Selectmedium

Which THREE are valid components of the Java Virtual Machine (JVM)?

Select 3 answers
A.Java source code (.java files)
B.Java compiler (javac)
C.Heap memory area
D.Execution engine
E.Class loader subsystem
AnswersC, D, E

Heap is where all objects are allocated.

Why this answer

Options B, D, and E are correct. Class loader (B) loads bytecode, heap (D) is where objects are stored, execution engine (E) executes bytecode. Option A (compiler) is part of JDK, not JVM.

Option C (source code) is input to compiler, not JVM component.

26
MCQmedium

A company is developing a security-sensitive banking application. Which Java feature most directly enhances security?

A.Automatic garbage collection
B.Platform independence via bytecode
C.Built-in multithreading support
D.Bytecode verification
AnswerD

Bytecode verification checks code for security violations before execution.

Why this answer

Option B is correct because bytecode verification ensures that code adheres to JVM security constraints, preventing malicious operations. Option A (garbage collection) relates to memory management, not direct security. Option C (multithreading) is a concurrency feature.

Option D (platform independence) is about portability, not security.

27
MCQmedium

A company is upgrading from Java 8 to Java 11. Which advantage does the module system introduced in Java 9 provide?

A.Better multithreading
B.Faster garbage collection
C.Stronger encapsulation of internal APIs
D.Improved lambda syntax
AnswerC

The module system allows hiding internal packages from external access.

Why this answer

Option A is correct because the module system (Project Jigsaw) enforces stronger encapsulation of internal APIs, preventing accidental access. Option B is wrong because garbage collection improvements are separate from the module system. Option C is wrong because lambda syntax was introduced in Java 8.

Option D is wrong because multithreading features are not directly related to the module system.

28
MCQmedium

A developer compiles a Java program successfully but gets 'ClassNotFoundException' when running it. What is the most likely cause?

A.The Java version is incompatible
B.The main method signature is incorrect
C.The program has multiple classes
D.The classpath does not include the directory containing the .class file
AnswerD

ClassNotFoundException is thrown when the classpath does not contain the class.

Why this answer

Option C is correct because ClassNotFoundException typically occurs when the classpath does not contain the directory or JAR file where the .class file resides. Option A is wrong because an incorrect main method signature causes a different error (NoSuchMethodError). Option B is wrong because Java version incompatibility would cause UnsupportedClassVersionError.

Option D is wrong because having multiple classes does not cause this error unless one is missing from classpath.

29
MCQeasy

Given the output, which statement is true about this Java installation?

A.It includes a Just-In-Time (JIT) compiler.
B.It runs only in interpreted mode without JIT.
C.It is a debug build of the JVM.
D.It is a Java Micro Edition (Java ME) runtime.
AnswerA

HotSpot VM always includes JIT.

Why this answer

Option B is correct because HotSpot VM includes a JIT compiler. Option A is wrong because it's Jave SE, not ME. Option C is wrong because mixed mode means both interpreter and JIT are available.

Option D is wrong because the build is not a debug build (no 'debug' in version string).

30
Drag & Dropmedium

Arrange the steps to compile and run a Java program from the command line in the correct order.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order

Why this order

The correct order is to first write the code, then open terminal, navigate to the file location, compile with javac, and run with java.

31
MCQeasy

Which component of the Java platform is responsible for executing compiled bytecode?

A.JRE
B.JVM
C.JDK
D.Java Compiler
AnswerB

The Java Virtual Machine executes bytecode.

Why this answer

Option C is correct because the Java Virtual Machine (JVM) interprets bytecode or compiles it to native code. Option A is wrong because the JDK includes development tools, not execution. Option B is wrong because the JRE includes the JVM but is not the executor itself.

Option D is wrong because the compiler produces bytecode, it does not execute it.

32
MCQeasy

A team is designing a Java application that needs to run on different operating systems without modification. Which Java feature makes this possible?

A.The Java Virtual Machine
B.Just-in-time compilation
C.Garbage collection
D.The Java compiler
AnswerA

JVM interprets bytecode on any platform, providing portability.

Why this answer

The Java Virtual Machine (JVM) is the key enabler of Java's 'write once, run anywhere' capability. When you compile Java source code, the Java compiler produces bytecode, which is platform-independent. This bytecode is then executed by the JVM, which is implemented specifically for each operating system (Windows, Linux, macOS, etc.), translating the bytecode into native machine instructions.

Therefore, the same compiled .class file can run on any OS that has a compatible JVM, without requiring any modifications to the application code.

Exam trap

Oracle often tests the misconception that the Java compiler or JIT compilation is responsible for platform independence, but the correct answer is always the JVM because it is the runtime environment that abstracts away the underlying operating system.

How to eliminate wrong answers

Option B is wrong because Just-in-time (JIT) compilation is an optimization technique used by the JVM to improve runtime performance by compiling bytecode into native machine code at runtime; it does not provide platform independence. Option C is wrong because Garbage collection is an automatic memory management feature that reclaims memory from objects no longer in use; it has no role in enabling cross-platform portability. Option D is wrong because The Java compiler (javac) translates Java source code into bytecode, but the bytecode itself is platform-independent only because the JVM interprets it; the compiler does not handle execution or OS-specific adaptation.

33
MCQeasy

What is the primary purpose of Java bytecode?

A.To be executed by the Java Virtual Machine on any platform
B.To be compiled into native code once and reused
C.To be human-readable source code
D.To be directly executed by the operating system
AnswerA

Bytecode is platform-independent and executed by JVM.

Why this answer

Option B is correct because bytecode is an intermediate representation that can run on any JVM. Option A is incorrect because bytecode is not source code. Option C is incorrect because bytecode is not native machine code.

Option D is incorrect because bytecode is not the final executable but an intermediate step.

34
MCQhard

A development team is building a modular Java application using Java 17. They have defined a module named com.myapp with a module-info.java that includes 'requires com.thirdparty.lib;'. The com.thirdparty.lib module is a third-party library packaged as a modular JAR with its own module-info.class. The application compiles successfully using javac with the module path pointing to the directory containing the JAR. However, when starting the application with java --module-path <path> --module com.myapp, a NoClassDefFoundError occurs for a class from com.thirdparty.lib. The error message indicates the class is not found. The team has confirmed that the JAR file is present in the specified module path and that the class exists in the JAR. No other errors or warnings are displayed. The team is puzzled because the code compiles without issues. What is the most likely cause of this runtime error?

A.The module path order is incorrect, causing a different version of the library to be loaded.
B.The library is not compatible with Java 17.
C.The application's module requires the wrong version of the library.
D.The module com.thirdparty.lib does not export the package containing the required class in its module-info.java.
AnswerD

Even though the module is on the module path, its packages are not accessible without an 'exports' directive.

Why this answer

In modular Java, a module must export a package for its classes to be accessible by other modules. If com.thirdparty.lib does not export the package containing the required class, that class will not be found at runtime, even though the module is present. This is a common issue when migrating from classpath-based to module-path-based applications.

Option A is correct because the module's exports directive is missing. Option B is incorrect because module path order does not affect accessibility of exported packages; it affects module resolution, but the module is resolved. Option C is incorrect because version conflicts typically cause different errors (e.g., NoSuchMethodError).

Option D is incorrect because if the library were incompatible, compilation would likely fail or errors would be different.

35
MCQeasy

An application throws 'java.lang.OutOfMemoryError: Java heap space'. Which JVM option can help generate diagnostic information to identify the cause?

A.-version
B.-verbose:gc
C.-XX:+HeapDumpOnOutOfMemoryError
D.-Xmx
AnswerC

This option produces a heap dump when OutOfMemoryError occurs, useful for analysis.

Why this answer

Option A is correct because -XX:+HeapDumpOnOutOfMemoryError creates a heap dump file for analysis. Option B is wrong because -verbose:gc prints GC details but does not capture a heap dump. Option C is wrong because -Xmx sets maximum heap size, which might prevent the error but does not diagnose it.

Option D is wrong because -version prints version info.

36
MCQeasy

What is the primary role of the Java Development Kit (JDK) compared to the JRE?

A.JDK provides only a debugger and profiler.
B.JRE includes the JDK and additional libraries.
C.JDK is required to run Java applications, whereas JRE is not.
D.JDK includes compilers and tools for developing Java applications.
AnswerD

JDK contains javac, debugger, etc., which JRE lacks.

Why this answer

Option A is correct because JDK includes development tools like javac, while JRE only provides runtime environment. Option B is wrong because both JDK and JRE support the same platforms. Option C is wrong because JDK includes JRE, not the other way.

Option D is inaccurate because JDK includes debuggers and profilers.

37
MCQhard

A developer writes a multi-threaded application that runs on Windows. To ensure the same bytecode runs without modification on Linux and macOS, which Java feature is essential?

A.Bytecode verification
B.Platform independence via JVM
C.Just-in-Time (JIT) compilation
D.Thread synchronization
AnswerB

The JVM abstracts the underlying OS, allowing the same bytecode to run anywhere.

Why this answer

Option D is correct because platform independence via the JVM allows the same bytecode to run on any OS with a compatible JVM. Option A is wrong because thread synchronization is a coding technique, not a cross-platform feature. Option B is wrong because JIT compilation optimizes performance but does not provide OS independence.

Option C is wrong because bytecode verification checks safety, not portability.

38
MCQhard

A company wants to run existing Java SE application code on an embedded device with limited resources. Which Java edition is designed for such environments?

A.Java Card
B.Java FX
C.Java EE (Enterprise Edition)
D.Java ME (Micro Edition)
AnswerD

Java ME is tailored for embedded and mobile devices.

Why this answer

Option C is correct because Java ME (Micro Edition) is for embedded and mobile devices with constrained resources. Option A (Java Card) is for smart cards. Option B (Java EE) is for enterprise servers.

Option D (Java FX) is a UI framework, not an edition.

39
MCQmedium

During execution, the JVM uses Just-In-Time (JIT) compilation. What is its primary benefit?

A.Translates bytecode into an intermediate language for interpretation.
B.Improves execution speed by compiling frequently used bytecode to native code.
C.Converts Java source code directly into bytecode.
D.Enhances security by verifying bytecode integrity.
AnswerB

JIT identifies hot spots and compiles them for faster execution.

Why this answer

Option A is correct because JIT compiles bytecode to native machine code at runtime for performance improvement. Option B is incorrect because JIT does not generate bytecode. Option C is incorrect because JIT does not translate to intermediate languages.

Option D is incorrect because JIT is not for security.

40
MCQmedium

A developer is writing a Java application that processes a large number of transactions. The application must ensure that each transaction is committed only if all steps complete successfully, otherwise the entire transaction should be rolled back. Which Java concept should the developer use to implement this requirement?

A.Exception handling
B.Inheritance
C.Multithreading
D.Encapsulation
AnswerA

Exception handling can catch failures and trigger rollback.

Why this answer

Option A is correct because exception handling in Java allows the developer to catch runtime failures (e.g., SQLException, IOException) within a try block and, in the catch block, invoke a rollback on the transaction (e.g., Connection.rollback()). If all steps succeed, the transaction is committed via Connection.commit(). This ensures atomicity — the 'all-or-nothing' property required for transaction processing.

Exam trap

Oracle often tests whether candidates confuse 'transaction management' with 'multithreading' — the trap here is assuming that concurrent execution (Option C) is needed for atomicity, when in fact atomicity is enforced by exception handling and explicit commit/rollback calls, not by running steps in parallel.

How to eliminate wrong answers

Option B is wrong because inheritance is a mechanism for code reuse and establishing type hierarchies (e.g., extends), not for controlling transactional commit/rollback behavior. Option C is wrong because multithreading deals with concurrent execution of tasks (e.g., using Thread or Runnable), not with ensuring atomicity of a single transaction's steps. Option D is wrong because encapsulation hides internal state and exposes methods via access modifiers (e.g., private fields with public getters/setters), which does not provide any mechanism for conditional commit or rollback.

41
MCQmedium

A developer runs the command shown in the exhibit. The developer wants to ensure the application uses the latest available language features. Which action should the developer take?

A.Download and install a newer version of the JDK.
B.Enable lambda expressions by setting the -enable-lambdas flag.
C.Use the -source and -target flags to compile for a newer version.
D.Upgrade the JVM to the latest version.
AnswerA

A newer JDK includes both compiler and runtime with latest features.

Why this answer

Option A is correct because the latest available language features (e.g., pattern matching, sealed classes, records) are tied to the JDK version. Downloading and installing a newer JDK provides both the compiler (javac) and runtime (JVM) that support those features. Simply upgrading the JVM (Option D) or using -source/-target flags (Option C) does not enable new language syntax in the compiler if the JDK itself is outdated.

Exam trap

The trap here is that candidates confuse upgrading the JVM (runtime) with upgrading the JDK (development kit), or think that compiler flags like -source and -target can retroactively add new language features to an older JDK.

How to eliminate wrong answers

Option B is wrong because there is no -enable-lambdas flag in Java; lambda expressions were introduced in Java 8 and are enabled by default when using a JDK 8 or later. Option C is wrong because the -source and -target flags only control the version of source code accepted and the class file format produced, but they do not add new language features to an older JDK; you need a newer JDK to compile with newer syntax. Option D is wrong because upgrading only the JVM (runtime) does not give the compiler access to new language features; the JDK (which includes javac) must also be updated.

Ready to test yourself?

Try a timed practice session using only What is Java questions.