Data Types in Java Language

Harsh Gupta - Tech Writer
The java programming language has many built-in data types. These fall into two broad categories: class type and primitive types. Primitive types are simple values, not objects. Class types are used for more complex types, including all of types that you declare yourself. Class types are used to create objects.

Primitive types:

The JAVA programming language defines eight primitive data types, which can be considered in four categories:

· Logical-Boolean

· Textual-char

· Integral- byte, short, int, and long

· Floating point- double and float

Logical-Boolean:

Logical values are represented using the Boolean type, which takes one of the two values: true or false. These values can be used to represent any two states, such as on and off, yes or no. The Boolean type has two literal values, true and false. The following code is an example of declaration and initialization of a Boolean type variable:

Boolean truth = true;

Textual-Char

Single characters are represented by using the Char type. A Char represents a 16 bit unsigned Unicode character. You must enclose the Char literal in single quotes ('). For example:

'a' The letter a

'
' A tab

Textual String

You can use a String type which is not a primitive but a class to represent sequence of characters. The characters themselves are Unicode, and the backslash notation shown previously for the Char type also works in a String. Unlike c and c++, String doesn't end with �. � is generally referred to as NULL.

A String literal is enclosed In double quote marks:

"This is a String."

Integral - byte, short, int, and long

There are four integral types in the Java programming language. Each type is declared using one of the keyword; byte, short, int or long. You can represent literal of integral type using decimal, octal or hexadecimal form as follows:

2 : This is the decimal form for the integer 2.

077 : The leading 0 indicates an octal value.

0xBAAC : The leading 0x indicates hexadecimal value.

All numeric types in the Java programming language represents signed numbers. Integral liters are of type int unless followed explicitly by the letter l that indicates a long value. In the Java programming language, you can use either an uppercase L or lowercase l. A lowercase l is not recommended because it is hard to distinguish it from digit 1.

2L : This is the decimal form for the long 2.

077L : The leading 0 indicates an octal value.

0xBAACL : The leading 0x indicates hexadecimal value.

Floating Point - float and double

You can declare a floating point variable using the keywords float or double. The following list contains examples of floating -point numbers. A numeric literal is a floating point if it includes either a decimal point or an exponent part (the letter E or e), or is followed by either F or f (float) or the letter D or d (double). Some examples of floating-point literals include:

3.14 : A simple floating-point value (A double)

6.02E23 : A large floating-point value

2.718F : A simple float size value

123.4E+306D : A large double value with redundant D

Floating-point literals are double by default. You can declare a literal of type float by appending F or f to the value. The format of a floating point number is defined by The Java Language Specification, Institute of Electrical and Electronics Engineers (IEEE) 754.

Published by Harsh Gupta - Tech Writer

I am a part time freelancer and writing is my hobby Some of my websites: http://www.GenericArticles.com http://www.JailBreakingiPhone.com  View profile

  • You can declare a floating point variable using the keywords float or double.
  • You can use a String type which is not a primitive but a class to represent sequence of characters.
Logical values are represented using the Boolean type, which takes one of the two values: true or false. These values can be used to represent any two states, such as on and off, yes or no.

To comment, please sign in to your Yahoo! account, or sign up for a new account.