First Steps
If you made it through the Getting Started section you've successfully run this program.
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
This "prints" - not in the sense of a physical printer, but like "displays on the screen" -
the text "Hello, World!"
.
Its a tradition for this to be your first program in any language.
Unfortunately, for reasons that are impossible to explain with the context you have at this point, half of this probably reads as cryptic nonsense.
public class Main {
public static void main(String[] args) {
I don't want it to stay cryptic nonsense, but until we get there all you truly need to know is that Java uses all of that to know where to start the program.
public class Main {
public static void main(String[] args) {
< WRITE YOUR CODE HERE >
}
}
So for all intents and purposes, this is the whole program.
System.out.println("Hello, World!");
This bit of magic here - System.out.println
- is a "statement" that "prints" the text inside the (
and )
as well as a "new line" to the screen.
print
with new l
in
e.
If you were to replace it with System.out.print
, then the output would lack that new line. This makes the following program be functionally identical to the first.
System.out.print("Hello, ");
System.out.print("World");
System.out.println("!");
Which, when we add back the part you are squinting past, looks like this.
public class Main {
public static void main(String[] args) {
System.out.print("Hello, ");
System.out.print("World");
System.out.println("!");
}
}
You should get in the habit of, whenever you see some bit of code, trying to physically type it out, run it, tweak it, and play with it.
So try playing around with this program. If you are not actively engaging then the whole thing is a bit of a wash.