English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To display the default initial value of a data type, you just need to declare a variable of the same data type and display it.
The following is a Java program used to display the initial values of DataTypes.
public class Demo { boolean t; byte b; short s; int i; long l; float f; double d; void Display() { System.out.println("boolean (Initial Value) = ") + t); System.out.println("byte (Initial Value) = ") + b); System.out.println("short (Initial Value) = ") + s); System.out.println("int (Initial Value) = ") + i); System.out.println("long (Initial Value) = ") + l); System.out.println("float (Initial Value) = ") + f); System.out.println("double (Initial Value) = ") + d); } public static void main(String[] args) { Demo d = new Demo(); System.out.println("Displaying initial values...") d.Display(); } }
Output Result
Displaying initial values... boolean (Initial Value) = false byte (Initial Value) = 0 short (Initial Value) = 0 int (Initial Value) = 0 long (Initial Value) = 0 float (Initial Value) = 0.0 double (Initial Value) = 0.0
In the above program, we declared a variable with different data types.
boolean t; byte b; short s; int i; long l; float f; double d;
To get the default initial value, simply print the variables declared above.
System.out.println("boolean (Initial Value) = ") + t); System.out.println("byte (Initial Value) = ") + b); System.out.println("short (Initial Value) = ") + s); System.out.println("int (Initial Value) = ") + i); System.out.println("long (Initial Value) = ") + l); System.out.println("float (Initial Value) = ") + f); System.out.println("double (Initial Value) = ") + d);
The default value is displayed above.