Variables; integer values with `int`
Java is a statically-typed language, which means that you must explicitly create each variable and tell what type of data (for example, an integer) that variable will store before using it.
We'll cover the following...
Here is an example of creating and using a variable that will store an integer value:
Press + to interact
class FortyTwo {public static void main(String args[]) {int meaningOfLife;meaningOfLife = 42;System.out.println(meaningOfLife);}}
Variable declaration
The statement int meaningOfLife
is called a variable declaration and it causes Java to reserve a space in memory to hold an integer value; it names that space meaningOfLife
. In languages like Python or Javascript, you can skip this step, but C and C++ also ...