java / beginner
Snippet
Variables and Primitive Data Types
In Java, every variable must have a declared data type. 'int' is used for whole numbers, 'String' for text, and 'double' for decimal numbers.
snippet.java
1
2
3
4
int age = 25;String name = "Java";double price = 19.99;System.out.println(name + " is " + age + " years old.");
Breakdown
1
int age = 25;
Declares an integer variable named 'age' and assigns it the value 25.
2
String name = "Java";
Creates a String object containing the text 'Java'.