Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Java Variable declaration

  • int
  • boolean
  • char

With and without initialization.

public class Variables {
    public static void main(String[] args) {

        int aNumber;
        boolean aBoolean;
        char aCharacter;

        int otherNumber = 12;
        boolean otherBoolean = true;
        char otherCharacter = 'x';

        System.out.println(otherNumber);
        System.out.println(otherBoolean);
        System.out.println(otherCharacter);
    }
}
javac Variables.java
java Variables
12
true
x