Java

Advertisements

Java Variable

Variables are used to store values. variable name is the name of memory location where value is stored. It must be alphanumeric, olny underscore and dollar signs are allowed in a variable name. It must begin with alphabet or underscore or dollar sign. It can not be begin with numeric.

Declaration of Variable

Declaration will allocate memory for specific type of variable with default value.

Syntax of declaring variable in java


	Data-Type Variable-name;

Example of declaring variable in java


	int a;
	float b;
	double d;
	char c;

Initialization of Variable

Initialization means assigning value to declared variable. Every value will overwrite the previous value.

Example of initializing variable in java


	a = 10;
	b = 4.5f;
Java treat decimal value as double type, we must use f or F to force compiler to treat decimal value as float value.

	d = 4.5;
	c = 'a';
Character value must be enclosed with single quotes.

Advertisement