logo image

Java Variables

Variable holds the value during the program execution. Following is the syntax for declaring a Variable

type identifier;


int i;

Following is the syntax for Initialization

identifier = value;


i = 10;

You can do these two things in one line

int i = 10;

Let me show you a program to declare & initialize all primitive data types of Java

public class PrimiteDataTypes {

	public static void main(String[] args) {

		byte byteVal = 127;
		short shortVal = 32767;
		int intValue = 2147483647;
		long longValue = 9223372036854775807L;

		float floatValue = 1.5F;
		double doubleVaue = 12.678;

		char charValue= 'f';

		boolean booleanValue = true;