Java declaration statements are one kind of statement, where declare a variable with specifying it’s data type and name.
A variable is named container (identifier) that holds values used in a Java program. A variable can be initialize with some value and can also have calculated values from expressions which can vary over time.
Example of variable declarations in Java
The following statements are declaration of variables of int, boolean and String. Here these variables will initialize with default values.
See also: Java : Primitive Type Default Value and Range
Note: Declaration statements always end with semicolon(;).
int perk; int salary; boolean isValid; boolean isCompleted; String empFirstName; String empLastName;
In statement declaration, apart from declare variable and type we can also initialize with some literal values.
int perk=20000; int salary=50000; boolean isValid=true; boolean isCompleted=false; String empFirstName="Saurabh"; String empLastName="Gupta";
To reduce number of lines of code and more clarity, we can also declare same type, more than one variable on same line with comma separated.
int salary, perk=20000; boolean isValid=true,isCompleted; String empFirstName="Saurabh",empLastName="Gupta";