Data types in Java

Data Types in Java

Java programming language is a statically typed language, means every variable and expression has a type that is known at compile time. Hence types limit the values a variable can hold or an expression can produce, also limits the operations supported on those values and determine the meaning of the operations.

Strong static typing helps detects the errors at compile time.
There are two kinds of values which can be stored in variables, passed as an arguments, returned by methods and operated on. These are


  1. Primitive values:
    Primitive types are predefined by Java programming language and named by it’s reserved keyword.
    Primitive values do not share state with other primitive values.
    There are total eight primitive data types in Java programming language.
    Primitive types are boolean types and numeric types.
    1.1 Numeric Types:
    Numeric types further divided into integral types and floating point types.
    1.1.1 Integral Types:
    Integral type incorporates byte, short, int, long and char.
    Any value of integral type may be cast to or from any numeric type.
    There are no casts between integral types and boolean type.

1.1.2 Floating Point Type:
Any value of a floating-point type may be cast to or from any numeric type. There are no casts between floating-point types and the type boolean.


1.2 Boolean Type:
Boolean type has only two possible value these are literals true or false.
A boolean value may be cast to type boolean, Boolean, or Object. No other cast on type boolean is allowed.

2. Reference values:
The values of a reference type are references to objects. All objects, including arrays, support the methods of class Object.
String literals are represented by String objects.
For all reference types the default value is null.
There are 4 kinds of reference types:
a. class types
b. interface types
c. type variables
d. array types.

Share and Enjoy !

0 0

Leave a Reply

Your email address will not be published. Required fields are marked *