JAVA

User defined data types

User defined data types are those which are developed by programmers by making use of appropriate features of the language.

User defined data types related variables allows us to store multiple values either of same type or different type or both. This is a data type whose variable can hold more than one value of dissimilar type, in java it is achieved using class concept.

Note: In java both derived and user defined data type combined name as reference data type.

In C language, user defined data types can be developed by using struct, union, enum etc. In java programming user defined datatype can be developed by using the features of classes and interfaces.

Example

Student s = new Student();

In java we have eight data type which are organized in four groups. They are

  • Integer category data types
  • Character category data types
  • Float category data types
  • Boolean category data types

Integer category data types

These category data types are used for storing integer data in the main memory of computer by allocating sufficient amount of memory space.

Integer category data types are divided into four types which are given in following table

Data Type Size Range
Byte 1 + 127 to -128
Short 2 + 32767 to -32768
Int 4 + x to - (x+1)
Long 8 + y to - (y+1)

Character category data types

A character is an identifier which is enclosed within single quotes. In java to represent character data, we use a data type called char. This data type takes two byte since it follows Unicode character set.

Data Type Size(Byte) Range
Char 2 232767 to -32768

Why Java take 2 byte of memory for store character ?

Java support more than 18 international languages so java take 2 byte for characters, because for 18 international language 1 byte of memory is not sufficient for storing all characters and symbols present in 18 languages. Java supports Unicode but c support ascii code. In ascii code only English language are present, so for storing all English latter and symbols 1 byte is sufficient. Unicode character set is one which contains all the characters which are available in 18 international languages and it contains 65536 characters

Float category data types

Float category data type are used for representing float values. This category contains two data types, they are in the given table

Data Type Size Range Number of decimal places
Float 4 byte +2147483647 to -2147483648 8
Double 8 byte + 9.223*1018 16

Boolean category data types

Boolean category data type is used for representing or storing logical values is true or false. In java programming to represent Boolean values or logical values, we use a data type called Boolean.

Why Boolean data types take zero byte of memory ?

Boolean data type takes zero bytes of main memory space because Boolean data type of java implemented by Sun Micro System with a concept of flip - flop. A flip - flop is a general purpose register which stores one bit of information (one true and zero false).

Note: In C, C++ (Turbo) Boolean data type is not available for representing true false values but a true value can be treated as non-zero value and false values can be represented by zero




Subscribe us on Youtube

Share This Page on


Ask Question