CodeNest

Variables and strings

Java variables have explicit types:

int count = 3;
double price = 9.99;
boolean active = true;
String city = "Tokyo";

Join strings with +; numbers are converted automatically:

System.out.println(city + " has " + count + " parks");

String.format("%d items", count) works like C's printf.

Try it

Print:

Tokyo has 14 million people
Java unavailable
Next
Running Java needs a server execution engine, which isn't configured on this deployment. You can still read the lesson and try the code locally.
Loading editor…

Press Ctrl/ + Enter or click Run to see the output here.