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
Understanding JavaA reference guide to all the people who need to learn or understand Java before they begin.- Features of Java: First Platform Independent LanguageJava was introduced by James Gosling at Sun Microsystems in 1995. Java being a pure object oriented language is mainly used because of its portability, a feature that makes java independent of an operating system.
- Tutorial - Declaring Array in JAVAYou can create variable of built in data type and reference variables easily. But, what will you do if you have to create many variables of the same data type?
- Best Practices to Be Followed in JAVAIf you want to be a good programmer in Java, then you need to follow certain conventions and you should be aware of some of the common things if you are a beginner. Following such conventions are a good sign of a Java...
- How to Program with Assertions in Java TechnologyAn assertion tests the assumptions made in a program. It contains a Boolean expression that returns a true or false. If the statement is correct, it will return a true and the program will pass on the correct data to...
- A Short Introduction to Java Programming Language
- Types of Access Modifiers and Ways to Declare Methods in Java Programming for Begi...
- JAVA - What You Need to Know About It
- The Secret to Understanding Objects in Java
- The 5 Pillars of Java
- Bridging the Gap Between Java and XML
- Java Programming Tutorials: The Online Give and Take
- 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.
