DEV Community

VINOTH
VINOTH

Posted on

Java Data Types

Java data types are mainly divided into two categories:

1.Primitive Data Types:

Some commonly used primitive data types are:

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

Primitive data types are the basic data types provided by Java. They are used to store simple values such as numbers, characters, and boolean values.

Example:

int age = 25;
double salary = 35000.50;
char grade = 'A';
boolean isActive = true;
Enter fullscreen mode Exit fullscreen mode

2.Non-Primitive Data Types:

Non-primitive data types are also called reference types.

They are used to store references to objects rather than directly storing the actual value.

  • String
  • Arrays
  • Classes
  • Objects
  • Interfaces

Example:

String name = "Vinoth";

int[] marks = {90, 85, 95};

Here, String and int[] are non-primitive data types.

We can also create our own class:

class Student {
String name;
int age;
}

Then create an object:

Student student = new Student();

Here:

Student → Class
student → Reference variable
new Student() → Object

Top comments (0)