📝 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.
📝 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 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?
📖 Explanation: Multiply the total CPU count (4) by each zone’s share: cores for zoneA, for zoneB, and 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?
📖 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?
📖 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’?
📖 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.