DEV Community

rohit juyal
rohit juyal

Posted on

Day 01 Theory behind java

My Java Learning Journey: Day 01 πŸš€

Hi everyone! πŸ‘‹ I’m Rohit, currently preparing to become a full-stack developer. My plan is to learn Java for backend and JavaScript for frontend, alternating between the two on different days. On holidays, I’ll dedicate time to building projects.

This post marks Day 01 of my Java journey. Today I focused more on the theory β€” understanding the big picture of how Java works.


How a Java Program Runs βš™οΈ

When we write and run a Java program, it undergoes following steps:

a. Writing source code

  • We write the program in Java and save it with a .java extension.
  • A project can have multiple .java files.

b. Compiling with javac

  • Java source code is compiled using the Java compiler (javac).
  • It checks for errors and converts the code into bytecode.
  • This bytecode is saved in a .class file.
  • The bytecode is platform-independent, meaning it can run on any system.

c. Running with JVM

  • The Java Virtual Machine (JVM) takes the bytecode and executes it.
  • The JVM is platform-dependent (different for different OS and hardware) but the bytecode remains the same.
  • This makes Java portable.

JDK vs JRE vs JVM πŸ”‘

This part was a little tricky, but here’s how I understood it:

  • JDK (Java Development Kit)
    Contains everything needed to develop Java applications: compiler (javac), JRE, and other tools.
    πŸ‘‰ We developers install this.

  • JRE (Java Runtime Environment)
    Provides the environment to run Java applications. Includes JVM, libraries, and other runtime tools.
    πŸ‘‰ End-users typically need this.

  • JVM (Java Virtual Machine)
    Executes the bytecode. It’s like the β€œengine” that makes Java programs run.
    πŸ‘‰ Different for each OS, but invisible to us as developers.


Key Features of Java 🌟

Here are some features that stood out to me:

a. Write Once, Run Anywhere

  • Compile once, run on any platform with JVM.

b. Backward Compatibility

  • New updates don’t break older code.

c. Security

  • We share bytecode, not the source code.
  • JVM restricts resource access (like RAM, storage) for safety.
  • If a program crashes, only the JVM crashes β€” not the whole system.

d. Multi-threading

  • Supports running multiple tasks at the same time.
  • Threading means running multiple tasks concurrently. Java implements software multi-threading, creating many threads in your program.
  • The CPU can only execute as many tasks truly in parallel as it has hardware threads (physical cores Γ— threads per core).
  • If there are more software threads than hardware threads, the OS time-slices them so all threads appear to run at the same time.

e. Object-Oriented Programming

  • Data is stored in form of object and classes.
  • This helps in many things like reusability which I will learn later.

Final Thoughts ✨

Today was all about understanding the ecosystem β€” how Java runs and what makes it powerful. I did write the code but time was limited to share it here. Kindly pardon for any error.

Thanks for reading! Please do suggest any improvement πŸ’»πŸš€


Top comments (0)