Variables in Java
A variable in simple terms is a storage place which has some memory allocated to it. Basically, a variable used to store some form of data. Different types of variables require different amounts of memory, and have some specific set of operations which can be applied on them.
Syntax
Datatype variable_name = variable_value;- Variable name don’t start variable name with digits.
- Beginning with underscore is valid but not recommended.
- Special character not allowed in the name of variable.
- Blank or White spaces are not allowed.
- Don’t use keywords to name of you variable.
Code Snippet
//Variables in Java
public class App {
public static void main(String[] args) {
String name = "Tutor Joes";
int age = 25;
float percent = 25.25f;
char gender = 'M';
boolean married = false;
System.out.println("Name : " + name);
System.out.println("Age : " + age);
System.out.println("Percent : " + percent);
System.out.println("Gender : " + gender);
System.out.println("Married : " + married);
}
}