 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Default value of primitive data types in Java
Primitive datatypes are predefined by the language and named by a keyword in Java. Here is an example to display the default value of primitive data types.
Example
public class Demo {    static boolean val1;    static double val2;    static float val3;    static int val4;    static long val5;    static String val6;    public static void main(String[] args) {       System.out.println("Default values.....");       System.out.println("Val1 = " + val1);       System.out.println("Val2 = " + val2);       System.out.println("Val3 = " + val3);       System.out.println("Val4 = " + val4);       System.out.println("Val5 = " + val5);       System.out.println("Val6 = " + val6);    } }  Output
Default values..... Val1 = false Val2 = 0.0 Val3 = 0.0 Val4 = 0 Val5 = 0 Val6 = null
Above, firstly we have declared variables of specific type. Remember, to get the default values, you do not need to assign values to the variable.
static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6;
Now to display the default values, you need to just print the variables.
System.out.println("Val1 = " + val1); System.out.println("Val2 = " + val2); System.out.println("Val3 = " + val3); System.out.println("Val4 = " + val4); System.out.println("Val5 = " + val5); System.out.println("Val6 = " + val6);Advertisements
 