Java by Example: Core Value Types

Java has various value types including Strings, Integers, Floats, Booleans, etc. Here are a few basic examples.

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

Strings, which can be added together with +.

    System.out.println("Java" + "Program");

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);
}
$ java CoreValueTypes
JavaProgram
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

Next example: Variables.

s