DEV Community

Cover image for Hello Java
rohit juyal
rohit juyal

Posted on

Hello Java

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");
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ž 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");
Enter fullscreen mode Exit fullscreen mode
  • 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) { }
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Output:

Hello.java  Hello.class
Enter fullscreen mode Exit fullscreen mode

Run the program

java Hello
Enter fullscreen mode Exit fullscreen mode

Output:

Hello java
Enter fullscreen mode Exit fullscreen mode

⚑ 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!");
Enter fullscreen mode Exit fullscreen mode

Output:

Hello from JShell!
Enter fullscreen mode Exit fullscreen mode

✨ 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.

Top comments (0)