primitive data types in Java

Java Data Types (Primitive and Non primitive / Reference), Java Variables (Local Variables, Instance Variables and Static or Class Variables), Explicit Declaration of Data Types & Variables, Purpose of Variables, Variable naming restrictions and Data Conversion.
Post Reply
AyubHussain
Posts: 142
Joined: Fri Nov 23, 2018 2:48 am

primitive data types in Java

Post by AyubHussain » Thu Nov 29, 2018 10:04 am

What are the primitive data types in Java ?

swathi
Posts: 134
Joined: Fri Nov 23, 2018 2:52 am

Re: primitive data types in Java

Post by swathi » Thu Nov 29, 2018 10:07 am

There are eight primitive data types.

1.byte.
2.short.
3.int.
4.long.
5.float.
6.double.
7. boolean.
8.char.

AyubHussain
Posts: 142
Joined: Fri Nov 23, 2018 2:48 am

Re: primitive data types in Java

Post by AyubHussain » Tue Dec 04, 2018 10:14 am

1. Integer
Integer types can hold whole numbers such as 123 and −96. The size of the values that can be stored depends on the integer type that we choose.
The range of values is calculated as −(2n−1) to (2n−1)−1; where n is the number of bits required. For example, the byte data type requires 1 byte = 8 bits. Therefore, the range of values that can be stored in the byte data type is −(28−1) to (28−1)−1
= −27 to (27) -1
= −128 to 127

2. Floating Point
Floating point data types are used to represent numbers with a fractional part. Single precision floating point numbers occupy 4 bytes and Double precision floating point numbers occupy 8 bytes. There are two subtypes

3. Character
It stores character constants in the memory. It assumes a size of 2 bytes, but basically it can hold only a single character because char stores unicode character sets. It has a minimum value of ‘u0000’ (or 0) and a maximum value of ‘uffff’ (or 65,535, inclusive).

4. Boolean
Boolean data types are used to store values with two states: true or false.

manoj
Posts: 87
Joined: Fri Nov 23, 2018 5:29 am

Re: primitive data types in Java

Post by manoj » Thu Dec 06, 2018 8:55 am

Primitive Data Type:

There are 8 primitive data types such as byte, short, int, long, float, double, char, and boolean. Size of these 8 primitive data types wont change from one OS to other.

byte, short, int & long – stores whole numbers
float, double – stores fractional numbers
char – stores characters
boolean – stores true or false

Post Reply

Return to “Java Data Types & Variables”