Androidberry logo
AndroidBerry Home
  • Learn Java
  • Java Programs
  • Androidberry Facebook connect
  • Androidberry twitter connect
  • Androidberry Google Plus connect

Java Tutorials


Basic Introduction

What is Java?
Java Features
Java vs Other Languages
Java on Internet
Java Components
Java First Program
Java Commandline argument
Java Constants
Java Variables
Java Types of Variables
Java Datatypes
Java Getting Input from User
Java Typecasting
Java Operators
Java Math Functions

Decision Making

Java if statement
Java if-else statement
Java nested if-else
Java else-if ladder
Java Switch case statement
Java Nested Switch Case
Java Ternary/Conditional operator

Looping

Java while loop
Java do-while loop
Java for loop
Java Enhanced loop/for each loop
Java Labelled for loop
Java Nesting of loops
Java Break and Continue

Classes and Objects

Inheritance

Interfaces

Packages

Exception Handling

Multithreading

Java Applets

Graphics Programming

More on Java

Java Programs
Java Keywords Dictionary
Java Interview Questions

Java Datatypes

The datatype specifies the size and type of data than can be stored in the memory for later use.


What are the Datatypes in java?

Datatypes in Java

Integer types

Integer types can hold whole numbers like 45672, -789. Java doesn’t support the concept of unsigned data types therefore all values in java are signed.

Java supports 4 types of integer data types as shown below.

Type Memory required to store value Minimum storage Maximum storage
byte 1 byte -128 127
short 2 bytes -32,768 32,767
int 4 bytes -2,147,483,648 2,147,483,647
long 8 bytes -9,223,372,036,854,775,808 9,223,372,036,854,775,807

Example

byte byteValue = 78;
short shortValue = 22360;
int intValue = 987654321;
int long = 922337203685477590;

If you declare a variable without assigning or with assigning a value then automatically the memory space is reserved to the respective variable


Floating types

Floating point types

Floating types can hold numbers containing fractional part such as 89.2, -12.03.
There are two types of floating point numbers in java.

Single precision value :

The float types are single precision number. Floating point numbers are treated as double precision quantities. That why append f or F to the numbers is used like – 3.14f, 9.81f

Double precision value

These are used when greater precision in storage is required. All mathematical functions, such as sin,cos and sqrt returns double type value.

Type Memory required to store value Minimum storage value Maximum storage value
float 4 bytes -3.4E-038 3.4E+038
double 8 bytes -1.7E-308 1.7E+308

By default the value is considered as double if you declared as like 83.90


Character type

Java provides the character data type called char to store single character constant in memory

Boolean type

Boolean holds only two values either true or false

following table shows the size required for storing the single values of char and boolean datatypes

Type Size Example
char 2 bytes char a = 's'
boolean 1 bit boolean b = true;

<< Previous Next >>

See Also

All Java Programs
Java Keywords
Java Interview Questions

AndroidBerry Support

About us
Contact us
Suggest us
Questions?

Follow us

Androidberry FacebookFacebook
Androidberry TwitterTwitter
Androidberry GooglePlusGoogle+
Back to top
Androidberry Name Logo