🎯 What is a data type?

Wikipedia says "In computer science and computer programming, a data type or simply type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support basic data types of integer numbers (of varying sizes), Floating-point numbers (which approximate real numbers), characters, and Booleans. A data type constrains the values that an expression, such as a variable or a function, might take. This data type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored. A data type provides a set of values from which an expression (i.e. variable, function, etc.) may take its values."

🎯 Types:

There are 2 types of data types in Java: Primitive and Non-Primitive. In simple words, primitive data types are predefined whereas non-primitive data types are user defined.

🎯 Primitive Datatypes:

A primitive data type specifies the size and type of variable values and has no additional methods. There are 8 primitive data types in Java: byte, short, int, long, float, double, boolean, char. Let us see how to initialize them below.

Byte

byte x=10;

Short

short x=10;

Int

int x=10;

Long

long x=10000000;

Float

float x=10f;

Double

double x=10.1010;

Boolean

boolean x=1;

Char

char c ='s';

🎯 Non-Primitive Datatypes:

Non-primitive data types are called reference types because they refer to objects. There are many non-primitive data types in Java: arrays, strings, classes etc. Let us see how to initialize an array and a string.

Array

int[] array = new int[10];

String

String s = "hello world";

Since now we know what data types are, it is important to learn the usage of these data types so that we know where to use them to solve a problem.

...To be continued! 🎉 keep learning, keep coding!💖

This post is also available on DEV.