- 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.
Advertisements