-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStaticBlock.java
More file actions
36 lines (26 loc) · 767 Bytes
/
StaticBlock.java
File metadata and controls
36 lines (26 loc) · 767 Bytes
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
/**
* 36.How Static block working in java Program
*
* Demonstrates: 1. Static block execution 2. OS validation using static block
*/
public class StaticBlock {
// First static block
static {
System.out.println("Static block is executed before main method.");
}
// Second static block for OS validation
static {
String os = System.getProperty("os.name");
if (os != null && os.toLowerCase().contains("windows")) {
System.out.println("Operating System validated successfully.");
System.out.println("Detected OS: " + os);
} else {
System.out.println("This application supports only Windows OS.");
System.exit(1);
}
}
// Main method
public static void main(String[] args) {
System.out.println("Main method is executed.");
}
}