What Is Data Types ? Discuss about Various Data Types. Write a short note on Data Types.
Data Types :-
Every variable in Java has a data type. Data types specify the size and type of values that can be stored. Java language is rich in its data types. The variety of data types available allow the programmer to select the type appropriate to the needs of the application. Data types in Java under various categories are shown in Fig. 4.2. Primitive types (also called intrinsic or built-in types are discussed in detail in this Chapter. Derived types (also known as reference types) are discussed later as and when they are encountered.
Fig.4.2
Fig.4.2
Integer Types :-
Integer types can hold whole numbers such as 123, -96, and 5639. The size of the values that can be stored depends on the integer data type we choose. Java supports four types of integers as shown in Fig. 4.3. They are byte, short, int, and long. Java does not support the concept of unsigned types and therefore all Java values are signed meaning they can be positive or negative. Table 4.3 shows the memory size and range of all the four integer data types.
It should be remembered that wider data types require more time for manipulation and therefore it is advisable to use smaller data types, wherever possible. For example, instead of storing a number like 50 in an int type variable, we must use a byte variable to handle this number. This will improve the speed of execution of the program.
We can make integers long by appending the letter L or 1 at the end of the number.
Example:
123L or 1231
Floating Point Types :-
Integer types can hold only whole numbers and therefore we use another type known as floating point type to hold numbers containing fractional parts such as 27.59 and —1.375 (known as floating point constants). There are two kinds of floating point storage in Java as shown in Fig.4.4.
Fig.4.4.
Fig.4.4.
The float type values are single.-precision numbers while the double types represent (limbic precision numbers. Table 4.4 gives the size and range of these two types.
Table 4.4
Table 4.4
Floating point numbers are treated as double-precision quantities. To force them to be in single precision mode, we must append f or F to the numbers.
Example:
1 . 2 3 f
7.56923e5F
Double-precision types are used when we need greater precision in storage of floating point numbers. All mathematical functions, such as sin, cos and sqrt return double type values.
Floating point data types support a special value known as Not-a-Number (NaN). NaN is used to represent the result of operations such as dividing zero by zero, where an actual number is not produced. Most operations that have NaN as an operand will produce NaN as a result.
Character Type :-
In order to store character constants in memory, Java provides a character data type called char. The char type assumes a size of 2 bytes but, basically, it can hold only a single character.
Boolean Type :-
Boolean type is used when we want to test a particular condition during the execution of the program. There are only two values that a Boolean type can take: true or false. Remember, both these words have been declared as keywords. Boolean type is denoted by the keyword Boolean and uses only one bit of storage.
All comparison operation return Boolean type values. Boolean values are often used in selection and iteration statement
Subscribe to:
Post Comments
(
Atom
)
Eto gulo pic ki ei answer ter?
ReplyDeleteSob gulo pic ki drawing korte Hobe?
To address the past inquiries, we will furnish our program with three kinds of structure. ExcelR Data Science Courses
ReplyDeleteIt's late finding this act. At least, it's a thing to be familiar with that there are such events exist. I agree with your Blog and I will be back to inspect it more in the future so please keep up your act.
ReplyDeletehttp://www.dbarepublic.com/2019/01/data-replication-sucks-when.html?showComment=1593762224017#c7816439684211007850
It is perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or tips. Perhaps you could write next articles referring to this article. I want to read more things about it!
ReplyDeletecyber security course training in Guwahati