Line At A Time
Lesson 6: Booleans
Booleans Create a true/false variable and print it.
1public static void main(String[] args) {
2 boolean isFalse = false;
3 System.out.println(isFalse);
4}
Terminal
$ javac Main.java
$ java Main
false
Every line, explained
public static void main(String[] args) {
Every Java program starts at the main method. When you run the program, Java looks for this exact line, public static void main(String[] args), and runs everything between its { and } from top to bottom.
boolean isFalse = false;
boolean declares a variable that can store only one of two values: true or false. Watch the spelling: in Java the type is boolean; writing bool (like some other languages use) will not compile.
System.out.println(isFalse);
System.out.println(...) prints whatever is inside the parentheses to the terminal, then moves to a new line. Read the name carefully: print-l-n is short for "print line". Printing a boolean shows the word true or false.
}
This closing curly brace } ends the main method. In Java every opening brace { must have a matching closing brace }.