Loading...

Java essentialsFoundations

Variables & types

6 min lesson

Next

Java variables have declared types. Primitive types such as int store simple values, while types such as String refer to objects.

Keep in mind

Use descriptive names and choose the narrowest type that matches the value you need to represent.

Lesson.java
public class Lesson {
    public static void main(String[] args) {
        String learner = "Mina";
        int lessonsComplete = 3;
        System.out.println(learner + " completed " + lessonsComplete + " lessons");
    }
}

What happens: Mina completed 3 lessons

Previous
Next