Java has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
To run the program, compile it and then use java to execute:
In this example, we demonstrate various value types in Java:
Strings: In Java, strings can be concatenated using the + operator.
Integers and Floats: Java supports both integer and floating-point arithmetic.
Booleans: Java includes boolean operators for logical operations.
Note that Java uses System.out.println() for console output, which is similar in function to fmt.Println() in other languages. Also, Java requires all code to be inside a class, hence we’ve wrapped our main function in a Values class.