Java Data Types

  • The data types are divided into two types:
  • Primitive datatype
  • Non – primitive datatype
  • Primitive datatype defines the size and value of the variable.
  • There are eight types of primitive data types that Java offers us
  • They are:
  • Int – 4 bytes
  • Float – 4 bytes
  • Char – 2 bytes
  • Byte – 1 byte
  • Short – 2 bytes
  • Long – 8 bytes
  • Boolean – 1 bit
  • Double – 8 bytes

Let us discuss about all the datatypes one by one:

  • Byte: It stores whole numbers from -128 to 127. It replaces int or any other integer types to save memory in the range of -128 to 127.
  • Int: It includes the whole numbers from -2147483648 to 2147483647.
  • Long: It stores whole number from -9223372036854775808 to 9223372036854775807. It includes numbers when int cannot include the numbers. It is denoted by “L”.
  • Float: It stores numbers in form of fractional number which lie between 3.4e-038 to 3.4e+038. Make sure that you are ending the value with “f” at end.
  • Double: It stores numbers in form of fractional number which lie between 1.7e-308 to 1.7e+308. Make sure that you are ending the value with “d” at end.
  • Boolean: Evaluates a condition is true or false.
  • Char or character: It is used to store a single character in single quotation marks. Char myName = ‘G’
  • Println(myName)

Alternatively, we can also predict the ASCII values.

Scroll to top