|
1 | | -static,public class MyClass { |
2 | | - static int classVariable = 0; |
3 | | - int instanceVariable; |
4 | 1 |
|
5 | | - public static void classMethod() { |
6 | | - System.out.println("This is a static method."); |
7 | | - } |
8 | | - |
9 | | - static { |
10 | | - System.out.println("Static initialization block executed."); |
11 | | - classVariable = 10; |
12 | | - } |
13 | | - |
14 | | - public MyClass(int instanceVariable) { |
15 | | - this.instanceVariable = instanceVariable; |
16 | | - } |
17 | | - |
18 | | - public static void main(String[] args) { |
19 | | - MyClass.classMethod(); |
20 | | - MyClass obj1 = new MyClass(5); |
21 | | - MyClass obj2 = new MyClass(15); |
22 | | - System.out.println("obj1.classVariable: " + obj1.classVariable); |
23 | | - obj1.classVariable = 20; |
24 | | - System.out.println("obj2.classVariable: " + obj2.classVariable); |
25 | | - } |
26 | | -} |
27 | | -final,public class MyClass { |
28 | | - final int constantValue = 10; |
29 | | - |
30 | | - public final void myMethod() { |
31 | | - System.out.println("This is a final method."); |
32 | | - } |
33 | | -} |
34 | | - |
35 | | -final class FinalClass { } |
36 | | - |
37 | | -class SubClass extends MyClass { |
38 | | - // public void myMethod() { } // Error: Cannot override final method |
39 | | -} |
40 | | - |
41 | | -public class Main { |
42 | | - public static void main(String[] args) { |
43 | | - MyClass obj = new MyClass(); |
44 | | - System.out.println(obj.constantValue); |
45 | | - } |
46 | | -} |
47 | | -abstract,abstract class MyAbstractClass { |
48 | | - public abstract void myAbstractMethod(); |
49 | | - public void myConcreteMethod() { |
50 | | - System.out.println("This is a concrete method."); |
51 | | - } |
52 | | -} |
53 | | - |
54 | | -class MySubClass extends MyAbstractClass { |
55 | | - @Override |
56 | | - public void myAbstractMethod() { |
57 | | - System.out.println("Implementation of myAbstractMethod."); |
58 | | - } |
59 | | -} |
60 | | - |
61 | | -public class Main { |
62 | | - public static void main(String[] args) { |
63 | | - MySubClass obj = new MySubClass(); |
64 | | - obj.myAbstractMethod(); |
65 | | - obj.myConcreteMethod(); |
66 | | - } |
67 | | -} |
68 | | -synchronized,public class Counter { |
69 | | - private int count = 0; |
70 | | - |
71 | | - public synchronized void increment() { |
72 | | - count++; |
73 | | - } |
74 | | - |
75 | | - public int getCount() { |
76 | | - return count; |
77 | | - } |
78 | | - |
79 | | - public static void main(String[] args) throws InterruptedException { |
80 | | - Counter counter = new Counter(); |
81 | | - Runnable task = () -> { |
82 | | - for (int i = 0; i < 1000; i++) { |
83 | | - counter.increment(); |
84 | | - } |
85 | | - }; |
86 | | - |
87 | | - Thread t1 = new Thread(task); |
88 | | - Thread t2 = new Thread(task); |
89 | | - t1.start(); |
90 | | - t2.start(); |
91 | | - t1.join(); |
92 | | - t2.join(); |
93 | | - System.out.println("Final count: " + counter.getCount()); |
94 | | - } |
95 | | -} |
96 | | -volatile,public class Worker { |
97 | | - private volatile boolean running = true; |
98 | | - |
99 | | - public void start() { |
100 | | - new Thread(() -> { |
101 | | - while (running) { |
102 | | - System.out.println("Worker is running..."); |
103 | | - try { |
104 | | - Thread.sleep(500); |
105 | | - } catch (InterruptedException e) { |
106 | | - e.printStackTrace(); |
107 | | - } |
108 | | - } |
109 | | - System.out.println("Worker has stopped."); |
110 | | - }).start(); |
111 | | - } |
112 | | - |
113 | | - public void stop() { |
114 | | - running = false; |
115 | | - } |
116 | | - |
117 | | - public static void main(String[] args) throws InterruptedException { |
118 | | - Worker worker = new Worker(); |
119 | | - worker.start(); |
120 | | - Thread.sleep(3000); |
121 | | - worker.stop(); |
122 | | - Thread.sleep(1000); |
123 | | - } |
124 | | -} |
125 | | -transient,import java.io.*; |
126 | | - |
127 | | -public class MyClass implements Serializable { |
128 | | - private String regularData; |
129 | | - private transient String sensitiveData; |
130 | | - |
131 | | - public MyClass(String regularData, String sensitiveData) { |
132 | | - this.regularData = regularData; |
133 | | - this.sensitiveData = sensitiveData; |
134 | | - } |
135 | | - |
136 | | - public static void main(String[] args) { |
137 | | - MyClass |
138 | | -transient,import java.io.*; |
139 | | - |
140 | | -public class MyClass implements Serializable { |
141 | | - private String regularData; |
142 | | - private transient String sensitiveData; |
143 | | - |
144 | | - public MyClass(String regularData, String sensitiveData) { |
145 | | - this.regularData = regularData; |
146 | | - this.sensitiveData = sensitiveData; |
147 | | - } |
148 | | - |
149 | | - public static void main(String[] args) { |
150 | | - MyClass obj = new MyClass("This will be saved", "This will NOT be saved"); |
151 | | - |
152 | | - // Serialization |
153 | | - try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("data.ser"))) { |
154 | | - oos.writeObject(obj); |
155 | | - System.out.println("Object serialized."); |
156 | | - } catch (IOException e) { |
157 | | - e.printStackTrace(); |
| 2 | + "properties": { |
| 3 | + "id": { |
| 4 | + "description": "Lowercase, underscore-separated, unique identifier.", |
| 5 | + "pattern": "^[a-z0-9_]+$", |
| 6 | + "title": "Id", |
| 7 | + "type": "string" |
| 8 | + }, |
| 9 | + "name": { |
| 10 | + "description": "Human-readable format, title case with acronyms.", |
| 11 | + "title": "Name", |
| 12 | + "type": "string" |
| 13 | + }, |
| 14 | + "full_form": { |
| 15 | + "description": "Full acronym expansion.", |
| 16 | + "title": "Full Form", |
| 17 | + "type": "string" |
| 18 | + }, |
| 19 | + "category": { |
| 20 | + "description": "Lowercase, underscore-separated.", |
| 21 | + "pattern": "^[a-z0-9_]+$", |
| 22 | + "title": "Category", |
| 23 | + "type": "string" |
| 24 | + }, |
| 25 | + "layer": { |
| 26 | + "description": "Lowercase, underscore-separated.", |
| 27 | + "pattern": "^[a-z0-9_]+$", |
| 28 | + "title": "Layer", |
| 29 | + "type": "string" |
| 30 | + }, |
| 31 | + "system": { |
| 32 | + "description": "System environment or domain.", |
| 33 | + "title": "System", |
| 34 | + "type": "string" |
| 35 | + }, |
| 36 | + "utility": { |
| 37 | + "description": "Lowercase values; multiple roles supported.", |
| 38 | + "items": { |
| 39 | + "type": "string" |
| 40 | + }, |
| 41 | + "title": "Utility", |
| 42 | + "type": "array" |
| 43 | + }, |
| 44 | + "description": { |
| 45 | + "anyOf": [ |
| 46 | + { |
| 47 | + "type": "string" |
| 48 | + }, |
| 49 | + { |
| 50 | + "type": "null" |
158 | 51 | } |
159 | | - |
160 | | - // Deserialization |
161 | | - try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("data.ser"))) { |
162 | | - MyClass loadedObj = (MyClass) ois.readObject(); |
163 | | - System.out.println("Object deserialized."); |
164 | | - System.out.println("regularData: " + loadedObj.regularData); |
165 | | - System.out.println("sensitiveData: " + loadedObj.sensitiveData); // Will be null |
166 | | - } catch (IOException | ClassNotFoundException e) { |
167 | | - e.printStackTrace(); |
| 52 | + ], |
| 53 | + "default": null, |
| 54 | + "description": "Optional description of the node.", |
| 55 | + "title": "Description" |
| 56 | + }, |
| 57 | + "connections": { |
| 58 | + "anyOf": [ |
| 59 | + { |
| 60 | + "items": { |
| 61 | + "type": "string" |
| 62 | + }, |
| 63 | + "type": "array" |
| 64 | + }, |
| 65 | + { |
| 66 | + "type": "null" |
168 | 67 | } |
169 | | - } |
170 | | -} |
171 | | -native,public class NativeExample { |
172 | | - // Native method declaration (no implementation in Java) |
173 | | - public native void myNativeMethod(); |
174 | | - |
175 | | - // Load the native library (e.g., mylibrary.so or mylibrary.dll) |
176 | | - static { |
177 | | - System.loadLibrary("mylibrary"); // Library name without prefix or extension |
178 | | - } |
179 | | - |
180 | | - public static void main(String[] args) { |
181 | | - NativeExample obj = new NativeExample(); |
182 | | - obj.myNativeMethod(); // Call the native method |
183 | | - } |
184 | | -} |
185 | | -strictfp,public class StrictFPExample { |
186 | | - // strictfp method |
187 | | - public strictfp double calculate(double a, double b) { |
188 | | - return a / b; |
189 | | - } |
190 | | - |
191 | | - public static void main(String[] args) { |
192 | | - StrictFPExample obj = new StrictFPExample(); |
193 | | - double result = obj.calculate(10.0, 3.0); |
194 | | - System.out.println("Result: " + result); |
195 | | - } |
| 68 | + ], |
| 69 | + "default": null, |
| 70 | + "description": "Optional list of connected node IDs.", |
| 71 | + "title": "Connections" |
| 72 | + }, |
| 73 | + "domain": { |
| 74 | + "anyOf": [ |
| 75 | + { |
| 76 | + "type": "string" |
| 77 | + }, |
| 78 | + { |
| 79 | + "type": "null" |
| 80 | + } |
| 81 | + ], |
| 82 | + "default": null, |
| 83 | + "description": "Optional domain the node belongs to.", |
| 84 | + "title": "Domain" |
| 85 | + }, |
| 86 | + "thresholds": { |
| 87 | + "anyOf": [ |
| 88 | + { |
| 89 | + "additionalProperties": { |
| 90 | + "type": "number" |
| 91 | + }, |
| 92 | + "type": "object" |
| 93 | + }, |
| 94 | + { |
| 95 | + "type": "null" |
| 96 | + } |
| 97 | + ], |
| 98 | + "default": null, |
| 99 | + "description": "Optional thresholds for triggering actions.", |
| 100 | + "title": "Thresholds" |
| 101 | + }, |
| 102 | + "status": { |
| 103 | + "anyOf": [ |
| 104 | + { |
| 105 | + "type": "string" |
| 106 | + }, |
| 107 | + { |
| 108 | + "type": "null" |
| 109 | + } |
| 110 | + ], |
| 111 | + "default": null, |
| 112 | + "description": "Optional status indicator, e.g., active, deprecated.", |
| 113 | + "title": "Status" |
| 114 | + }, |
| 115 | + "tags": { |
| 116 | + "anyOf": [ |
| 117 | + { |
| 118 | + "items": { |
| 119 | + "type": "string" |
| 120 | + }, |
| 121 | + "type": "array" |
| 122 | + }, |
| 123 | + { |
| 124 | + "type": "null" |
| 125 | + } |
| 126 | + ], |
| 127 | + "default": null, |
| 128 | + "description": "Optional list of tags or keywords.", |
| 129 | + "title": "Tags" |
| 130 | + } |
| 131 | + }, |
| 132 | + "required": [ |
| 133 | + "id", |
| 134 | + "name", |
| 135 | + "full_form", |
| 136 | + "category", |
| 137 | + "layer", |
| 138 | + "system", |
| 139 | + "utility" |
| 140 | + ], |
| 141 | + "title": "Node", |
| 142 | + "type": "object" |
196 | 143 | } |
0 commit comments