Tuesday, 15 August 2017

Java Data Type

Having a good understanding of Data types and variables is the basic step towards understanding java programming. 

The word data type refers to the type of data that can be stored in a variable. at times, Java is called a “strongly typed language” because when you declare a variable, you must specify the variable’s type. Then the compiler ensures that you don’t try to assign data of the wrong type to the variable. A data type indicates what sort of value or the type of data the variable can represents, such as integer, floating-point numbers, character, boolean or an alphanumeric string.

There are different data types listed below
  • ·        Int
  • ·        Char
  • ·        Double
  • ·        Boolean
  • ·        Short
  • ·        Long
  • ·        Float

Int data type is a 32-bit signed two's complement integer.
it stores the value between -2,147,483,648 and 2,147,484,647. But a decimal number can not be store in the ‘int‘ data type.

char data type is a single 16-bit Unicode character.
it stores the value between 0 to 65535.

double data type is a double-precision 64-bit IEEE 754 floating point.
This data type is generally used as the default data type for decimal values. usually the default choice.

Float data type is a single-precision 32-bit IEEE 754 floating point.
Float is mainly used to save memory in large arrays of floating point numbers.
Default value is 0.0f.

boolean data type represents one bit of information.
There are only two possible values : true and false.

Short data type is a 16-bit signed two's complement integer.
Minimum value is -32,768 (-2^15)
Maximum value is 32,767(inclusive) (2^15 -1)
Short data type can also be used to save memory as byte data type. A short is 2 times smaller than an int
Default value is 0.

Long data type is a 64-bit signed two's complement integer.
Minimum value is -9,223,372,036,854,775,808.(-2^63)
Maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)

So these are the data types in java.and the propoper data types uses descrease the bugs in program.in next post we will learn about java operators.


Post a Comment