Java Data Types
“Data types are those which are used for allocating sufficient amount of memory space in the main memory of the computer for the input of the program either by following static memory allocation (or) dynamic memory allocation”
In every programming language data types are classified in to three types they are
a) Fundamental / pre-defined data types
b) Derived data types
c) User/programmer/secondary/customized data types
In every programming language data types are classified in to three types they are
a) Fundamental / pre-defined data types
b) Derived data types
c) User/programmer/secondary/customized data types
Fundamental data types are those which are developed by language vendors and whose variable allows us to store only one value but they never allows us to multiple values of same type.
Ex: -
int a; // valid
a = 10; // valid
a = 10, 20, 30; // invalid
Derived data types are those whose variables allow us to store multiple values of same type but they never allow us to store multiple values of different type.
Ex: -
int a [] = {10, 20, 30}; // valid
int b [] = {10, 10.75, ‘A’}; // invalid
user-defined data types are those which are developed by programmers by making use of language features and whose variables allow us to store multiple values either of same type (or) different type (or) both the types.
In ‘c’ language we use structures (struct), unions etc… for development of user-defined data types
In java programming language we use classes and interfaces for development of user-defined data types
Student so = new Student ();
Ex: -
int a; // valid
a = 10; // valid
a = 10, 20, 30; // invalid
Derived data types are those whose variables allow us to store multiple values of same type but they never allow us to store multiple values of different type.
Ex: -
int a [] = {10, 20, 30}; // valid
int b [] = {10, 10.75, ‘A’}; // invalid
user-defined data types are those which are developed by programmers by making use of language features and whose variables allow us to store multiple values either of same type (or) different type (or) both the types.
In ‘c’ language we use structures (struct), unions etc… for development of user-defined data types
In java programming language we use classes and interfaces for development of user-defined data types
Student so = new Student ();
Java Fundamental Data types: -
In java programming fundamental data types are 8 types which are categorized in to 4 categories they are
1. Integer category data type
2. Float category data type
3. Character category data type
4. Boolean category data type
Integer category data type: -
The basic aim of integer category data type is to store integer data in the main memory of the computer by allocating sufficient amount of memory space.
Integer category data types are classified in to 4 types and they types and they are given in the following table.
In java programming fundamental data types are 8 types which are categorized in to 4 categories they are
1. Integer category data type
2. Float category data type
3. Character category data type
4. Boolean category data type
Integer category data type: -
The basic aim of integer category data type is to store integer data in the main memory of the computer by allocating sufficient amount of memory space.
Integer category data types are classified in to 4 types and they types and they are given in the following table.
Integer category data types are four and selecting an appropriate data type is mandatory for the java programmer to select an appropriate data type, as a programmer we need to find the range of any data type.
Float category data type: -
The basic aim of float category data type is to store real constant values in the main memory of the computer by allocating sufficient amount id memory space.
Float category contains 2 types of data types they are given in the following table.
The basic aim of float category data type is to store real constant values in the main memory of the computer by allocating sufficient amount id memory space.
Float category contains 2 types of data types they are given in the following table.
If we store any real constant value in the variable of float data type then float data type stores the real constant values in the main memory, in such a way that after the dot (.) it takes seven decimal places and every real constant value must be followed by the letter f in java programming.
Ex: -
float f1=3.45f;
If you want to store any real constant value in a variable of double data type then the real constant value stored in the main memory, in such a way that after the dot(.) it takes fifteen decimals and the real constant value may (or) may not be followed by their letter d.
Ex: -
double d1=3.4;
Ex: -
float f1=3.45f;
If you want to store any real constant value in a variable of double data type then the real constant value stored in the main memory, in such a way that after the dot(.) it takes fifteen decimals and the real constant value may (or) may not be followed by their letter d.
Ex: -
double d1=3.4;
Character data type:-
A character is an identifier which is enclosed with in single quote.
Ex: -
‘A’, ‘$’, ‘9’
Collection of characters/sequence of characters enclosed with in double quotes is known as String.
In order to store character data in the main memory of the computer in c,c++ and java, we use a data type called char.
In java programming char data type takes 2 bytes, where as in c,c++ programming char data type take 1byte, because java programming is available in eighteen international languages and it follows Unicode (universal code) character set & c,c++ is available only in one international language called English and it follows ASCII.
A character is an identifier which is enclosed with in single quote.
Ex: -
‘A’, ‘$’, ‘9’
Collection of characters/sequence of characters enclosed with in double quotes is known as String.
In order to store character data in the main memory of the computer in c,c++ and java, we use a data type called char.
In java programming char data type takes 2 bytes, where as in c,c++ programming char data type take 1byte, because java programming is available in eighteen international languages and it follows Unicode (universal code) character set & c,c++ is available only in one international language called English and it follows ASCII.
Boolean category data type: -
The basic aim of Boolean category data type is to store logical values. Logical values represent True (or) False.
In java programming to deal with the logical values we use a data type called Boolean.
Boolean data type of java implemented by sun micro system by using the general purpose register called Flip-flop and stores 1bit of information (1 for True and 0 for false) here true and false values are storing in registers but not in main memory of the computer so that Boolean data type of java takes zero bytes of main memory space.
In c,c++ programming the true and false values represents by using non-zero and zero values are belongs to integer data type.
Note: -
In java programming all the key words must be written in small letters.
1. The default value of integer category value is 0.
2. The default value of float category value is 0.0.
3. The default value of character category value is nothing.
4. The default value of boolean category value is false.
The basic aim of Boolean category data type is to store logical values. Logical values represent True (or) False.
In java programming to deal with the logical values we use a data type called Boolean.
Boolean data type of java implemented by sun micro system by using the general purpose register called Flip-flop and stores 1bit of information (1 for True and 0 for false) here true and false values are storing in registers but not in main memory of the computer so that Boolean data type of java takes zero bytes of main memory space.
In c,c++ programming the true and false values represents by using non-zero and zero values are belongs to integer data type.
Note: -
In java programming all the key words must be written in small letters.
1. The default value of integer category value is 0.
2. The default value of float category value is 0.0.
3. The default value of character category value is nothing.
4. The default value of boolean category value is false.
Visitors