Java Interview Questions Flashcards
Which memory areas does the JVM provide and what’s the difference between them?
Heap Area: represents the runtime data, where arrays and classes are allocated. It is created on the startup, doesn’t need to be continuous.
Where a primitive is stored in memory?
Stack area
How can you override a static method?
They can’t be overriden
Difference between StringBuffer and StringBuilder?
StringBuffer is not thread safe
What is JIT for?
JIT gets a block of code that is executed frequently and compiles it to native machine language to speed up process
Where are complex objects stored?
The heap
What do the stack store?
local variables like int,float
What is Metaspace? What types of variables is stored in the metaspace?
Metaspace is only for Java 8+.
static primitives are stored in metaspace.
static objects have the reference stored in the metaspace
Where is the String Pool stored?
In the Heap
When is an object eligible for GC?
any elements on the heap that are not reachable
Where is the Young and Old gen stored?
The heap
What’s the difference between Young and Old generation?
The Young gen. is way smaller. That’s why the GC on that part of the memory only takes a fraction of second. If it survives, it gets moved to the Old Gen.
GC on the Old gen are way slower, but they happen less frequently
What are the survivor spaces in the Young gen?
Eden: When it gets full, the GC happens
S0/S1: When GC happens, objects get moved from one to another, either one them will be empty
Explain JDK, JRE, JVM
JDK: Java development kit, it is the tool necessary to compile, document and package Java Programs. It contains JRE + development tools
JRE: Java Runtime Environment, refers to a runtime env. in which Java bytecode can be executed. It’s an implementation of JVM which physically exists.
JVM: Java virtual Machine, it’s an abstract machine. It is a specification that provides a runtime environment in which java bytecode can be executed
What is the difference between ArrayList and Vector?
ArrayList is not syncronized.