Variables and types
Primitive types, String, var, casting, and converting text to numbers.
Runs in Zerethon IDE · Java 25
Official Java documentation ↗
Main.java
public class Main {
public static void main(String[] args) {
int count = 3;
double price = 9.5;
long big = 3_000_000_000L;
boolean ready = true;
char grade = 'A';
String name = "Ada";
var total = count * price; // var: the type (double) is inferred
final int MAX = 10; // cannot be reassigned
System.out.println(count + " " + price + " " + big + " " + ready + " " + grade + " " + name);
System.out.println(total + " " + MAX);
System.out.println(7 / 2 + " " + 7 / 2.0 + " " + 7 % 2 + " " + (int) 3.99);
System.out.println(Integer.parseInt("42") + 1 + " " + Double.parseDouble("2.5") * 2 + " " + String.valueOf(7) + 7);
}
}
Output
3 9.5 3000000000 true A Ada 28.5 10 3 3.5 1 3 43 5.0 77
int / intis whole-number division (7 / 2is3); make one side adoubleto get3.5.intholds about ±2.1 billion; uselong(with anLsuffix on literals) for more.- Compare strings with
a.equals(b), nevera == b(that compares object identity).