How Java Programme Works
- Java is a platform-independent language.
- Java is portable works on wora principle (write once and run anywhere).
- Java is highly object orianted programming language.
JVM (Java Virtual Machine):-
Role: The JVM is the engine that executes Java bytecode. It is platform-specific and ensures Java’s “write once, run anywhere” capability by providing a consistent runtime environment across different operating systems.
How It Works:
- The Java compiler (
javac) converts Java source code into bytecode (.classfiles). - The JVM loads the bytecode and interprets or compiles it into machine-specific instructions using a Just-In-Time (JIT) compiler.
- The JVM executes the machine code on the host system.
Key Features:
- Memory Management: Handles memory allocation and garbage collection.
- Platform Independence: Bytecode can run on any system with a compatible JVM.
- Security: Provides a secure execution environment by isolating Java applications from the underlying system.
2. JRE (Java Runtime Environment)
Role: The JRE provides the environment necessary to run Java applications. It includes the JVM and standard libraries but does not include development tools like the compiler or debugger.
Get SIDDHARTH SHARMA’s stories in your inbox
Join Medium for free to get updates from this writer.
How it Works:
- JVM (Java Virtual Machine): Executes Java bytecode.
- Standard Libraries: Predefined classes and methods (e.g.,
java.lang,java.util) that provide common functionality. - Other Libraries: Additional libraries required for running Java applications.
When to Use:
- End-users or systems that only need to run Java applications (not develop them) use the JRE.
JDK (Java Development Kit)
Role: The JDK is a software development kit used to develop Java applications. It provides all the tools, executables, and libraries needed to compile, debug, and run Java programs.
Components:
- Compiler (
javac): Converts Java source code (.javafiles) into bytecode (.classfiles). - Debugger: Helps developers find and fix errors in their code.
- Java Runtime Environment (JRE): Included in the JDK to run Java applications.
- Other Tools: Includes tools like
javadoc(for generating documentation),jar(for packaging files), andjdb(for debugging).
When to Use:
- Developers use the JDK when writing, compiling, and testing Java applications.
WHY ONLY ONE PUBLIC CLASS IN JAVA FILE IS Allowed?
1.Jvm Starts execution from Main method and main method is static so it should be inside public class.
2.each file name should be same as public class Name.
Now lets suppose in one file we have 100 classes then JVM will confuse which class I need to check so java bound us to have only one public class in a file.
JAVA EDITION:-
Java SE (Standard Edition)
Java SE provides the core functionality of the Java programming language, including libraries, APIs, and the JVM, for developing desktop, command-line, and lightweight server applications.
Java EE (Enterprise Edition)
Java EE is an extension of Java SE, offering additional APIs and frameworks (like Servlets, JSP, EJB, and JPA) for building scalable, secure, and robust enterprise-level web and server applications.
Java ME (Micro Edition)
Java ME is a stripped-down version of Java designed for developing applications on resource-constrained devices like mobile phones, embedded systems, and IoT devices.







