Search⌘ K
AI Features

Variables; integer values with `int`

Explore how to declare and assign integer variables in Java by using the int data type. Understand Java’s strict typing and naming conventions like camelCase to write clearer and less error-prone code.

We'll cover the following...

Here is an example of creating and using a variable that will store an integer value:

Java
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 ...