1.What is the size of int in 64-bit JVM?
The size of an int variable is constant in Java, it's always 32-bit irrespective of platform.
Which means the size of primitive int is same in both 32-bit and 64-bit Java virtual machine.
2.The difference between Serial and Parallel Garbage Collector?
Even though both the serial and parallel collectors cause a stop-the-world pause during Garbage
collection. The main difference between them is that a serial collector is a default copying collector
which uses only one GC thread for garbage collection while a parallel collector uses multiple GC
threads for garbage collection.
3.What is the size of an int variable in 32-bit and 64-bit JVM?
The size of int is same in both 32-bit and 64-bit JVM, it's always 32 bits or 4 bytes.
4.A difference between WeakReference and SoftReference in Java?
Though both WeakReference and SoftReference helps garbage collector and memory efficient.
WeakReference becomes eligible for garbage collection as soon as last strong reference is lost
But SoftReference even thought it can not prevent GC, it can delay it until JVM absolutely need memory.
5.How do WeakHashMap works?
WeakHashMap works like a normal HashMap but uses WeakReference for keys, which means
if the key object doesn't have any reference then both key/value mapping will become eligible
for garbage collection.
6.How do WeakHashMap works?
WeakHashMap works like a normal HashMap but uses WeakReference for keys, which means
if the key object doesn't have any reference then both key/value mapping will become eligible
for garbage collection.
7.How do you find if JVM is 32-bit or 64-bit from Java Program?
You can find that by checking some system properties like sun.arch.data.model
or os.arch
8.What is the maximum heap size of 32-bit and 64-bit JVM?
Theoretically, the maximum heap memory you can assign to a 32-bit JVM is 2^32 which is 4GB but practically the limit is much smaller. It also varies between operating systems
e.g. form 1.5GB in Windows to almost 3GB in Solaris.
64-bit JVM allows you to specify larger heap size, theoretically 2^64 which is quite large
but practically you can specify heap space up to 100GBs.
There are even JVM e.g. Azul where heap space of 1000 gigs is also possible.
9.What is the difference between JRE, JDK, JVM and JIT?
JRE stands for Java run-time and it's required to run Java application. JDK stands for
Java development kit and provides tools to develop Java program e.g. Java compiler.
It also contains JRE. The JVM stands for Java virtual machine and it's the process responsible
for running Java application. The JIT stands for Just In Time compilation and helps to boost
the performance of Java application by converting Java byte code into native code when the
crossed certain threshold i.e. mainly hot code is converted into native code.
10.Can you guarantee the garbage collection process?
No, you cannot guarantee the garbage collection, though you can make a request
using System.gc() or Runtime.gc() method.
11.How do you find memory usage from Java program? How much percent of the heap is used?
You can use memory related methods from java.lang.Runtime class to get the free memory, total
memory and maximum heap memory in Java.
By using these methods, you can find out how many percents of the heap is used and how
much heap space is remaining.
Runtime.freeMemory() return amount of free memory in bytes, Runtime.totalMemory() returns total memory in bytes and
Runtime.maxMemory() returns maximum memory in bytes
0 Comments