bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!
×
UPTO
50%
OFF!

Basic Datatypes and Variables in Java

 

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 Types Default Values Range Default Size Example
boolean False True/ False 1bit boolean b = True
char ‘\u0000’ ‘\u0000’ to ‘\uffff’ 2byte char c=’A’
byte 0 -128  (-2^7) to 127 (2^7 -1) 1byte byte  b = 12
short 0 -32,768 (-2^15)  to  32,767(2^15 -1) 2byte short s=1000
int 0 – 2,147,483,648 (-2^31)  to 2,147,483,647(2^31 -1) 2byte int i= 100000000
long 0L -9,223,372,036,854,775,808(-2^63)  to 9,223,372,036,854,775,807(2^63 -1) 8byte long l= 1000000L
float 0.0f Single-precision 32-bit IEEE 754 floating point 4byte float f = 25.9f
double 0.0d Double-precision 64-bit IEEE 754 floating point 8byte double 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!

"0 Responses on Basic Datatypes and Variables in Java"

Leave a Message

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.
top

Sales Offer

  • To avail this offer, enroll before 23rd February 2017.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free Basic Datatypes and Variables in Java.