Variables and Data Types

After completing our first program we will study variables and data types in java. First, we will look at variables then we will move towards data types.

Variables are used to store some value in memory while the execution of the program. For example, you want to add two number it means you have to store these two numbers somewhere, so you can store these to numbers in variables. Example of defining and initialize variable in Java.

int a=10;

Data Types:-

A Data type identifies a set of values and their representation in memory and set of operations that can transform these values into other values that set. Java is a strongly typed language. It means you can not write any variable without mentioning its data type. There are two types of data types in java.

  • Primitive data types (built-in, predefined types )
  • Non Primitive data types

Primitive Types:- Which are given by keyword to us in java like int, char, float etc. You can also say it predefined or built-in data types.

booleantrue/false1bittrue or false
bytetwo’s complement integer8bits125
charUnicode character16bits‘a’, ‘k’, ‘m’, ‘l’
shorttwo’s complement integer16bits25550
inttwo’s complement integer32bits325000
longtwo’s complement integer64bits32954861L
floatIEEE 754 Floating Number32bits4.65F
doubleIEEE 754 Floating Number64bits54564.50D

Non Primitive Types: In this kind of data types variable store reference(memory address) of value instead of direct value. Examples of Non-Primitive data types are String, Object, Array.

Spread the love