Java Tutorial
Variables, Types and Operators
Use primitive types, strings, variables, constants and common operators.
Concept
Java variables have declared types. Primitive types such as int, double and boolean store simple values, while String is a class used for text.
Use final when a reference should not be reassigned after initialization. Operators cover arithmetic, comparison, boolean logic and assignment.
Example
int age = 21;
double fee = 6500.0;
String course = "Core Java";
boolean active = true;
System.out.println(course + " - " + age);
Type the example yourself and change at least one value. Small experiments reveal syntax and behavior faster than passive reading.
Practice Tasks
- Declare variables for name, age, fee and admission status.
- Calculate simple interest using double.
- Use comparison operators to check whether a number is positive.
Key Takeaways
- Java is statically typed.
- Choose types that match the data.
- String is an object, not a primitive.
Previous
← Java Getting Started
← Java Getting Started