- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display default initial values of DataTypes in Java
To display default initial values of a datatype, you need to just declare a variable of the same datatype and display it.
The following is a Java program to display initial values of DataTypes.
Example
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
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 have declared a variable with different datatypes.
boolean t; byte b; short s; int i; long l; float f; double d;
Now to get the default initial values, just print the variable 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 above displays the default values.
- Related Articles
- Display the limits of DataTypes in Java
- Default array values in Java
- Overflow of DataTypes in Java
- Underflow of DataTypes in Java
- Display only the default values set for columns in MySQL
- Do local variables in Java have default values?
- What are the default array values in Java?
- Replace null values with default value in Java Map
- Display the maximum of three integer values in Java
- Display the minimum of three integer values in Java
- Display Minimum and Maximum values of datatype int in Java
- Display MySQL table values using Java
- Write a C program to display all datatypes ranges in tabular form
- What are the default initialization values of elements in an array using Java?
- Default values of static variables in C

Advertisements