Java Program to get the default value of primitive data types

Getting the default value of primitive data types is not a tedious task. Declare a variable with the specific datatype and display the value. This gives the default value. Do not assign a value to the variable, since we need the default.

However, first we should learn what is primitive datatype in Java. Primitive types are the Java data types used for data manipulation, for example, int, char, float, double, boolean, etc. Let’s learn about them one by one:

  • byte: An 8-bit signed two’s complement integer
    Minimum Value: -128
    Maximum Value: 127
  • short: A 16-bit signed two’s complement integer
    Minimum Value: -32768
    Maximum Value: 32767
  • int: A 32-bit signed two’s complement integer
    Minimum Value: -2,147,483,648
    Maximum Value: 2,147,483,647
  • long: A 64-bit two’s complement integer
    Minimum Value: -9,223,372,036,854,775,808
    Maximum Value: 9,223,372,036,854,775,807
  • char: A single 16-bit Unicode character.
    Minimum Value: ‘\u0000’ (or 0)
    Maximum value: ‘\uffff’
  • float: A single-precision 32-bit IEEE 754 floating point
    Minimum Value: 1.4E-45
    Maximum Value: 3.4028235E38
  • double: A double-precision 64-bit IEEE 754 floating point
    Minimum Value: 4.9E-324
    Maximum Value: 1.7976931348623157E308
  • boolean: Possible values, TRUE and FALSE.

Below are some examples to display the primitive datatypes default value in Java:

Example 1

Output

Example 2

Output

StringBuffer class in Java
Java Program to display the minimum and maximum value of primitive data types
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading