JAVA - Zero to Hero / Getting Started with JAVA

Additional Notes

πŸ†” Naming Conventions

  • File name must match the public class name (e.g., Hello.java)

  • Class names β†’ PascalCase (e.g., MyFirstProgram)

  • Method and variable names β†’ camelCase (e.g., printMessage())


πŸŒ€ How Java Code Runs (Behind the Scenes)

βœ… Programmer Writes Code

  • The programmer creates a file like Hello.java.

  • This file contains Java source codeβ€”human-readable instructions.

πŸ“ File Created: Hello.java

🧠 You: Write the code using an editor (like VS Code, IntelliJ, or Notepad).


βœ… Compilation using JDK

  • The JDK (Java Development Kit) includes a compiler (javac) that converts .java into .class.

πŸ› οΈ javac Hello.java β†’ Produces β†’ Hello.class

πŸ”Ή .class file contains bytecode, which is platform-independent.


βœ… Running the Code using JRE

  • You run the code using the java Hello command.

  • This sends the .class file (bytecode) to the JRE (Java Runtime Environment).


βœ… JRE – What Happens Inside

The JRE contains:

πŸ”Έ JVM (Java Virtual Machine):

  • It reads the .class bytecode.

  • Converts it to machine-specific code (native code).

  • This is where the actual execution happens.

πŸ”Έ JIT Compiler (Just-In-Time):

  • JIT improves performance by converting frequently-used bytecode into machine code just in time for execution.

πŸ”Έ Built-in Libraries:

  • JRE also includes core Java libraries (.class files, APIs) required during execution.


βœ… Execution on the Computer

  • The JVM executes the machine code on your computer hardware (CPU, memory).

  • Finally, you see the output on your screen.


⚠️ Common Output Issue

If you see nothing or an error:

  • Check that the file name matches the class name.

  • Make sure the main method is spelled exactly like:

public static void main(String[] args)