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

Sample Java

Java is not a pure object-oriented language because it supports primitive data types like int and float, in addition to object types. In Java, stack memory is allocated for each program and holds variables and methods, while heap memory is not pre-allocated and holds objects created during program execution, which are referenced from the stack. For example, in a Java program that prints an array, the array object would be created in heap memory and referenced from the stack.

Uploaded by

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

Sample Java

Java is not a pure object-oriented language because it supports primitive data types like int and float, in addition to object types. In Java, stack memory is allocated for each program and holds variables and methods, while heap memory is not pre-allocated and holds objects created during program execution, which are referenced from the stack. For example, in a Java program that prints an array, the array object would be created in heap memory and referenced from the stack.

Uploaded by

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

2. Why is Java not a pure object oriented language?

Java supports primitive data types - byte, boolean, char, short, int, float, long,
and double and hence it is not a pure object oriented language.

3. Difference between Heap and Stack Memory in java. And how 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);
}
}

You might also like