0% found this document useful (0 votes)
4 views

Core Java Interview Questions and Answers (2024) - InterviewBit 2

The document discusses core Java interview questions and answers, specifically focusing on the differences between heap and stack memory in Java. Stack memory is fixed and assigned to individual programs, while heap memory is dynamically allocated during runtime for objects. An example Java program illustrates how variables are stored in stack memory and objects in heap memory.

Uploaded by

ekanemwork
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Core Java Interview Questions and Answers (2024) - InterviewBit 2

The document discusses core Java interview questions and answers, specifically focusing on the differences between heap and stack memory in Java. Stack memory is fixed and assigned to individual programs, while heap memory is dynamically allocated during runtime for objects. An example Java program illustrates how variables are stored in stack memory and objects in heap memory.

Uploaded by

ekanemwork
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2/8/24, 6:56 AM Core Java Interview Questions and Answers (2024) - InterviewBit

is not a pure object oriented language.


Online Free New
Practice Resources  Contests   Events Scaler
3. Difference between Heap and Stack Memory in java.
IDE And how
Mock java utilizes this.

Stack memory is the portion of memory that was assigned to every individual program. And it was
fixed. On the other hand, Heap memory is the portion that was not allocated to the java program but
it will be available for use by the java program when it is required, mostly during the runtime of the
program.

Java Utilizes this memory as -


When we write a java program then all the variables, methods, etc are stored in the stack memory.
And when we create any object in the java program then that object was created in the heap memory.
And it was referenced from the stack memory.
Example- Consider the below java program:

class Main {
public void printArray(int[] array){
for(int i : array)
System.out.println(i);
}
public static void main(String args[]) {
int[] array = new int[10];
printArray(array);
}
}

For this java program. The stack and heap memory occupied by java is -

https://www.interviewbit.com/java-interview-questions/ 1/2
2/8/24, 6:56 AM Core Java Interview Questions and Answers (2024) - InterviewBit

Instructions from Interviewbit

Start Test

https://www.interviewbit.com/java-interview-questions/ 2/2

You might also like