Month End Sale: Get Extra 10% OFF on Job-oriented Training! Offer Ending in
D
H
M
S
Get Now

Data Types in Java

Level : Beginner
Mentor: Shailendra Chauhan
Duration : 00:02:00

Data Types

Data type describes the various sizes as well as values that can be stored in a variable.

Types of Data Types

Data Types can be categorized into two types:

  1. Primitive 
  2. Non-primitive

Primitive Data types

Primitive data consists of only single values and has no special capabilities.

Types of Primitive Data Types

There are 8 primitive data types:

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

Non-Primitive Datatypes (Reference Variable)

Non-primitive data types, unlike primitives, are user-defined rather than predefined, referring to locations in memory where objects exist when defined, allowing for greater programming flexibility and customization.

Types of Non-primitive data types

There are mainly 5 non-primitive data types :

  1. Arrays
  2. String
  3. Class
  4. Object
  5. Interfaces 

Type Casting

A type casting is a method for converting one data type into another. We can cast both primitive and reference data types. Only the data type can be modified; the data itself cannot.

Types of Type Casting

Java has two types of type casting:

  1. Widening casting
  2. Narrowing casting

Widening casting

A lower data type is converted to a higher one using a technique known as widening type casting. Some call it implicit type casting or casting down. It happens naturally.

Narrowing casting

Narrow type casting is the process of reducing a larger data type to a smaller one. It's also known as casting up or explicit type casting. It does not occur on its own. Narrowing type casting is risky because data loss may occur due to the lower data type's reduced range of allowable values.

Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this