Variables in Java
Variables are the containers to store the data values in the memory. Variables are naming entities and must follow naming conventions. These rules typically include starting with a letter or underscore, using letters, numbers, or underscores (no spaces or special characters), avoiding reserved keywords, and using naming conventions such as CamelCase or snake_case for readability. These conventions help keep the code organized and understandable.
Syntax:
data_type variable_name;
data_type variable_name = value;
Examples:
int myAge = 21;
String myName = "Zack";
Data Types in Java
When declaring a variable, it's essential to specify the type of data it will store, such as numbers or words. These specifications are known as data types.
There are two data types:
- Primitive Data Types:
byte
,short
,int
,long
,float
,double
,boolean
andchar
- Non-primitive Data Types: String, Arrays, and Classes
Comments
Post a Comment