Home » Blog » Write a Java program to display all primitive type variables. Also display your name in the last line.

Write a Java program to display all primitive type variables. Also display your name in the last line.

The basic primitive datatypes are listed below.

  1. Integer
  2. Floating Point
  3. Character
  4. Boolean

Here this types also categorized in other datatypes as follow.

  • Integer

This all stores signed, positive and negative values.

  1. byte
  2. short
  3. int
  4. long
  • Floating Point

Floating Point also known as real number are used when evaluating expression that require fraction precision.

  1. float
  2. double

Character take ASCII value. In java char is 16 bit type. The range of char is 0 to 65535. There is no negative char.

In java, boolean data type we cannot assign 0 or 1 or any numeric value to determines true or false. It strictly take true or false as value.

 

  • Example :

The below example shows the basic concept of datatypes.

class PrimitiveConcept
{
	public static void main(String args[])
	{
		byte b;
		int i;
		boolean bool;
		float f;
		double d;
		short s;
		char c;
		String str;
		b=12;
		i=2555;
		bool=true;
		f=11.23f;
		d=122.32d;
		s=3;
		c='S';
		str="TejSumeru";
		
		System.out.println("Value Of Byte Variable - "+b);
		System.out.println("Value Of Integer Variable - "+i);
		System.out.println("Value Of Boolean Variable - "+bool);
		System.out.println("Value Of Float Variable - "+f);
		System.out.println("Value Of Double Variable - "+d);
		System.out.println("Value Of Short Variable - "+s);
		System.out.println("Value Of Character Variable - "+c);
		System.out.println(str);
	}
}
  • OutPut
Value Of Byte Variable - 12
Value Of Integer Variable - 2555
Value Of Boolean Variable - true
Value Of Float Variable - 11.23
Value Of Double Variable - 122.32
Value Of Short Variable - 3
Value Of Character Variable - S
TejSumeru

 

Leave a Reply

Your email address will not be published.