Course Content
Core Java
About Lesson

Primitive Types

Primitive types in Java are predefined data types that represent simple values, and they are not objects. There are eight primitive types in Java:

  1. byte: 8-bit signed integer.
  2. short: 16-bit signed integer.
  3. int: 32-bit signed integer.
  4. long: 64-bit signed integer.
  5. float: 32-bit floating-point number.
  6. double: 64-bit floating-point number.
  7. char: 16-bit Unicode character.
  8. boolean: Represents true or false values.

Wrapper Classes

Wrapper class in Java provides the mechanism to convert primitive into object and object into primitive. They provide utility methods and constructors to convert primitive types into objects and vice versa. Each primitive type has a corresponding wrapper class:

  1. Byte: Represents byte.
  2. Short: Represents short.
  3. Integer: Represents int.
  4. Long: Represents long.
  5. Float: Represents float.
  6. Double: Represents double.
  7. Character: Represents char.
  8. Boolean: Represents boolean.

Uses of Wrapper Classe

  1. Change the value in Method: Java supports only call by value. So, if we pass a primitive value, it will not change the original value. But, if we convert the primitive value in an object, it will change the original value.
  2. java.util package: The java.util package provides the utility classes to deal with objects.
  3. Collection Framework: Java collection framework works with objects only. All classes of the collection framework (ArrayList, LinkedList, Vector, HashSet, LinkedHashSet, TreeSet, PriorityQueue, ArrayDeque, etc.) deal with objects only.
  4. Wrapper classes often define constants and enumerations for commonly used values and types, providing a convenient way to access them.
  5. Primitive types cannot be null, but wrapper classes can be null, allowing them to represent absence of value in scenarios like database operations or optional method parameters.

Scroll to Top