Java Flashcards

1
Q

JVM vs JRE vs JDK

A
  • JDK - Java Development Kit - software environment + tooling for developing Java, including: JRE, Interpreter (Java), Compiler (javac), archiver (jar), document generator (javadoc)
  • JRE - Java Runtime Environment - Minimum requirements for running a java application, including the JVM, core classes, supporting files.
  • JVM - Java Virtual Machine - The interpreter that runs compiled java byte code line by line.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stack vs Heap

A

Stack Memory keeps track of primitives, method invocations and references to objects that exist in the heap.
Stack is for static memory allocation and execution of a thread.
Access is LIFO (Last-In-First-Out)
Stack is THREAD SAFE (Each thread has its own stack)
Access is FAST compared to Heap
Heap Space keeps track of objects
Heap is dynamic memory allocation.
Diving into the heap, it is actually divided into 3 parts (known as generations). Young (new objects, minor GC when filled up), Old (Tenured, long surviving objects, when Young objects are old enough, they move here), Permanent (JVM metadata for runtime classes/methods)
Heap is NOT THREAD SAFE, needs proper guard via synchronizing code.
Access is SLOW compared to Stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Primitive vs Object

A

**Primitive - predefined data types that cannot contain a null value. **
Primitives are immutable (Primitive variables can re-assign a new value, but existing value cannot be altered in memory)
Memory efficient
There are 8 types: int, byte, short, long, float, double, boolean, char.
Primitives cannot be used for generics or the reflection API.
Object - user-defined that default to null value.
NOT memory efficient (When compared to primitives)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is Autoboxing and Unboxing

A

The transformation of primitives to their object wrapper classes or vise versa. Java will automatically handle this to ease development, but can come at a performance cost for high-performant systems, so it’s better to avoid and use primitives if that is a concern)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

String

A

String is not a primitive, but is pre-defined and solves the case where a char cannot store multiple characters. Strings are immutable (Prefered to use StringBuilder, String.format(…) etc)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly