Data Types: There are two types of data types –

  • Primitive Data type
  • Non Primitive Data type

datatypes
Primitive Data Types
These are the predefined data types. In java there are 8 primitive data types which are as follows:

Data TypesDefault ValuesRangeDefault SizeExample
booleanFalseTrue/ False1bitboolean b = True
char‘\u0000’‘\u0000’ to ‘\uffff’2bytechar c=’A’
byte0-128  (-2^7) to 127 (2^7 -1)1bytebyte  b = 12
short0-32,768 (-2^15)  to  32,767(2^15 -1)2byteshort s=1000
int0– 2,147,483,648 (-2^31)  to 2,147,483,647(2^31 -1)2byteint i= 100000000
long0L-9,223,372,036,854,775,808(-2^63)  to 9,223,372,036,854,775,807(2^63 -1)8bytelong l= 1000000L
float0.0fSingle-precision 32-bit IEEE 754 floating point4bytefloat f = 25.9f
double0.0dDouble-precision 64-bit IEEE 754 floating point8bytedouble d = 152.3

 
Variable: A variable is a memory address that can change and when memory address cannot change then it is known as constant. Variable is a name of the memory location where data is stored. Once a variable is stored then space is allocated in memory. It defines a variable using a combination of numbers, letters and the underscore character.
There are three types of variables: Local, Instance and Static
Local Variable: A variable we declared inside of method called as Local variable.
e.g.

public class intellipaatclass
{
public void method()
{
int a = 10;  // Local Variable
}
}

 
Instance Variable: A variable we declared inside of class but outside of method is called instance variable. It is not declared as static.
e.g.

public class intellipaatclass
{
int a = 10;  // Instance Variable
public void method()
{
}
}

 
Static Variable: A variable that we declared as static is called static variable. It cannot be local.
e.g.

public class intellipaatclass
{
static int a = 10;  // Static Variable
public void method()
{
}
}

Learn more about Cross-Platform Mobile Technology for Android and iOS using Java in this insightful blog now!

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
6 + 25 =