By Dummy for Dummies
Write this in your text editor (e.g. VS Code) and run the program:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Hello, World!
I wanted this to be your first program so I could stuff a few important things into your mind right away.
The first two lines and the last two lines are your magical spell. Write the first two lines at the start of your code, and the last two lines (two closing brackets) at the end. Don't worry about their meaning yet.
The third line, the one with System.out.println, is where you'll write most of your code for now. That's the line that actually does something. Swap "Hello, World!" for anything, and it prints that instead.
Here are 3 things you must understand from this program:
In the first line, the third word after public class must match your file name.
HelloWorld.java? Third word must be HelloWorld.Monkeys.java? Third word must be Monkeys.Capital and small letters matter. Banana and banana are different for Java.
In the second line, you'll see the word main. This is the starting point of your program. Whenever you run code, Java looks for this keyword and starts executing from here.
Right before the golden line, a { curly bracket opens. Right after it, a } curly bracket closes. Everything inside is called the main method, your main box of code for now.
You'll deal with other boxes later too, called methods, each enclosed in their own curly brackets. But your program always executes the main method first.
That's it for your first Java program! In the next blog, we'll understand Variables and Data types.