Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Jdk7 Primitive Data Types

Related Tutorials


 
 

Share on Google+Share on Google+

Primitive Data Types

Advertisement
In this section we will discuss about Primitive Data Types in Java 7.

Primitive Data Types

In this section we will discuss about Primitive Data Types in Java 7.

Primitive Data Type :

Primitive data types is already defined and represented by the reserved keyword. Value of primitive type don't share state with another primitive values. Java 7 supports eight primitive data types -

  1. byte
  2. short
  3. int
  4. long
  5. float
  6. double
  7. boolean
  8. char

byte : It is an 8-bit signed two's complement integer that is 1 byte.
Minimum value : -128
Maximum value : 127(inclusive)
Default value : 0
You can use it in place of int where you need to save memory space.

Example : byte value1=150, value2= -55;

short : It is 16-bit signed two's complement integer that is 2 byte.
Minimum value : -32,768
Maximum value : 32,767(inclusive)
Default value : 0
This is also used to store numeric value where you need to save memory space.

Example :  short s1=3000, s2= -2000;

int : It is 32-bit signed two's complement integer that is 4 byte.
Minimum value : -2,147,483,648
Maximum value : 2,147,483,647 (inclusive)
Default value : 0
In general we use this data types for numeric values. It is large enough to use for common purpose of our program.

Example : int num=20000;

long : It is a 64-bit signed two's complement integer that is 8 byte.
Minimum value : -9,223,372,036,854,775,808
Maximum value : 9,223,372,036,854,775,807 (inclusive)
Default value : 0L
When we need large range of values then we use it in place of int.

Example: long l=222222L;

float : It is a single-precision 32-bit IEEE 754 floating point. It takes 4 byte.
Default value : 0.0f
This is used where we want decimal representation and want to save memory space
Example : float value=111.9f;

double : It is double-precision 64-bit IEEE 754 floating point. By default we use double for decimal values.
Default value is 0.0d.

Example : double value=232.5;

boolean : It is one bit information data type. This contains only two values that are true and false. we use it for true/false conditions.
By default it is false.

Example : boolean test=true;

char : This is single 16-bit Unicode character.
Minimum value : '\u0000' (or 0)
Maximum value : '\uffff' (or 65,535 inclusive).
This is used to store any character.

Example : char ch='A';

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 18, 2012

Related Tutorials

Discuss: Primitive Data Types  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com