0% found this document useful (0 votes)
1 views2 pages

Java Primitives Keywords

Java has 8 primitive data types including byte, short, int, long, float, double, char, and boolean. The document explains the differences between int, float, and double, highlighting their usage for whole and decimal numbers. It also covers the use of keywords in Java, which are reserved words with predefined meanings that cannot be used as variable names.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Java Primitives Keywords

Java has 8 primitive data types including byte, short, int, long, float, double, char, and boolean. The document explains the differences between int, float, and double, highlighting their usage for whole and decimal numbers. It also covers the use of keywords in Java, which are reserved words with predefined meanings that cannot be used as variable names.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Primitive Data Types and Keywords

Java's Primitive Data Types:

Java has 8 primitive data types:

1. byte - 8-bit signed integer

2. short - 16-bit signed integer

3. int - 32-bit signed integer

4. long - 64-bit signed integer

5. float - 32-bit floating point

6. double - 64-bit floating point

7. char - 16-bit Unicode character

8. boolean - true or false

Difference between int, float, and double:

1. int:

- Used to store whole numbers (integers)

- Example: int num = 25;

2. float:

- Used to store decimal numbers with single precision (less accurate)

- Must add 'f' or 'F' at the end

- Example: float price = 10.5f;

3. double:
- Used to store decimal numbers with double precision (more accurate)

- Default for decimal values

- Example: double pi = 3.14159;

Use of Keywords in Java:

Keywords are reserved words that have a predefined meaning in Java. They cannot be used as

variable names.

Examples:

1. class - Declares a class. Example: class MyClass { }

2. public - Specifies access level. Example: public void show() { }

3. static - Indicates that a method or variable belongs to the class, not instances. Example: static

int count;

4. void - Specifies that a method does not return a value. Example: public void main() { }

5. return - Used to return a value from a method. Example: return x + y;

You might also like