-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreLanguageFeatures.java
More file actions
132 lines (120 loc) · 3.12 KB
/
Copy pathCoreLanguageFeatures.java
File metadata and controls
132 lines (120 loc) · 3.12 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package java1.core;
/**
* Java 1.0 Core Language Features Demonstrates fundamental language constructs introduced in Java 1.0
*/
public class CoreLanguageFeatures
{
public static void main(String[] args)
{
System.out.println("=== Java 1.0 Core Language Features ===\n");
System.out.println("1. Primitive Data Types");
System.out.println("----------------------");
byte b = 127;
short s = 32767;
int i = 2147483647;
long l = 9223372036854775807L;
float f = 3.14f;
double d = 3.14159;
char c = 'A';
boolean bool = true;
System.out.println("byte: " + b);
System.out.println("short: " + s);
System.out.println("int: " + i);
System.out.println("long: " + l);
System.out.println("float: " + f);
System.out.println("double: " + d);
System.out.println("char: " + c);
System.out.println("boolean: " + bool);
System.out.println("\n2. Control Flow - If-Else");
System.out.println("------------------------");
int number = 10;
if (number > 0)
{
System.out.println("Number is positive");
}
else if (number < 0)
{
System.out.println("Number is negative");
}
else
{
System.out.println("Number is zero");
}
System.out.println("\n3. Control Flow - Switch");
System.out.println("----------------------");
int day = 3;
switch (day)
{
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
default:
System.out.println("Other day");
}
System.out.println("\n4. Control Flow - For Loop");
System.out.println("-------------------------");
System.out.print("Numbers 1-5: ");
for (int j = 1; j <= 5; j++)
{
System.out.print(j + " ");
}
System.out.println();
System.out.println("\n5. Control Flow - While Loop");
System.out.println("---------------------------");
int count = 0;
System.out.print("Count 0-4: ");
while (count < 5)
{
System.out.print(count + " ");
count++;
}
System.out.println();
System.out.println("\n6. Control Flow - Do-While Loop");
System.out.println("------------------------------");
int num = 0;
System.out.print("Do-while 0-2: ");
do
{
System.out.print(num + " ");
num++;
}
while (num < 3);
System.out.println();
System.out.println("\n7. Arrays");
System.out.println("--------");
int[] numbers = {1, 2, 3, 4, 5};
System.out.print("Array elements: ");
for (int k = 0; k < numbers.length; k++)
{
System.out.print(numbers[k] + " ");
}
System.out.println();
System.out.println("\n8. Exception Handling");
System.out.println("--------------------");
try
{
int result = 10 / 2;
System.out.println("Division result: " + result);
}
catch (ArithmeticException e)
{
System.out.println("Error: " + e.getMessage());
}
finally
{
System.out.println("Finally block executed");
}
System.out.println("\nKey Features:");
System.out.println("- Platform independence");
System.out.println("- Strong typing");
System.out.println("- Exception handling");
System.out.println("- Automatic garbage collection");
System.out.println("- Object-oriented programming");
}
}