DATA TYPES IN JAVA PROGRAMMING Tccicomputercoaching.com

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

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

Float Data Type

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

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).

Default Values

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:

Typedef

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 tccicoaching@gmail.com

To Learn More About Java course in Ahmedabad, TCCI

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s