DATA TYPES IN JAVA PROGRAMMING – tccicomputercoaching.com
- June 23, 2020
- Posted by: Riddhi Dhandha
- Category: Java course at TCCI
In this article we will learn about the java data types.
Variable is a memory location where we can store the data. There are three types of variables: local, instance and static. There are two types of data types in java, primitive and non-primitive.
Data Types in Java
In general every programming language is containing three categories of data types. They are
- Fundamental or primitive data types
- Derived data types
- User defined data types.
Primitive data types
Primitive data types are those whose variables allows us to store only one value but they never allows us to store multiple values of same type. This is a data type whose variable can hold maximum one value at a time.
|Data Type Default Value Default size boolean false 1 bit char ‘\u0000’ 2 byte byte 0 1 byte short 0 2 byte int 0 4 byte long 0L 8 byte float 0.0f 4 byte double 0.0d 8 byte The Java programming language is statically-typed, which means that all variables must first be declared before they can be used. This involves stating the variable’s type and name, as you’ve already seen: int gear = 1; int a; // valid a=10; // valid User defined data types User defined data types are those which are developed by programmers by making use of appropriate features of the language. In java both derived and user defined data type combined name as reference data type. Student s = new Student(); Integer Data Type: Data Type Size Range 1 Byte 1 + 127 to -128 2 Short 2 + 32767 to -32768 3 Int 4 + x to – (x+1) 4 Long 8 + y to – (y+1) Char Data Type|
|Char||2||232767 to -32768|
Float Data Type
|Data Type||Size||Range||Number of decimal places|
|Float||4||+2147483647 to -2147483648||8|
Boolean Data Type
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).
It’s not always necessary to assign a value when a field is declared. Fields that are declared but not initialized will be set to a reasonable default by the compiler. Generally speaking, this default will be zero or null, depending on the data type. Relying on such default values, however, is generally considered bad programming style.
User Defined Data Type:
A typedef associates a name with another data type. Here is the syntax of an IDL typedef:
typedef type identifier;
The type can be any basic IDL data type, a user-defined data structure
typedef int unit;
If you like this post then please share and like this post.
Visit us @ tccicomputercoaching.com
Call us @ 98256 18292.
Mail to email@example.com