-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTypes.java
More file actions
52 lines (39 loc) · 1.74 KB
/
Copy pathDataTypes.java
File metadata and controls
52 lines (39 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package variablesanddatatypes;
public class DataTypes {
public static void main(String[] args) {
byte b = 8;
System.out.println("Byte value: " + b);
char ch = 'a';
System.out.println("Char value: " + ch);
boolean var = false;
System.out.println("Boolean value: " + var);
float price = 10.5f; // float literals must end with 'f' or 'F'
System.out.println("Float value: " + price);
int num = 25;
System.out.println("Int value: " + num);
long largeNum = 123456789L; // long literals must end with 'L' or 'l' to indicate it's a long type
System.out.println("Long value: " + largeNum);
double preciseNum = 99.99999; // double is for decimal numbers with high precision, like 3.14159265358979
System.out.println("Double value: " + preciseNum);
short n = 240;
System.out.println("Short value: " + n);
}
}
/*
Data Types (Primitive and Non-Primitive)
Primitive Data Types:
1. byte : 1 byte - Small whole numbers (–128 to 127)
2. short : 2 bytes - Medium whole numbers (–32,768 to 32,767)
3. int : 4 bytes - Standard whole numbers (~ –2B to 2B)
4. long : 8 bytes - Large whole numbers (use L at the end)
5. float : 4 bytes - Decimal numbers, less precision (use f)
6. double : 8 bytes - Precise decimal numbers (default for decimals)
7. char : 2 bytes - Single character (e.g., 'a', 'Z', '@')
8. boolean : 1 byte - true or false
Non-Primitive Data Types:
1. String : Sequence of characters (e.g., "Hello")
2. Array : Collection of elements of the same type
3. Class : Blueprint for creating objects
4. Object : Instance of a class
5. Interface : Abstract type that defines methods to implement
*/