The data types in java

By: aathishankaran Emailed: 1767 times Printed: 2515 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

The data types in java

 

            Java defines eight simple (or elemental) types of data: byte, short, int, long char, float, double, and Boolean. These can be put in four groups:

 

Integers: This group includes byte, short, int, and long, which are for whole-valued signed numbers.

 

Floating-point numbers: This group includes float and double, which represent numbers with fractional precision.

 

Characters: This group includes char, which represents symbols in a character set, like letters and numbers.

 

Boolean: This group includes Boolean, which is a special type for representing true/false values.

 

You can use these types as-is, or to construct arrays or your own class types. Thus, they form the basis for all other types of data that you can create.

 

            The simple types represent single values not complex objects. Although java is otherwise completely object-oriented, the simple types are not. They are analogous to the simple types found in most other non-object-oriented languages. The reason for this is efficiency. Making the simple types into objects would have degraded performance too much.

 

Integers

 

            Java defines four integer types: byte, short, int, and long. All of these are signed, positive and negative values, java does not support unsigned, positive-only integers. Many other computer languages support both signed and unsigned integers. However, java’s designers felt that unsigned integers were unnecessary. Specifically, they felt that the concept of unsigned was used mostly to specify the behavior of the high-order bit, which defined the sign of an int when expressed as a number.

 

            The width of an integer type should not be thought of as the amount of storage it consumes, but rather as the behavior it defines for variable and expressions of that type

 

            The width and ranges of these integer types vary widely, as shown in this table.

 

Name               Width               Range

long                  64                    -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

int                     32                    -2,147,483,648 to 2,147,483,647

short                 16                    -32,768 to 32,767

byte                  8                      -128 to 127

 

byte

 

            The smallest integer type is byte. This is a signed 8-bit type that has a range from –128 to 127. Variable of type are especially useful when you’re working with a stream of data from a network or file. They are also useful when you’re working with raw binary data that may not be directly compatible with java’s other built-in types.

 

short

            short is a signed 16-bit type. It has a range from –32,768 to 32,767. It is probably the least-used java type, since it is defined as having its high byte first (called big-endian format). This type is mostly applicable to 16-bit computers, which are becoming increasingly scarce.

 

int

            The most commonly used integer type is int. it is a signed 32-bit type that has a range from –2,147,483,647. In addition to other uses, variables of type int are commonly employed to control loops and to index arrays. Any time you have an integer expression involving bytes, shorts, ints, and literal numbers, the entire expression is promoted to int before the calculation is done.

 

            The int type is the most versatile and efficient type, and it should be used most of the time when you want to create a number for counting or indexing arrays or doing integer math.

 

long

 

            long is a signed 64-bit type and is useful for those occasions where an int type is not large enough to hold the desired value. The range of a long is quite large. This makes it useful when big, whole numbers are needed.

 


Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
A Serialization Example in Java
Type Casting in Java
instanceof sample program in Java
Using One-Dimensional Arrays in Java
Method Overriding in Java
indexOf( ) and lastIndexOf( ) in Java
The java Buzzwords
Write to a file in Java - Sample Program
XML and Java - Parsing XML using Java Tutorial
Student marks calculation program in Java
Handling Fractions in Java
Calculate average sale of the week in Java
Java program to check if user input is an even number
Using the AWS SDK for Java
How to create an array and method in JSP
Most Emailed Articles (in Java)
Converting a number into its equalant value in words in Java
java.lang.reflect package
Disadvantages of using Native methods in Java
What is UCS? What is ISO 10646?
Generating Your Key Pair example using keytool in Java
Operator Precedence in Java
PushbackReader sample program in Java
concat(), replace(), and trim() Strings in Java
instanceof sample program in Java
Use of - new - in Java
The Benefits of OOP
Increment and Decrement Operator
Characters in java
The continuing Revolution of java
Why java is important to the Internet