- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
List out the default values of numeric and non-numeric primitive data types in Java?
When you create instance variables in Java you need to initialize them, else the compiler will initialize on your behalf with default values which are −
- byte: 0
- short: 0
- int: 0
- long: 0
- float: 0.0
- double: 0.0
- boolean: false
- string: null
Example
In the following Java program prints the default values of the numeric and non-numeric primitive variables in java.
public class DefaultValues { byte byteVariable; short shortVariable; int intVariable; long longVaraible; float floatVariable; double doubleVariable; boolean boolVariable; String stringVariable; public static void main(String args[]){ DefaultValues obj = new DefaultValues(); System.out.println("Default values of numeric variables in Java:"); System.out.println("byte: "+obj.byteVariable); System.out.println("short: "+obj.shortVariable); System.out.println("int: "+obj.intVariable); System.out.println("long: "+obj.longVaraible); System.out.println("float: "+obj.floatVariable); System.out.println("double: "+obj.doubleVariable); System.out.println("Default values of non-numeric variables in Java:"); System.out.println("boolean: "+obj.boolVariable); System.out.println("string: "+obj.stringVariable); } }
Output
Default values of numeric variables in Java: byte: 0 short: 0 int: 0 long: 0 float: 0.0 double: 0.0 Default values of non-numeric variables in Java: boolean: false string: null
- Related Articles
- Convert Long to numeric primitive data types in Java
- Convert Byte to numeric primitive data types in Java
- Convert Short to numeric primitive data types in Java
- Java Program to convert Double to numeric primitive data types
- Java Program to convert Java Float to Numeric Primitive Data Types
- Default value of primitive data types in Java
- What are Primitive and Non-Primitive Data Types in JavaScript?
- How to find the correlation for data frame having numeric and non-numeric columns in R?
- How does MySQL handle out of range numeric values?
- Python Numeric Types
- Java primitive data types
- Vertically align numeric values in Java using Formatter
- Add only numeric values present in a list in Python
- Set values in categorical column to numeric values in R data frame.
- What are primitive data types in Java?

Advertisements