google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Data Types in Java

Data Types in Java

1
There are two types of Language on the Basic of Data types

  1. First is Statically typed language where each variable and type of expression is already known at the time of compilation. Once a variable has been determined to be of a certain type of data it can not hold values of other types of data. Example: Java, C, C++.
  2. The other languages are written as Dynamically. Over time these languages may obtain various types of data. Eg: Ruby, Python


Java is statically typed and also a strongly typed language because in Java, each data type (such as integer, character, void, float, double and so on) is predefined as part of the programming language and all the constants or variables specified for a given program must be represented with one of the data types.

Java has two data types: 

Data Types in Java



1. Primitive Data Types :Boolean, char, int, short, byte, long, float and double

2. Non-Primitive Data Type: String, Array, Interface, Class.


Primitive Data Type/ System Defined Data Type:

Data Types in Java
There are 8 primitive data type:

1. Boolean: the boolean data type represents only one bit of true or false information, but the boolean data type is virtual machine-dependent. Boolean-type values are not converted to any other style, implicitly or explicitly (with casts). But the programmer can write the conversion code very quickly.



Syntax:

boolean booleanVar; // boolean is data type and booleanVar is a variable of boolean type.

Size:

1 byte // take 1 byte space in the memory

Values:

True or False // takes the result in True or false only

Default Value:

False // By default the Value of boolean data type is False


2. Byte: The byte data type is an 8-bit complement integer signed by two. The sort of byte data helps to save memory in large arrays.


Syntax:

byte byteVar; // byte is data type and byteVar is a variable of byte type.

Size:

1 byte // take 1 byte space in the memory

Values:

-128 to +127 // takes the result between -128 to +127 only

Default Value:

0 // Zero




3. Short: The short data form is the 16-bit complement integer signed by two. Similar to byte, in large arrays, use a short to save memory, in cases where memory savings really matter.
Syntax:

short shortVar; // short is data type and shortVar is a variable of short type.

Size:

2 byte // take 2 byte space in the memory

Values:

-32,768 to +32,767 // Range between -32,768 to +32,767 only

Default Value:

0 // Zero


4. int: It is a 32-bit signed two’s complement integer.

Syntax:

int intVar; // int is data type and intVar is a variable of int type.

Size:

4 byte // take 4 byte space in the memory

Values:

-2,143,483,648 to +2,143,483,647 // Range between -2,143,483,648 to +2,143,483,647 only

Default Value:

0 // Zero

5. long: The long data type is a 64-bit two’s complement integer.


Syntax:

long longVar; // long is data type and longVar is a variable of long type.

Size:

8 byte // take 8 byte space in the memory

Values:

-9,223,372,036,854,775,808 to +9,223,372,036,854,775,8087

Default Value:

0 // Zero

6. Float: The float data type is a single IEEE 754 floating point with 32-bit precision. If you need to conserve memory in large arrays of floating point numbers, use a float (instead of the double).


Syntax:

float floatVar; // float is data type and floatVar is a variable of float type.

Size:

4 byte // take 4 byte space in the memory

Values:

Upto 7 decimal digits

Default Value:

0.0 // Zero

7. double: double data type is a 64-bit IEEE 754 floating point with double-precision. That type of data is usually the default choice for the decimal values.


Syntax:

double doubleVar; // double is data type and doubleVar is a variable of double type.

Size:

8 byte // take 8 byte space in the memory

Values:

Upto 16 decimal digits

Default Value:

0.0 // Zero

8. char: A single 16-bit Unicode character is the form of the char data.


Syntax:

char charVar; // char is data type and charVar is a variable of char type.

Size:

2 byte // take 2 byte space in the memory

Values:

‘\u0000’  (0) to ‘\uffff’ (65535)

Default Value:

‘\u0000’



2. Non-Primitive Data Type/ System Defined Data Type:

1. String

A Java string data type is a sequence or string of connected characters (Java char data type objects). The String is also a class, meaning it has its own methods. These methods include checking for string length, transforming to upper or lower case, and replacing values in strings with other values.

2. Array 

An array is a set of elements of similar type that have a contiguous memory location. Java array is an object that contains elements of a specific type of data. Therefore, the array elements are located in a contiguous position of the memory. It is a data structure, where similar elements are stored.

3. Interface

An interface in Java is a reference type. It is a summary of abstract methods. A class implements an interface, thus inheriting interface abstract methods. An interface may also contain constants, default methods, static methods, and nested types, in addition to abstract methods.

Post a Comment

1 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top