9:35 pm - Monday October 15, 2018

Primitive types in java with Example Program

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

Primitive types

1.     Data types:

Data types specifies the size and type of values that stores in an variable. Variables have the data types that are used for allocating memory locations to store value. Based on the data type of the variable, operating system allocates memory to store values. There are two data types in java.

  • Primitive data type
  • Reference / Object data types

1.      Primitive Data types:

              Primitive data types are the most basic data types in java. They are simple, fixed size and predefined by the programming language. The primitive data types serve as the building blocks in java for defining variables. There are 8 primitive data types,

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

Byte:

Byte is a 8-bit signed two’s complement integer. The range starts from -128 to 127. It

For Example, Byte is declared as byte b=20;

Short:

Short is a 16-bit signed two’s complement integer. The range starts from -32768 to 32767.

For example, short is declared as short s=2500;

int:

integer is a 32-bit signed two’s complement integer. The range starts from

-2,147,483,648 to 2,147,483,648.

for example, int is declared as int i=29;

char:

char is a 16-bit unsigned Unicode character. The range starts from ‘\u0000’ to ‘\uffff’.

For example, char is declared as char a=‘s’;

long:

long data type is a 64-bit signed two’s complement integer. The range starts from

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,808.

For example, long is declared as long s=5040 l.

float:

float data type is a single precision 32-bit IEEE 754 floating point.

For example, float is declared as float f=199 f;

double:

double data type is a double precision 64-bit IEEE 754 floating point.

For example, double is declared as, double d= 9999;

Boolean:

Boolean data type represents one bit of information. There are only two possible values true and false.

For example, Boolean b=true;

1.     Reference data types:

A reference variable can be used to refer to any object of the data type.

For example, student std=new std( );

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply