We know that JVM is responsible for memory allocation and deallocation. Reference variable refers to the object stored in heap memory. So, why can't we use pointers to refer main memory and what are the different issues caused by the pointers due to which Java doesn't support pointers?
Does JVM create a GC thread for each and every unreferenced object? Will there be a performance issue if there are lots of GC threads running in the background?
Garbage Collector is a single demon thread running behind the scenes and monitors the heap memory. Ass and when required, it will clean up unused objects and unrefereed object using the 3 rules that we discussed.
This means that you can only have one object for the runtime. The meaning of singleton class is that, you can have only one object for the class at anytime. You cannot have multiple instances of that class. You can do that by having a private constructor for the class and a public method which always returns the same object. That is the reason why you obtain runtime object by using getRuntime() method and not by using new Runtime(). you will use the same runtime object for everything, so that the performance of the system will be increased.
8 thoughts on “Core Java doubts & clarifications”
We know that JVM is responsible for memory allocation and deallocation. Reference variable refers to the object stored in heap memory. So, why can't we use pointers to refer main memory and what are the different issues caused by the pointers due to which Java doesn't support pointers?
Garbage Collection Working:
Does JVM create a GC thread for each and every unreferenced object? Will there be a performance issue if there are lots of GC threads running in the background?
Garbage Collector is a single demon thread running behind the scenes and monitors the heap memory. Ass and when required, it will clean up unused objects and unrefereed object using the 3 rules that we discussed.
I'm trying give input of characters through console and print them. But not able to do. Can you correct me?
char[] charArray = new char[4];
for(int i=0;i<4;i++){
System.out.println("Enter: ");
charArray= scan.next().toCharArray();
}
for(int m=0;m<charArray.length;m++){
System.out.println("Elements are: "+charArray[m]);
}
Output:
Enter:
w
Enter:
d
Enter:
s
Enter:
a
Elements are : a
I GOT IT.
There is only one instance of java.lang.Runtime class is available for one java application.
The Runtime.getRuntime() method returns the singleton instance of Runtime class.
-What does this mean exactly. How this instance differ from other instances (created by us).?
This means that you can only have one object for the runtime. The meaning of singleton class is that, you can have only one object for the class at anytime. You cannot have multiple instances of that class. You can do that by having a private constructor for the class and a public method which always returns the same object. That is the reason why you obtain runtime object by using getRuntime() method and not by using new Runtime(). you will use the same runtime object for everything, so that the performance of the system will be increased.
As part of singleton design pattern discussion, you can understand this …