This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: Java Data Types
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Data Types are used to store data temporarily in computer through a program
The data type will specify the type of data that will be stored into a memory location.
Definition:
The data type is something which gives information about
Size of the memory location and range of the data that can be accommodated inside that location.
Possible legal operations those can be performed on that location.
What type of result come out from an expression when we use these types inside that expression.
Whichever the keyword gives these semantics is treated as "data type".
The java language provides different categories of data types.
Different Java Data Types:
In java mainly we have two types of data types.
Primitive data types or Fundamental data types.
Referenced data types or Derived data types.
User defined data types.
1.Primitives Data types:
The primitive data types are the predefined data types given by the programming language and they are meant for storing a single value.
Based on the type and range of data, primitive types are divided into 8 types.
1.Integer category:
This category can be used for storing numbers which can be either positive value or negative value without decimal points.
In this category we have 4 primitive data types whose memory sizes are different.
All the 4 types under this category are used for storing same data. But there ranges are different. The java language is providing 4 types under Integer category. So that the memory is utilized efficiently.
byte
short
int
long
Default value for all these types is "0".
2. Floating point category:
This category can be used for storing numbers which can be either +VE or –VE with decimal point. In the floating point category we have two types whose size is different. The two data types are float and double.
Both the data types under the floating point category are used for storing same data but there range is different. The java language provide as two data types under floating point category so that memory is utilized efficiently.
Default value of float is 0
Default value of double is 0.0
float
double
3.Character category:
This category can be used for storing a single character. A character can be represented by alphabets, a digit and special symbols.
This category contains only one data type an it is char.
Default value of char is "one space"
char
4.Boolean category:
This category can be used for storing either true or false. Under the Boolean category only one data type an it is Boolean. The size is dependent on JVM to JVM.