GCGrowCarrer

Variables and Primitive Types

Available

Lesson 1 of 60 · Syntax · Easy

Mastery0% of 85%
1

The big idea

A variable stores a value so your program can use it later. In Java, every variable starts with its type, followed by a name, an equals sign =, a value, and a semicolon ; at the end: Java keeps code organized inside a class block (public class Solution { ...

Think of it like this: Think of a Java variable like a labeled box with its shape printed on the side: `int` says the box holds a whole number, `x` is the label, and `5` goes inside.
Key words (tap to learn):
2

Read the lesson

A variable stores a value so your program can use it later.

In Java, every variable starts with its type, followed by a name, an equals sign =, a value, and a semicolon ; at the end:

int age = 20;         // a whole number
double price = 9.99;  // a decimal number
boolean ok = true;    // true or false

Java keeps code organized inside a class block (public class Solution { ... }). We already added that wrapper for you — just write your variable line inside the curly braces.

3

Quick check

Which line correctly creates a whole-number variable named age set to 20 in Java?

4

Your challenge

1 sample test, 1 hidden

Inside Solution, create a whole-number variable named x set to 5 (type int x = 5;).

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

Similar to javascript.variables-types (85% overlap). Variables & primitive types: compare let/const (JS), auto/int (C++), := (Go), let mut (Rust), and column types (SQL).

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Variables and Primitive Types.

Mastery0%

Learn this first

Nothing needed - you can start here.