Thursday, 16 April 2020

SE - 52 - Primitive Vs non-Primitive data types

In Java data-types are divided into 2 sections : Primitive and non-Primitive data types

Primitive data-types : 
A primitive data type specifies the size and type of variable values, and it has no additional methods. It doesn't references a object or we need not to create a new object for primitive data types.
There are 8 primitive data types :

  • byte
  • short
  • int
  • long
  • double
  • float
  • char
  • boolean

Non-Primitive data types :
Non-primitive data types are also called reference types as they refer to a object. They are not predefined as Primitive ones. Eg : String , Array , Class, Interface , etc



Note :
String is a special type of non-primitive data type in which we can use without creating object too.


Difference :

1. Primitive types are predefined (already defined) in Java having fixed size. Non-primitive types are created by the programmer and is not defined by Java (except for String).

2. Non-primitive types can be has additional methods to perform certain operations, while primitive types does not has any methods.

3. A primitive type has always a value, while non-primitive types can be null.

4. A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase letter.

5. The size of a primitive type depends on the data type, while non-primitive types have all the same size.

6. Primitive types does not refer to any object while non-primitive  types are refered to objects


No comments:

Post a Comment