🎓 BookMCQ
← Back to 16. Virtual Machines

📝 Java Virtual Machine JVM in Operating System (12 MCQs)

JVM as a Virtual Execution Environment

The Java Virtual Machine is an abstract computing environment that executes Java bytecode and provides services such as memory management, class loading, runtime checks, and exception handling. It is a programming environment virtual machine rather than a hypervisor that virtualises an entire physical computer. The JVM operates as a process supported by the host operating system.

Why Bytecode Supports Platform Independent Execution

Compiling Java source separately for every processor and operating system would reduce application portability. Java compilers instead generate bytecode for a defined virtual instruction set. A compatible JVM implements that instruction set on each platform, translating or interpreting bytecode while using the host OS for files, networking, threads, and other services.

Class Loading, Verification and Bytecode Execution

The JVM loads class files, verifies bytecode constraints, links required classes, and executes instructions. An interpreter can execute bytecode directly, while a just-in-time compiler converts frequently executed sections into native machine code. Runtime services also manage objects, garbage collection, threads, and exceptions within the Java execution environment.

Example of Running Java Bytecode Across Systems

A developer compiles a program on Windows and obtains a class file containing bytecode. The same file runs on a Linux computer with a compatible JVM. The Linux JVM interprets or compiles the instructions for its processor, while using Linux system calls and libraries for underlying resources.

Portability, Managed Memory and Runtime Costs

The JVM offers portability, automatic memory management, bytecode verification, and runtime optimisation. Garbage collection, class loading, and just-in-time compilation consume resources and may affect startup or latency. The JVM does not isolate a complete guest operating system, and application security still depends on runtime configuration, libraries, and operating system protections.

Misconceptions About the Java Virtual Machine

'The JVM is a Type 1 hypervisor' is false because it runs as a host process. 'Java bytecode is always interpreted' ignores just-in-time compilation. 'The JVM removes all operating system dependencies' overlooks its use of host files, threads, networking, and native interfaces.

Exam Focus: Bytecode, Runtime and System Virtualisation

Trace Java source compilation into bytecode, class loading, verification, and execution by the JVM. Distinguish interpretation from JIT compilation and explain the role of garbage collection. Questions may compare the JVM with a hardware virtual machine or ask how bytecode supports portability across operating systems.

Key Terms of the Java Virtual Machine

  • JVM - Runtime environment for Java bytecode.
  • Bytecode - Intermediate instructions executed by the JVM.
  • Class loader - Loads Java classes into runtime.
  • JIT compiler - Compiles selected code into native instructions.
  • Garbage collection - Reclaims unreachable allocated objects.
2
Easy
6
Medium
4
Hard

📝 All Java Virtual Machine JVM in Operating System MCQs

Q1. An administrator configures two zones on a Solaris 10 host and assigns each zone 50 % of the physical CPU capacity. Which statement best describes how each zone’s scheduler will treat its CPU resources?

A.Each zone will see two virtual CPUs and schedule them as if they were dedicated cores.
B.Each zone will perceive a single virtual CPU that can use the full physical CPU, but the global scheduler limits actual usage to 50 %. ✅
C.Each zone receives a fixed time slice that guarantees exactly half of every CPU cycle.
D.Each zone’s scheduler is unaware of the physical limit and may over‑commit CPU time.
💡 Difficulty: easy | ✅ Correct: B

📖 Explanation: The global scheduler enforces the 50 % limit, so a zone thinks it has one virtual CPU that can run at full speed, but the VMM caps its actual consumption. Option B captures this behavior. Option A is wrong because zones do not automatically get extra virtual CPUs; they inherit the number of physical CPUs. Option C is incorrect because limits are enforced by time‑sharing, not a fixed slice of every cycle. Option D is false because the VMM prevents over‑commitment. In practice, this allows administrators to guarantee fair CPU distribution while each zone still sees a normal single‑CPU environment.

Q2. Why do Solaris zones give processes the impression that they are the only ones running on the system?

A.Because each zone runs its own independent kernel instance.
B.Because the VMM virtualizes hardware devices and isolates system calls per zone.
C.Because the zone’s scheduler hides other zones’ processes from the process table. ✅
D.Because zones use a separate physical network interface for each process.
💡 Difficulty: easy | ✅ Correct: C

📖 Explanation: Zones create separate process namespaces, so a process sees only the processes belonging to its zone, making it appear alone. Option C states this correctly. Option A is false; zones share the same kernel. Option B describes device virtualization, not process isolation. Option D is unrelated; network interfaces do not affect process visibility. This design lets administrators run applications without modifying code, as the applications behave as if on a dedicated system.

Q3. A zone is allocated 2 GB of memory, but a Java application inside the zone requires 3 GB. What is the most likely outcome?

A.The application will run normally because zones can borrow memory from the global pool.
B.The zone will trigger swapping, potentially degrading performance. ✅
C.The VMM will automatically expand the zone’s memory limit to satisfy the request.
D.The application will fail to start with an OutOfMemoryError.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: When a zone is limited to 2 GB, any request beyond that forces the zone to use swap space, so the Java process continues but may suffer latency. Option B reflects this behavior. Option A is incorrect because zones cannot arbitrarily borrow memory without swapping. Option C is wrong; the VMM does not raise the limit automatically. Option D is too absolute; the JVM may start and later encounter an OutOfMemoryError, but initially it will rely on swap. This illustrates why administrators must size zones appropriately for memory‑intensive workloads.

Q4. How does the virtual machine monitor (VMM) schedule virtual CPUs among multiple Solaris zones?

A.It assigns each zone a dedicated physical CPU core.
B.It uses a priority‑based round‑robin algorithm to share physical CPUs. ✅
C.It runs zones sequentially, completing one zone before starting the next.
D.It relies on the zones’ own schedulers to manage physical CPU allocation without VMM involvement.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: The VMM interposes between zones and hardware, distributing CPU time using a fair, often priority‑aware round‑robin scheme. Option B captures this. Option A is false because zones usually share cores. Option C describes a batch approach not used in Solaris. Option D ignores the VMM’s role; while each zone has its own scheduler, the VMM still arbitrates physical CPU access. Understanding this hierarchy helps predict how workloads compete for CPU resources across zones.

Q5. Two zones need to run a web server on port 80. Which statement accurately describes how Solaris prevents a conflict?

A.Both zones can bind to port 80 because they have separate network stacks.
B.Only the zone with the higher priority can bind, the other must use a different port.
C.The global network stack enforces unique port usage, so one zone must use an alternative port. ✅
D.Solaris automatically maps port 80 to different IP addresses for each zone.
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: Ports are unique within the global network namespace; Solaris prevents two zones from listening on the same IP/port combination, so one must select another port. Option C explains this rule. Option A is incorrect because ports are not duplicated across zones. Option B is not how Solaris resolves conflicts; it does not choose based on priority. Option D describes IP aliasing, which is possible but still requires distinct ports if IP addresses are shared. This knowledge is crucial when deploying web services in multiple zones.

Q6. What is the relationship between a zone’s internal scheduler and the global scheduler in Solaris?

A.The internal scheduler operates only when the global scheduler grants the zone a CPU time slice. ✅
B.The internal scheduler directly controls physical CPU cores, bypassing the global scheduler.
C.Both schedulers are identical; there is no distinction.
D.The global scheduler runs only after all zone schedulers have finished their tasks.
💡 Difficulty: medium | ✅ Correct: A

📖 Explanation: A zone’s scheduler can dispatch its processes only during the intervals allocated by the global scheduler, making option A correct. Option B is wrong because physical CPU assignment is always mediated by the global scheduler. Option C ignores the layered nature of scheduling. Option D reverses the control flow; the global scheduler decides first, then zones schedule internally. Recognizing this hierarchy helps administrators tune performance by adjusting both global and zone‑level parameters.

Q7. A workload must be moved from zone 1 to zone 2, and the CPU share for zone 2 needs to be increased to 70 %. Which command accomplishes this?

A.zonecfg -m cpu‑share
B.prctl -n zone -s cpu‑share
C.zonecfg -z zone2 -c 'set cpu‑cap=70' ✅
D.zlogin -z zone1 -c 'renice'
💡 Difficulty: medium | ✅ Correct: C

📖 Explanation: The zonecfg utility modifies zone configuration, and the ‘set cpu‑cap’ attribute changes the CPU share for a specific zone, matching option C. Option A is not a valid zonecfg syntax. Option B mixes prctl with zone parameters, which is unsupported. Option D attempts to renice processes but does not alter zone‑level CPU allocation. Using zonecfg ensures the VMM respects the new share, allowing the workload to run with the desired proportion of CPU resources.

Q8. Why are Solaris zones considered lighter‑weight than full hardware virtualization solutions such as Xen or VMware?

A.Zones share the same kernel and avoid emulating hardware devices, reducing overhead. ✅
B.Zones duplicate the entire operating system image, increasing memory usage.
C.Zones require a separate hypervisor that adds extra processing steps.
D.Zones virtualize the CPU using binary translation, which is slower than hardware assistance.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Because zones run on a single kernel and do not need to emulate hardware, they incur minimal performance penalties, making option A correct. Option B is opposite; zones do not duplicate the OS. Option C is false; there is no separate hypervisor layer. Option D mischaracterizes zone virtualization, which does not rely on binary translation. This distinction explains why enterprises can host many zones on a server with near‑native efficiency, unlike full VMs that carry higher CPU and memory costs.

Q9. Three zones have CPU caps of 30 %, 45 % and 25 % on a system with four physical CPUs. How many CPU cores can each zone use?

A.ZoneA: 1.2 cores, ZoneB: 1.8 cores, ZoneC: 1.0 core ✅
B.ZoneA: 1 core, ZoneB: 2 cores, ZoneC: 1 core
C.ZoneA: 2 cores, ZoneB: 2 cores, ZoneC: 1 core
D.ZoneA: 1.5 cores, ZoneB: 2.0 cores, ZoneC: 0.5 core
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: Multiply the total CPU count (4) by each zone’s share: 4×0.30=1.24 \times 0.30 = 1.2 cores for zoneA, 4×0.45=1.84 \times 0.45 = 1.8 for zoneB, and 4×0.25=1.04 \times 0.25 = 1.0 for zoneC, matching option A. Option B rounds down, losing fractional capacity. Option C over‑allocates cores, exceeding the 4‑CPU limit. Option D miscalculates zoneC’s share. Understanding fractional core allocation helps administrators plan workloads that may not need whole cores, ensuring fair distribution without over‑provisioning.

Q10. How does Solaris zone isolation for user accounts differ from container isolation mechanisms in Linux, and what implication does this have for security?

A.Zones use separate UID namespaces, providing complete isolation identical to Linux containers.
B.Zones share the same UID space but enforce access controls through zone‑specific permission sets. ✅
C.Zones rely on mandatory access control (MAC) policies that are not present in Linux containers.
D.Zones do not isolate user accounts at all, making them insecure compared to Linux containers.
💡 Difficulty: hard | ✅ Correct: B

📖 Explanation: Solaris zones keep a single UID namespace; users in different zones can have the same numeric ID, but zone‑specific permission checks prevent cross‑zone access, which is described in option B. Option A is incorrect because zones do not provide separate UID namespaces like Linux. Option C misattributes MAC to zones exclusively; while Solaris supports RBAC, MAC is not the primary differentiator here. Option D overstates the lack of isolation; zones still enforce boundaries. Recognizing this nuance informs security planning when choosing between zones and Linux containers.

Q11. A zone’s scheduler is overloaded and its applications are experiencing latency. Which tuning action is most likely to improve performance?

A.Increase the zone’s cpu‑cap value to allow more CPU time. ✅
B.Set the zone’s cpu‑capped attribute to true.
C.Decrease the zone’s cpu‑share attribute to reduce contention.
D.Enable the global scheduler’s fair‑share mode.
💡 Difficulty: hard | ✅ Correct: A

📖 Explanation: If a zone is throttled, raising its cpu‑cap permits it to consume a larger portion of the physical CPU, alleviating scheduler pressure, which is option A. Option B merely toggles capping without changing the limit. Option C would worsen the problem by limiting the zone further. Option D changes global behavior but does not directly address the overloaded zone. Adjusting cpu‑cap is a common tuning step for performance‑critical zones, ensuring they receive sufficient CPU slices for their workloads.

Q12. In Solaris terminology, what is a ‘zone’?

A.A hardware‑level virtual machine that runs its own kernel.
B.A lightweight OS container that shares the host kernel but has isolated resources. ✅
C.A networking protocol for inter‑process communication.
D.A type of file system used for snapshotting.
💡 Difficulty: medium | ✅ Correct: B

📖 Explanation: A zone is defined as a lightweight OS container that shares the host kernel while providing isolated process, network, and file system views, matching option B. Option A describes full virtualization, not zones. Option C confuses zones with communication protocols. Option D refers to a storage concept unrelated to zones. This definition underpins how Solaris achieves application containment without the overhead of separate kernels.

🔗 Related Topics (MCQs)