Hello, Javengers!
Today we start our Java journey. Our first mission? Make Java say 'hello, world' like every other programmer before us. Why? Because it is tradition and breaking tradition means risking the wrath of ancient programmers.
The compiler I'm using today is: https://www.programiz.com/java-programming/online-compiler/
LET'S GET STARTED!!!
THE CODE
Here's the code-
public class Main{
public static void main (String[] args) {
System.out.println("hello, world!");
}
}
(Don't copy-paste this!!! Write the code on your own, that is the only way you'll learn!)
HOW IT WORKS
public class Main
- Java demands everything inside a class. Think of this as the house of your code. You can name this class whatever you want, but 'Main' is common for starting codes.
public static void main(String[] args)
This is Java's 'START HERE' button. Java only begins execution from the main
method. Java won't look at your code if you write it outside the main
function (unless you specifically tell it to!)
Think of it like a restaurant kitchen. The ingredients (your code) are there, but nothing happens until the chef (Java) finds the recipe (the main
method) and starts cooking!
NOTE- the previous 'Main
' was the name of the class. Here, 'main
' is a function.
System.out.println("hello, world")
This is a way of saying, "Hey, Java, print this on the system"
println
means print AND move to a new line. Yu can also just use print
(which means only print, don't move to the next line) and it will show the exact same output in this case.
Oh, and don’t mix up println
(small 'L') with printIn
(capital 'I')—that’s NOT a thing, and Java will yell at you. Trust me, I've been there. 😭
MY MISTAKES
I forgot semicolons (;)(EVEN THOUGH I SWORE I WON'T FORGET THEM!!) → Java is picky. Forget a semicolon, and it throws a tantrum.
I Misspelled System.out.println → Even one wrong letter and Java’s like, "I have no idea what you’re saying."
I confused 'Main' and 'main'. (of course)
I also messed up on the capitalization!!! System
, String
(have capital 'S's). public
has a small 'p'.
TASK OF THE WEEK
Alright, time to put your printing skills to the test! Your challenge:
Print your name
Print your favorite food
Print your dream vacation destination
Print them all in one fancy sentence (Example: "Hi, I'm Alex. I love pizza and I want to visit Japan!")
!!!-!!! Bonus: Try using multiple System.out.println
statements vs. just one. See the difference? Also, use just print
and see how that works!
BYE FOR NOW, JAVENGERS
That’s it for today! You’ve officially made Java talk. Next time, we’ll dive deeper into variables—because printing the same thing over and over is boring, and Java deserves better.
Make sure to practice, complete the challenge, and get ready for the next lesson. See you on Saturday!
Top comments (0)