undefined

Bonus task | Lesson 13 | Level 6

Java Core
Level 6 , Lesson 13
Available

"Hey, soldier!"

"Good day, Captain!"

"I've got awesome news for you. Here are some exercises to reinforce your skills. Do them every day and your skills will grow at an insane speed. They were created especially for IntelliJ IDEA."

"Those previous exercises were for rookies. I've added some more advanced bonus exercises for the old-timers. Just for veterans."

undefined
4
Task
Java Core, level 6, lesson 13
Locked
Thread.currentThread always returns the current thread
1. In the printMsg method, assign the current thread to the variable t. 2. In the printMsg method, add a delay of 1 millisecond after all the actions.
undefined
4
Task
Java Core, level 6, lesson 13
Locked
Consecutive threads
1. In the run method, add a delay of 10 milliseconds after all the actions. Display "Thread interrupted" if the thread is interrupted. 2. Make all the threads run sequentially: first, for thread 1, count down from COUNT to 1; then for thread 2 - from COUNT to 1, etc. Example: #1: 4 #1: 3 ... #1: 1 #
undefined
18
Task
Java Core, level 6, lesson 13
Locked
Creating threads recursively
1. Change the GenerateThread class to make it a thread. 2. Create a GenerateThread constructor, which must: 2.1. Call the superclass's constructor, passing the created thread's number as a String. Use createdThreadCount. 2.2. Start the current thread. 2.3. The thread numbers must start with 1. 3. O
undefined
4
Task
Java Core, level 6, lesson 13
Locked
Consecutive threads
1. Figure out what the program does. 2. Make the program first display the result of the thread, and when the thread has finished then the main method continues. 3. Example output: inside MyThread 0 inside MyThread 1 ... inside MyThread 9 inside main 0 inside main 1 ... inside main 9
undefined
4
Task
Java Core, level 6, lesson 13
Locked
Deadlock
1. Figure out how the program works. 2. Without changing the T1 and T2 classes, make it so their threads finish (not necessarily successfully). 3. Don't use the sleep method.
undefined
9
Task
Java Core, level 6, lesson 13
Locked
Following a pattern
Figure out how the program works. Similar to CountdownRunnable, create a CountUpRunnable thread that displays values ​​in the counting order: from 1 to number.
undefined
18
Task
Java Core, level 6, lesson 13
Locked
Shall we play?
Three people play the game. Each player (Gamer) is characterized by two parameters: last name (name) and the actions-per-second (rating). Display the actions taken and determine the winner and the losers. Let's begin... 1. Figure out what the program does. 1.1. List actions stores the sequen
undefined
18
Task
Java Core, level 6, lesson 13
Locked
The early bird gets the worm
1. Figure out what the program does. 1.1. Each thread should read lines from the console. Use the existing static BufferedReader reader. 1.2. Use AtomicInteger readStringCount to calculate how many lines all the threads have read from the console. 2. Implement the run method: 2.1. As long as a thr
undefined
9
Task
Java Core, level 6, lesson 13
Locked
Take your turn!
1. In the Solution class, create a public static Read3Strings class that inherits Thread. 2. In the run method, read three lines from the console. 3. Three lines should be read in succession on one thread and combined into one space-delimited string. 4. In the main method, display the result for eac
undefined
18
Task
Java Core, level 6, lesson 13
Locked
Sequential file output
1. Figure out what the program does. 2. In a static block, read 2 filenames: firstFileName and secondFileName. 3. Inside the Solution class, create a public static ReadFileThread class that implements the ReadFileInterface interface (Think about what is more appropriate: Thread or Runnable). 3.1. Th
undefined
18
Task
Java Core, level 6, lesson 13
Locked
Factory method pattern
1. Take a careful look at the classes you have. 2. In separate files in the common package, create JpgReader, PngReader, and BmpReader classes that implement the ImageReader interface. 3. In a separate file in the main package, create the ImageReaderFactory class with one method. 3.1. Think about wh
undefined
18
Task
Java Core, level 6, lesson 13
Locked
Clew
1. Create 5 different threads that differ from Thread: 1.1. Thread 1 must run indefinitely; 1.2. Thread 2 should display "InterruptedException" when an InterruptedException occurs; 1.3. Thread 3 should display "Hurray" every half second"; 1.4. Thread 4 must implement the Message interface. When the
undefined
18
Task
Java Core, level 6, lesson 13
Locked
Debug everything under the sun
Figure out what the program does. Read about UncaughtExceptionHandler - it's important. Take another careful look at the program. Figure out why our OurUncaughtExceptionHandler doesn't work (use the debugger). Fix the bug, i.e. everything should work. :) Expected result in no particular order: Thre
Comments (26)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
DarthGizka Level 24, Wittenberg, Germany
5 June 2021
task1631 (Factory method pattern) pitfall: the task turned up another dark corner of the language, which is that switch statements explode if presented with a null value. This is somewhat suprising since there is no dereferencing of any pointers involved, only comparison of pointer values. A chained if statement with operator == would not exhibit such weird behaviour. Anyway, this is relevant to the task at hand because there is a specific requirement which exception should be thrown for any illegal arguments.
DarthGizka Level 24, Wittenberg, Germany
5 June 2021
task1630 (Sequential file output) undocumented requirement: your code will be failed unless it reacts to invalid inputs by printing an empty string instead of null or whatever (i.e. the content of a non-existing file is deemed to be "").
DarthGizka Level 24, Wittenberg, Germany
5 June 2021
task1626 (Following a pattern) caveat: you will get failed if you 'follow the pattern' (i.e. if you emulate the broken logic of the CountdownRunnable code as you are told) because it runs afoul of the requirement "The CountUpRunnable class's run method should run for approximately 2.5 seconds". I bet on the wrong horse and lost - don't follow my pattern. 😉
ayhem bouabid Level 25, Tunis, Tunisia
30 May 2021
That moment when one completes all the easy and medium tasks and has to face the hard tasks...
Andrei Level 39
6 January 2021
Man, it took me maybe 1 month or so to finish this chapter. Try these 3 videos, they helped me with unhandled exceptions: 1. https://www.youtube.com/watch?v=7yM890QoSD8&list=PL1ZYhU1nPNh-ZzXrhaXhsNhrb9SlTtMJd&index=4&ab_channel=JavaJ2EEChamp 2. https://www.youtube.com/watch?v=1UOSwTfWNIc&list=PL1ZYhU1nPNh-ZzXrhaXhsNhrb9SlTtMJd&index=3&t=1s&ab_channel=JavaJ2EEChamp 3. https://www.youtube.com/watch?v=JlVPbxrVrck&list=PL1ZYhU1nPNh-ZzXrhaXhsNhrb9SlTtMJd&index=2&ab_channel=JavaJ2EEChamp
Chandan Thapa Level 22, Dubai, United Arab Emirates
19 December 2020
the last one - make sure to read the entire documentation on UncaughtExceptionHandler... including get, set and default.. :)
Lawson Level 29, Lagos, Nigeria
31 August 2020
Am i the only one who gets scared on seeing a hard task
Henrique Level 41, São Paulo, Brazil
12 June 2020
On task Clew, Thread 4, must we actually use the stop() method, which is deprecated, instead of interrupt() method? I could only success using stop().
null Level 26, Orlando, United States
15 May 2020
I'm glad that I took the Operating System concept class before getting into this.
Mohamed Hamda Level 22, Tunis, Tunisia
8 May 2020
The most hardest and unlogical topics in programming, you expect a certain behavior and you get a complete different one and the worst when you try to figure out what's going on you end up with what you have already expected!!!!! Lol!!!!!