Values

Java has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

public class Values {
    public static void main(String[] args) {
        // Strings, which can be concatenated with +
        System.out.println("java" + "lang");

        // Integers and floats
        System.out.println("1+1 = " + (1 + 1));
        System.out.println("7.0/3.0 = " + (7.0 / 3.0));

        // Booleans, with boolean operators as you'd expect
        System.out.println(true && false);
        System.out.println(true || false);
        System.out.println(!true);
    }
}

To run the program, compile the code into a .class file and then use java to execute it.

$ javac Values.java
$ java Values
javalang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

Now that we have seen how to handle values in Java, let’s move on to more advanced topics.