Posts

Java interview questions for 5 years experience

Contents [ hide ] What is difference between Heap and Stack Memory in Java, and shed light on their utilization? In Java, memory management plays a crucial role in determining how objects are stored and accessed during program execution . Heap and Stack Memory are two distinct regions where different types of data are managed. Understanding their differences is essential for efficient memory utilisation and managing object lifecycles. Stack Memory Stack Memory is a region used for storing method calls, local variables, and references to objects . It operates in a Last-In-First-Out (LIFO) manner , resembling a stack of items. Each method call creates a new frame in the stack, containing variables specific to that method. Stack Memory is relatively fast for allocation and deallocation because it follows a strict order. However, it has limited space and is typically used for small, short-lived data. Primitive data types and references to objects are often stored here. Ex

Java interview questions - Must to know concepts

Contents [ hide ] How does Java achieve platform independence, and what is the underlying principle? Java programs can run on diverse operating systems and hardware setups without requiring modification. This feat is primarily achieved through the concept of the Java Virtual Machine (JVM). The Java Virtual Machine (JVM) The JVM acts as a bridge between the Java code you write and the underlying hardware and operating system . When you compile your Java code, it is translated into an intermediate form called bytecode, which is not tied to any specific platform. The JVM then comes into play. It takes this bytecode and dynamically translates it into machine-specific instructions that the host system can execute. This means that a Java program can be written once and executed on any system with the appropriate JVM for that system. Example: Running a Java Program on Different Platforms Consider a simple Java program that calculates the sum of two numbers: package codeKatha