JVM in short
What is the JVM? Java programs need the JVM to run. Like .NET Framework. Stands for Java Virtual Machine. Java can run on multiple platforms because JVMs are implemented for different systems. So, Java programs can run on any platform that has a JVM (Though JVM may be different). It executes bytecode, which is translated from Java code. Oh, and Kotlin code can also be compiled into bytecode. What are JRE, JDK, and JAR? JRE (Java Runtime Environment) – It’s what Java needs to run, includes the JVM. JDK (Java Development Kit) – The toolkit for Java developers (You need it to do developing things), and it includes the JRE. It also contains the javac compiler, which turns your code into bytecode. JAR (Java ARchive) – A zip file specifically for Java programs. If everything’s set up correctly, you can run it directly. What is the JVM made of? Class Loader Subsystem – Finds your classes. Runtime Data Area – Contains the native method stack, Java method stack, method area, PC Registers, and heap. Native Method Stack – For calling code in other languages (mainly C++). Java Method Stack – For storing Java function call stacks. PC Registers – Tells the interpreter where to go next. Fact: It’s the only area that won’t throw an OutOfMemoryError. Method Area – Holds class-related info. It’s shared between threads. Heap – Just the heap, shared between threads. Anything not explicitly mentioned is thread-private. Execution Engine – Interpreter, JIT (Just-In-Time compiler), and GC (Garbage Collector). Native Method Library. Class Loader Subsystem? MyClass.java -> Loading (find the class) -> Linking -> Verify, Prepare, Resolve -> Initialization. Verify – Did you write your class correctly? Prepare – Allocates memory for static variables and sets them to default. Resolve – Turns symbolic references (names) into direct references (addresses). Loading: Class Loaders Everything’s an object in Java, even the classes themselves are loaded by class loader objects. ...