DEV Community 👩‍💻👨‍💻

Cover image for More into Data types!
Kumar Sanskar
Kumar Sanskar

Posted on

More into Data types!

Today is day five of my learning Java journey.

Yesterday, I had learnt and shared with you the data types available in Java and the various types under the respective Primitive and Reference data type. Today, I would be sharing more in depth about each of the data types discussed in the previous post.

As we had discussed that Java has eight sub types of data types under the category of Primitive data types.

  • The types Byte, Short Int and Long can be combined under one umbrella as Integer data types.
Type Size in bits Range
byte 8 bits -127 to 128
short 16 bits -32768 to 32767
int 32 bits -2147483648 to 2147483647
long 64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • these types of integer data types have a wide implications from being as variable types in control statements, for example in loops as control variables data type to general purpose mathematics.
  • the byte and short data type are generally type-casted with (byte) or (short) so as to make it clear to compiler so as not to be mistaken with int.
  • also with large data type we use 'L' as format specifier. for example - 244368L

  • Another data type that combines two data types are Floating Point Types : -

    • it consists of float and double.
    • if you are new to programming let me break it clear for you that floating point numbers are those that have a decimal part in common language or technically those number which have a fractional component.
Type Size in bits Range
float 32 bits 1.4 E -45 to 3.402835E38
double 64 bits 1.7976931348623157 x 10308 to 4.9406564584124654 x 10-324
  • in case of data having float or double value we use format specifier 'f' or 'd' respectively. for example - 0.002f or 0.0235d.

    • Char data type:-
Type Size in bits Range
char unsigned 16 bits 0 to 65,535
  • also the ASCII values are valid as Java characters.
  • arithmetic manipulations are viable on char data type.

    • Boolean data type:-
  • it has two values true and false.

  • these true and false are defined as reserved words in Java as it defines the values true and false using these words and not like in many programming languages where false is considered as 0(zero) and true as any other value than 0.

Closing for today, and will be sharing my next learnt topic tomorrow till then keep learning, keep growing. Also feel free to give any suggestions or add up any point that I may have missed.

Top comments (0)

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<