data-types

 Data type




Integer types

  •  Integer types can hold whole number such as 123, -97 and 6543.
  • The size of the values that can be stored depends on the integer data type we choose.
  •  Java defines four integer types: byte, short, int and long. All of these are signed it means positive or negative values. Java does not support unsigned types.

  •  It should be remember that wider data types require more time for manipulation and therefore it is advisable to use smaller data types, wherever possible.
  • For example, instead of storing number like 56 in an int type variable, we have to use a byte type variable to handle this number. This will improve the speed of execution of the program.

Floating point types

  •  Integer types can hold only whole numbers and therefore we use another type known As Floating point type to hold numbers containing fractional part such as 22.43 and -2.346 .

  • Floating-point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision.

  • There are two kinds of floating point storage float and double which represent single-and double-precision numbers, respectively.
  • Double precision types are used when we need greater precision in storage of floating point numbers.
  •  All mathematical functions such as sin,cos and sqrt return double type values.

Character type

  •  In order to store character constants in memory, java provides a character data type called char.

  • The char type assumes a size of 2 bytes but, it can hold only a single character.
Boolean type
  • Boolean type is used when we want to test a particular condition during the execution of the program.

  • There are only two values that a boolean type can take that is true or false.
  •  Boolean type is denoted by the keyword boolean and uses only one bit of storage.
  • All comparison operators return boolean type values.
  • Boolean values are often used in selection and iteration statements.
  •  The words true or false can not be used as identifiers.

No comments:

Post a Comment