0 day streak
java / beginner
Snippet

Variables and Data Types

In Java, you must declare the type of a variable before using it. Common types include int for integers, String for text, double for decimal numbers, and boolean for true/false values.

snippet.java
java
1
2
3
4
int age = 25;
String name = "Alex";
double price = 19.99;
boolean isJavaFun = true;
Breakdown
1
int age = 25;
Declares an integer variable named 'age' and assigns it the value 25.
2
String name = "Alex";
Creates a String object to store text.