summary refs log tree commit diff stats
path: root/java/text/StaticExecution.typ
diff options
context:
space:
mode:
Diffstat (limited to 'java/text/StaticExecution.typ')
-rw-r--r--java/text/StaticExecution.typ29
1 files changed, 29 insertions, 0 deletions
diff --git a/java/text/StaticExecution.typ b/java/text/StaticExecution.typ
new file mode 100644
index 0000000..00b4ed0
--- /dev/null
+++ b/java/text/StaticExecution.typ
@@ -0,0 +1,29 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.75em)
+
+#assignment(10)[
+  Write a program to show that `static` blocks get executed before any object creation and implement the use of static variable to count the number of objects.
+]
+
+#scos("StaticExecution")
+
+=== Discussion
+
+#skind[Classes, interfaces and methods used from Java standard library]
+
+- `java.util.Random` class:
+  Provides methods for generating pseudorandom numbers.
+  - `int nextInt(int)`: Returns a pseudorandom, uniformly-distributed, random number between 0 (inclusive) and provided value (exclusive).
+
+#skind[Classes and methods implemented in the program]
+
+- `StaticExample` class:
+  The class being used to demonstrate the order of execution of static block.
+  - `static int getObjectCount()`: Returns the object count of this class.
+  - Constructor `StaticExample()`: Shows a message first time it is called, i.e. when the first object is created. Increments the object count static variable.
+- `StaticExecution` class contains the main method of the program.
+  - `public static void main(String[])`: Creates a random number of objects of the `StaticExample` class and shows the number of objects created.
+
+#signature()