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

Java_Data_Types

Uploaded by

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

Java_Data_Types

Uploaded by

narundba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Data Types

Primitive Data Types

1. byte:

- Size: 8 bits

- Range: -128 to 127

- Example: byte b = 10;

2. short:

- Size: 16 bits

- Range: -32,768 to 32,767

- Example: short s = 1000;

3. int:

- Size: 32 bits

- Range: -2^31 to 2^31-1

- Example: int i = 100000;

4. long:

- Size: 64 bits

- Range: -2^63 to 2^63-1

- Example: long l = 100000L;

5. float:

- Size: 32 bits

- Precision: 7 decimal digits


Java Data Types

- Example: float f = 3.14f;

6. double:

- Size: 64 bits

- Precision: 15-16 decimal digits

- Example: double d = 3.14159265359;

7. char:

- Size: 16 bits

- Represents a single character (Unicode)

- Example: char c = 'A';

8. boolean:

- Size: 1 bit

- Values: true or false

- Example: boolean flag = true;

Non-Primitive Data Types

1. String:

- Represents a sequence of characters

- Example: String str = "Hello World";

2. Arrays:

- Collection of elements of the same type


Java Data Types

- Example: int[] arr = {1, 2, 3};

3. Classes:

- User-defined types containing fields and methods

- Example: class Person { String name; int age; }

4. Interfaces:

- Abstract types defining a contract

- Example: interface Animal { void sound(); }

5. Enums:

- Represents a fixed set of constants

- Example: enum Direction { NORTH, SOUTH, EAST, WEST; }

You might also like