|
| 1 | +# Primitive Data Types in Java |
| 2 | + |
| 3 | +This folder contains a structured guide to **primitive data types** and their **wrapper classes** in Java. It is divided into two sections: |
| 4 | + |
| 5 | +1. **Primitive Types**: The foundational data types in Java. |
| 6 | +2. **Wrapper Classes**: Object representations of primitive types. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Folder Structure |
| 11 | + |
| 12 | +### 1. **Primitive Types** |
| 13 | +The `primitive-types/` folder contains detailed explanations and examples of Java's primitive data types. |
| 14 | + |
| 15 | +| **Primitive Type** | **Description** | |
| 16 | +|---------------------|---------------------------------------------------------------------------------| |
| 17 | +| [`boolean`](./primitive-types/boolean/) | Represents true/false values. | |
| 18 | +| [`char`](./primitive-types/char/) | Represents a single character. | |
| 19 | +| [`int`](./primitive-types/int/) | Represents 32-bit integers. | |
| 20 | +| [`float`](./primitive-types/float/) | Represents 32-bit floating-point numbers. | |
| 21 | +| [`double`](./primitive-types/double/) | Represents 64-bit floating-point numbers with higher precision. | |
| 22 | + |
| 23 | +### 2. **Wrapper Classes** |
| 24 | +The `wrapper-classes/` folder contains files explaining Java's wrapper classes, which provide object-based representations of primitive data types. |
| 25 | + |
| 26 | +| **Wrapper Class** | **Primitive Type** | **Description** | |
| 27 | +|--------------------|--------------------|------------------------------------------| |
| 28 | +| [`Boolean`](./wrapper-classes/Boolean/) | `boolean` | Wraps a boolean value into an object. | |
| 29 | +| [`Character`](./wrapper-classes/Character/) | `char` | Wraps a character value into an object. | |
| 30 | +| [`Integer`](./wrapper-classes/Integer/) | `int` | Wraps an int value into an object. | |
| 31 | +| [`Float`](./wrapper-classes/Float/) | `float` | Wraps a float value into an object. | |
| 32 | +| [`Double`](./wrapper-classes/Double/) | `double` | Wraps a double value into an object. | |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Example Usage |
| 37 | + |
| 38 | +### Primitive Types |
| 39 | + |
| 40 | +```java |
| 41 | +// Example: Using primitive types |
| 42 | +boolean isJavaFun = true; |
| 43 | +char grade = 'A'; |
| 44 | +int age = 25; |
| 45 | +float price = 10.99f; |
| 46 | +double pi = 3.14159; |
| 47 | + |
| 48 | +System.out.println("Is Java fun? " + isJavaFun); |
| 49 | +System.out.println("Grade: " + grade); |
| 50 | +System.out.println("Age: " + age); |
| 51 | +System.out.println("Price: " + price); |
| 52 | +System.out.println("Pi: " + pi); |
| 53 | +``` |
| 54 | + |
| 55 | +### Wrapper Classes |
| 56 | + |
| 57 | +```java |
| 58 | +// Example: Using wrapper classes |
| 59 | +Boolean isJavaFun = Boolean.valueOf(true); |
| 60 | +Character grade = Character.valueOf('A'); |
| 61 | +Integer age = Integer.valueOf(25); |
| 62 | +Float price = Float.valueOf(10.99f); |
| 63 | +Double pi = Double.valueOf(3.14159); |
| 64 | + |
| 65 | +System.out.println("Is Java fun? " + isJavaFun); |
| 66 | +System.out.println("Grade: " + grade); |
| 67 | +System.out.println("Age: " + age); |
| 68 | +System.out.println("Price: " + price); |
| 69 | +System.out.println("Pi: " + pi); |
| 70 | +``` |
| 71 | + |
| 72 | + |
| 73 | +## Why Use Wrapper Classes? |
| 74 | +- **Object Manipulation**: Wrapper classes allow primitive values to be treated as objects. |
| 75 | +- **Utility Methods**: Provide utility methods for parsing, conversion, and manipulation. |
| 76 | +- **Collections Support**: Enables storing primitive values in data structures like ArrayList and HashMap. |
0 commit comments