How to write Java variable declaration
How to write a variable declaration
When declaring a variable in Java, write as follows
Data type variable name;
//Example: Declare an integer variable age and a string variable name
int age; //Integer variable age
String name; //String variable name
How to name variables
There are the following points to note when assigning variable names
- Do not use reserved words (such as the words if and void used in Java syntax)
- Do not use variable names that are already in use
- Case sensitive (eg name and Name are considered separate variables)
- It is desirable to use camel case (example: userName)