Hello Java



This content originally appeared on DEV Community and was authored by Rohit Juyal

Java Learning Journey: Day 02 ✨

Date: 25 Sept, 2025

Hello everyone 👋 Today I wrote my very first Java program:

public class Hello {
    public static void main(String[] args) {
        System.out.print("Hello java");
    }
}

🔎 Breaking Down the Code

Semicolon ;

  • Tells the compiler (javac) that one instruction has ended.

Methods (Functions)

  • A method performs a specific action.
  • Methods can be predefined (like System.out.print()) or user-defined.
  • We can pass data into methods called as arguments.

👉 Example here:

System.out.print("Hello java");
  • Prints the string "Hello java".
  • "Hello java" is a string literal (just text).

Curly Braces { }

  • Used for grouping code together into a block.

Classes

  • In Java, everything lives inside a class.
  • Hello is our class name.
  • Convention: class names start with a capital letter.

💡 Important:

  • If a class is declared public, the filename must match the class name.
  • Public class → Hello.java ✅
  • Non-public class → filename can be anything (but best practice is to match).
  • No matter what it will name bytecode file same as class name.
    Remember:

  • We compile files (javac Hello.java)

  • We run classes (java Hello)

The main Method

public static void main(String[] args) { }

This is special in Java:

  • Entry point of the program.
  • Execution starts here.
  • Must be public → JVM can access it.
  • Must be static → JVM can call it without creating an object.
  • void → no return value.
  • String[] args → command-line arguments (will learn later).

👉 Without the main method, the program compiles fine, but the JVM can’t run it.

public, static, void — Quick Notes

  • public → anyone can access it.
  • static → belongs to the class, not an object (deep dive later).
  • void → no return value.

🖥 Running the Program

Compile the program

javac Hello.java
ls

Output:

Hello.java  Hello.class

Run the program

java Hello

Output:

Hello java

⚡ Bonus: JShell

I also explored JShell, a REPL (Read–Eval–Print–Loop) included in JDK.

  • Read → takes your input
  • Evaluate → runs it
  • Print → shows the result
  • Loop → waits for more commands

👉 JShell is not an IDE. Its main purpose is quick testing, not for full development.

Example in JShell

jshell> System.out.println("Hello from JShell!");

Output:

Hello from JShell!

✨ Takeaway

  • Wrote and ran my first Java program 🎉
  • Got basic introduction to some keywords.
  • Learned how to compile/run from terminal.
  • Got introduced to JShell for quick testing.

Next up: For tomorrow, I will be doing front-end basics.🚀

Self notes

  • I am happy that I am better than yesterday but it is long jouney ahead. Today day 2 I did my best with what time I got, as I was busy in some personal stuff. I wasted much time in choosing ide, later realising it doesn’t matter. Somethings are better learned in hard way. I will be careful in future. Above notes are what I understand about the topics, they may be wrong. Thanks for reading.


This content originally appeared on DEV Community and was authored by Rohit Juyal