Variables & Data Types
Understand variables, primitive data types, declarations, assignment, and basic output.
Variables & Data Types is a free Java Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Are Variables
Variables store values your program can use and change. Think of a variable as a labeled box.
- Each variable has a type that defines what it can hold.
- Names should be short and meaningful (e.g.,
count,price). - Use one variable per distinct piece of information.
Types Overview
Primitive types:
int: whole numbers (e.g., 0, 7, -12)double: decimals (e.g., 3.5, -0.25)boolean:trueorfalsechar: one character
String holds text (it is a class, not a primitive): String name = "Ada";
Declare & Assign
Declare and assign:
int count = 3;- Type then name, optional initial value.
- Change later:
count = 10; - End each statement with a semicolon.
Literals
Literals are fixed values in code.
- Integers:
0,-5,42 - Doubles:
3.14,2.0 - Booleans:
true,false
Keep lines short for mobile. Break long expressions and add spaces around operators for readability.
Printing Values
Print values with System.out.println.
System.out.println("Count: " + count);When a String is involved, + concatenates text with values.
Variables Demo
Try it: Create Main.java, paste the code, run it, then change values and run again to see output updates.
public class Main {
public static void main(String[] args) {
int count = 3;
double price = 3.5;
boolean active = true;
String product = "Book";
System.out.println("Count: " + count);
System.out.println("Price: " + price);
System.out.println("Active: " + active);
System.out.println("Product: " + product);
count = 10;
System.out.println("Updated count: " + count);
}
}
Double Declaration
Quick check: Which line declares a double variable with the value 3.5 correctly?
Recap & Next
Recap: You learned variable purpose, primitive types, declaration/assignment, literals, and printing values.
Next: Work with user input and arithmetic expressions.
Frequently asked questions
Is the “Variables & Data Types” lesson free?
Yes — the full text of “Variables & Data Types” is free to read here on the web, and the Java Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.
What will I learn in “Variables & Data Types”?
Understand variables, primitive data types, declarations, assignment, and basic output. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Java Academy?
No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.
How long does the “Variables & Data Types” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Java Academy lesson?
Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Variables & Data Types
- Input & Expressions – Part 1
- Input & Expressions – Part 2