Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Java Data Types

                         

 Data type defines a set of permitted values on which the legal operations can be performed. 
In java, all the variables needs to be declared first i.e. before using a particular variable, it must be declared in the program for the memory allocation process. Like

 int pedal = 1;

This statement exists a field named "pedal" that holds the numerical value as 1. The value assigned to a variable determines its data type, on which the legal operations of java are performed. This behavior specifies that, Java is a strongly-typed programming language.

The data types in the Java programming language are divided into two categories  and can be explained using the following hierarchy structure :

 Primitive Data Types 

 The primitive data types are predefined data types, which always hold the value of the same data type, and  the values of a primitive data type don't share the state with other primitive values. These data types are named by a reserved keyword in Java  programming language. 

There are eight primitive data types supported by Java programming language :

 byte
 The byte data type is an 8-bit signed two's complement integer. It ranges from -128 to127 (inclusive). This type of data type is useful to save   memory  in large arrays.. We can also use byte instead of int  to increase the limit of the code. The syntax of declaring a byte type variable is shown as:

 byte b = 5;

 short
 The short data type is a 16-bit signed two's complement integer. It ranges from -32,768 to 32,767. short is used to save memory in large arrays. The syntax of declaring a short type variable is shown as:

 short s = 2;

 int
 
The int data type is used to store the integer values not the fraction values. It is a 32-bit signed two's complement integer data type. It ranges from -2,147,483,648 to 2,147,483,647 that is more enough to store large number in your program.  However for wider range of values use long. The syntax of declaring a int type variable is shown as:

 int num = 50;

 long
 The long data type is a 64-bit signed two's complement integer. It ranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Use this data type with larger range of values. The syntax of declaring a long type variable is shown as:

 long ln = 746; 

 float
 The float data type is a single-precision 32-bit IEEE 754 floating point. It ranges from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative). Use a float (instead of double) to save memory in large arrays. We do not use this data type for the exact values such as currency. For that we have to use java.math.BigDecimal class. The syntax of declaring a float type variable is:

 float f = 105.65;  
 float f = -5000.12;

 double
 
This data type is a double-precision 64-bit IEEE 754 floating point. It ranges from 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative). This data type is generally the default choice for decimal values. The syntax of declaring a double type variable is shown as:

 double d = 6677.60;

 char
 The char data type is a single 16-bit, unsigned Unicode character. It ranges from 0 to 65,535. They are not integral data type like int, short etc. i.e. the char data type can't hold the numeric values. The syntax of declaring a char type variable is shown as:

 char caps = 'c';   

 boolean
 The  boolean data type represents only two values: true and false and occupy is 1-bit in the memory. These values are keywords in Java and  represents the two boolean states: on or off, yes or no. We use boolean data type for specifying conditional statements as if, while, do, for. In Java, true and false are not the same as True and False. They are defined constants of the language. The syntax of declaring a boolean type variable is shown as:

 boolean result = true;

 The  ranges of these data types can be described with default values using the following table:

Data Type Default Value (for fields) Size (in bits) Minimum Range Maximum Range
 byte  0 Occupy 8 bits in memory  -128  +127
 short  0 Occupy 16 bits in memory  -32768  +32767
 int  0 Occupy 32 bits in memory  -2147483648  +2147483647
 long  0L Occupy 64 bits in memory  -9223372036854775808  +9223372036854775807
 float  0.0f Occupy 32-bit IEEE 754 floating point 1.40129846432481707e-45  3.40282346638528860e+38
 double  0.0d Occupy 64-bit IEEE 754 floating point  4.94065645841246544e-324d  1.79769313486231570e+308d
 char  '\u0000' Occupy 16-bit, unsigned Unicode character    0 to 65,535
 boolean  false Occupy 1- bit in memory  NA  NA

When we declare a field it is not always essential that we initialize it too. The compiler sets a default value to the fields which are not initialized which might be zero or null. However this is not recommended. 

 Integer Data Types

 
So far you would  have been  known about these data types. Now lets take an Integer data type in brief to better understand:

As we have told that an integer number can hold a whole number. Java provides four different primitive integer data types that can be defined as  byte, short, int, and long  that can store both positive and negative values. The  ranges of these data types can be described using the following table:

Data Type Size (in bits) Minimum Range Maximum Range
byte Occupy 8 bits in memory -128 +127
short Occupy 16 bits in memory -32768 +32767
int Occupy 32 bits in memory -2147483648 +2147483647
long Occupy 64 bits in memory -9223372036854775808 +9223372036854775807

Examples of floating-point literals are:

 0
 1
 123
 -42000

 

Floating-point numbers

A floating-point number represents a real number that may have a fractional values i.e. In the floating type of variable, you can assign the numbers in an in a decimal or scientific notation. Floating-point number have only a limited number of digits, where most values can be represented only approximately. The floating-point types are float and double with a single-precision 32-bit IEEE 754 floating point and double-precision 64-bit IEEE 754 floating point respectively. Examples of floating-point literals are:

 10.0003
  48.9
 -2000.15
 7.04e12

 

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
how to edit a any file
chaching
tesseract ocr
graphics
list is sorted or not
3DS MAX Making a Ligh
javaexampleprogramuseo
how to insert date val
struts 2 and exception
upload an image
jpanel
checkbox button enable
java button event fram
update checkbox row in
extracting day from da
java file browser
updatetable
distributed cache upda
give me some java pro
csv file format
value change listener
joining
call printer in jsp
javax.mail
download
standard
?ร??ร?ย
program of creating wa
UsingAbstractClass
j2me canvas
decimal to binary conv
JScroolPane in JTable
JQUERY
methods in java
multiple checkboxes st
usingbufferedreaderin.
hssf
remove array element
Passing Parameters in
Photoshop Photo Effect
.append
Action Class in struts
array in javascript
CSSCSSTheRevealTransFi
LazyDynaBean
array to list
Variables
covertir texte to bina
example of Jtext area
remote method invocati
multiplying all even n
java forward to page
JSP delete records in
i18n example struts2
spring mvc tutorial
3DS MAX Effects Lights
button tag
ä»??é?«??????????ä»??é
Combo Box operation in
HelloWorld.shtml
Accessing data structu
ASP.NET.NETSendingMass
creation of a director
how to check a valid e
Arrays
call ????????????????Â
Combattons la programm
algorithm for calculat
<s:ahref
example of java array
prepare statement to i
Working with EHCache
ip address programming
swith statement exampl
code for frames using
Murachதà¯?à®?à®???à®
ajax
insert image into data
login jsp
Jenia pop up jsf
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.