0% found this document useful (0 votes)
141 views

Datatypes in Java

Java has both primitive and non-primitive data types. Primitive types include boolean, byte, short, int, long, char, float, and double. Non-primitive types include String, Array, Class, and Interface. The sizes of primitive types are: boolean (1 bit), char (2 bytes), byte (1 byte), short (2 bytes), int (4 bytes), long (8 bytes), float (4 bytes), and double (8 bytes). Float stores 6 decimal places while double stores 15. By default, decimal numbers are double. Unicode supports different character encoding formats like UTF-8, UTF-16, and UTF-32 to represent various languages.

Uploaded by

REAL world
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Datatypes in Java

Java has both primitive and non-primitive data types. Primitive types include boolean, byte, short, int, long, char, float, and double. Non-primitive types include String, Array, Class, and Interface. The sizes of primitive types are: boolean (1 bit), char (2 bytes), byte (1 byte), short (2 bytes), int (4 bytes), long (8 bytes), float (4 bytes), and double (8 bytes). Float stores 6 decimal places while double stores 15. By default, decimal numbers are double. Unicode supports different character encoding formats like UTF-8, UTF-16, and UTF-32 to represent various languages.

Uploaded by

REAL world
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

PROGRAMMING IN JAVA

Data types in java


• Data types means which define which type of
data we are using in the program.
• To declare the variable
• Can be Categorize in primitivies and non
primitives
• Primitives means user define and non
primitive means user has to define
Data types in Java

Primitive Non primitive


• Boolean • String
• Byte • Array
• Short • Class
• Int • Interface
• Long
• Char
• Float
• Double
Data types and its size
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


• float a=10.123456789
• double b=10.123456789
In both which one is correct and why?
• float a=10.123456789f
• double b=10.123456789
Output …?
System.out.println(a)
System.out.println(b)
• Float can store 6 digit after decimal points
• Double can store 15 digit after decimal points
• By default decimal will store double means
If we write Pi=3.14
It will store double datatype
Size calculation
• Formula:
- 2n-1 To + 2n-1-1
Where n is no. of bits.

• For example:
Byte = 1 byte=8 bits
-28-1 To 28-1 -1
-128 to +127
byte num=-129 (not accepted)
byte num=128 (not accepted)
Unicode
• Unique code for each character
• We can use any language character
• Can be categories in
UTF-8. UTF-16 and UTF-32
Unicode Transformation Format
UTF-8 means: 28 =256 types of character supported
UTF-16 means: 216 =65536 types of characters
UTF-32 means: 232 = 4294967296 types of charcters
• As compare with ASCII (American Standard Code
Information Interchange) , ASCII support only 256

You might also like