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.

Datatype variable_name = variable_value;

To store the numeric value 25 in a variable named "a":
int a = 25;

Variables Rules:

  • 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.

Source Code

import java.lang.*;
class variables
	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);


Name        : Tutor Joes
Age         : 25
Percent     : 25.25
Gender      : M
Married     : false
To download raw file Click Here

Basic Programs