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.
Top comments (0)