Java has various value types including String
, Integer
, Double
, Boolean
, etc. Here are a few basic examples.
The usage of these data types are shown in the below code block
class Values {
public static void main(String[] args) {
// Strings, that can be added together with +.
System.out.println("Java" + " " + "Lang");
// Integer and Double
Integer sum = 1+1;
Double division = 7.0/3.0;
System.out.println("1+1 = " + sum);
System.out.println("7.0/3.0 =" + division);
//Booleans, with boolean operators as you’d expect.
System.out.println(true && false);
System.out.println(true || false);
System.out.println(!true);
}
}
Below are the commands and output.
javac Values.java
java Values
# Java Lang
# 1+1 = 2
# 7.0/3.0 = 2.3333333333333335
# false
# true
# false
Top comments (0)