Java Data Types

Java is a Strongly Typed Language

Java is strongly typed language. Indeed, part of the Java's safety and robustness comes from this fact.

Data Types

First, every variable and expression has a type, and every type is strictly defined. Second, all the assignments, whether explicit or via the parameter passing in the method calls, are checked for the type compatibility. There are no automatic conversions of infringing types as in some languages. The Java compiler checks all the expressions and parameters to ensure that the type are compatible. Any type mismatches are errors that must be corrected before the compiler will finish compiling the class.

Java Primitive Data Types

Java defines the following eight primitive data types:

  1. byte
  2. short
  3. char
  4. int
  5. long
  6. float
  7. double
  8. boolean

The primitive data types are also commonly referred to as simple types. These can be put in the following four groups :

  1. Integers - This group included byte, short, int, and long, which are for whole-valued signed numbers.
  2. Floating-Point numbers - This group includes float and double, these represent the numbers with fractional precision.
  3. Characters - This group includes char, which represents the symbols in a character set, like letters and numbers.
  4. Booleans - This group includes boolean, which is a special type for representing the true/false values.

You can use these types as is, or to construct the arrays or your own class types. Therefore, they form the basis of all the other types of data that you can create.

Java Online Test


« Previous Tutorial Next Tutorial »