summary refs log tree commit diff stats
path: root/java/text/ThreadsExample.typ
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-01-28 06:38:55 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-01-28 06:38:55 +0000
commitfc4d96a9e3e20f8ddf035c16fc32b1effb75481b (patch)
tree4e13b2606e94e2098d1a288b051603cfc36d983b /java/text/ThreadsExample.typ
parentcd6a9243c056710794549a1ab5d51fbdd082ce2e (diff)
downloadzadania-fc4d96a9e3e20f8ddf035c16fc32b1effb75481b.tar.gz
Complete all Java assignments
Diffstat (limited to 'java/text/ThreadsExample.typ')
-rw-r--r--java/text/ThreadsExample.typ36
1 files changed, 36 insertions, 0 deletions
diff --git a/java/text/ThreadsExample.typ b/java/text/ThreadsExample.typ
new file mode 100644
index 0000000..5e1b2c8
--- /dev/null
+++ b/java/text/ThreadsExample.typ
@@ -0,0 +1,36 @@
+#import "/template.typ": *
+#show: A => apply(A)
+#set raw(lang: "java-new")
+#set par(leading: 0.5em)
+
+#assignment(25)[
+  Write a program in Java to create three threads printing 1 to 10, then implement the program using both inheriting Thread class and implementing Runnable interface.
+]
+
+#scos("ThreadsExample")
+
+=== Discussion
+
+#skind[Classes, interfaces and methods used from Java standard library]
+
+- `java.lang.Runnable` interface:
+  - `void run()`: The method to be implemented by the class that implements this interface.
+
+- `java.lang.Thread` class:
+  - `void start()`: Causes this thread to begin execution.
+  - `static Thread currentThread()`: Returns a reference to the currently executing thread.
+  - `long getId()`: Returns the identifier of this thread.
+
+#skind[Classes and methods implemented in the program]
+  
+- Class `NumberRunnable` (implements `Runnable`):
+  - `public void run()`: Implements the `run` method of the `Runnable` interface, printing numbers.
+
+- Class `NumberThread` (extends `Thread`):
+  - `public void run()`: Implements the `run` method of the `Thread` class, printing numbers.
+
+- Main program:
+  - Class `ThreadsExample`:
+    - `public static void main(String[])`: Demonstrates multi-threading using both `Thread` and `Runnable` approaches, creating and starting threads to print numbers.
+  
+#signature()