Sharpen your understanding of core Java interview topics, including JVM architecture, object-oriented principles, and key relationships in Java programming.
Which component of the Java Virtual Machine is responsible for loading class files into memory when a program starts running?
Explanation: The Class Loader handles loading class files into memory at the start of program execution. The Execution Engine runs the byte code, the Heap stores objects and data, and the Method Area keeps class-level information, but none of these loads classes into memory directly.
What is the primary role of the Heap in the Java Virtual Machine?
Explanation: The Heap is dedicated to storing Java objects and their related data during program execution. Storing method calls happens in the Stack, executing byte code involves the Execution Engine, and interfacing with native libraries is managed by the Java Native Interface.
Which type of information is stored in the JVM's Method Area?
Explanation: The Method Area stores elements such as static variables, constant pools, and method data. Thread execution and local variables are related to the Stack, while native code is handled by JNI.
In the JVM, what does the Stack primarily keep track of during program execution?
Explanation: The Stack manages method frames, which track method calls and local variables. Constant pools are stored in the Method Area, object allocation is handled by the Heap, and byte code interpretation is managed by the Execution Engine.
What is the main function of the Execution Engine within the JVM?
Explanation: The Execution Engine reads and executes Java byte code, either by interpreting it or compiling it to machine code. Loading class files is the Class Loader's role, class-level management is for the Method Area, and object allocation is the Heap's function.
What does the Java Native Interface (JNI) enable Java programs to do?
Explanation: JNI allows Java to communicate with code written in languages like C or C++. Compilation and storage of static data are handled elsewhere, and thread synchronization is unrelated to JNI.
Why is Java not considered a 100% object-oriented language?
Explanation: Java includes primitive data types (like int, boolean) that aren't objects, so it's not considered fully object-oriented. Java supports user-defined classes, class inheritance, and procedural code can exist, but primitives are the deciding factor.
In object-oriented programming, what is the relationship between classes and objects?
Explanation: Classes define the structure and behaviors that objects (instances) will possess. Objects aren't blueprints, and classes are not created from objects, nor are they unrelated.
What best describes aggregation in Java?
Explanation: Aggregation is an association where a parent holds reference to children with their own lifecycles. It is not inheritance, doesn't necessarily involve dependent lifecycles (that's composition), nor is it unrelated to hierarchy.
How does aggregation help in Java system design?
Explanation: Aggregation allows code reuse by linking classes through ownership, aiding in modularity and maintainability. It doesn't force shared lifecycles, doesn't prevent code reuse, and relies on object references.