"Hoy, kawal!"
"Magandang araw, Kapitan!"
"Mayroon akong kahanga-hangang balita para sa iyo. Narito ang ilang mga pagsasanay upang palakasin ang iyong mga kasanayan. Gawin ang mga ito araw-araw at ang iyong mga kasanayan ay lalago nang napakabilis. Ang mga ito ay nilikha lalo na para sa IntelliJ IDEA."
"Yung mga nakaraang exercise ay para sa mga rookies. Nagdagdag ako ng ilang mas advanced na bonus exercises para sa mga old-timers. Para lang sa mga beterano."
18
Gawain
Java Core, antas, aralin
CRUD
CrUD: Create, Update, Delete.
The program runs with one of the following sets of arguments:
-c name sex bd
-u id name sex bd
-d id
-i id
Argument values:
name (String)
sex ("m" or "f")
bd (birth date in the following format: "04 15 1990")
-c (adds a person with the specified arguments to the end of
18
Gawain
Java Core, antas, aralin
CRUD 2
Batch CrUD: multiple Creations, Updates, Deletions.
The program runs with one of the following sets of arguments:
-c name1 sex1 bd1 name2 sex2 bd2 ...
-u id1 name1 sex1 bd1 id2 name2 sex2 bd2 ...
-d id1 id2 id3 id4 ...
-i id1 id2 id3 id4 ...
Argument values:
name (String)
sex ("m" or "f")
bd (birth
18
Gawain
Java Core, antas, aralin
Restaurant
1. Figure out what the program does. For some reason, the waiter isn't bringing the prepared dishes out to the tables :(
2. Fix the bug.
Hint: it's one line
18
Gawain
Java Core, antas, aralin
Shared list
1. Change the Solution class so that it becomes a list. (It must implement the java.util.List interface).
2. The Solution list should only work with Longs.
3. Use the original field.
4. The list will be used by threads, so you need to ensure that all the methods are synchronized.
9
Gawain
Java Core, antas, aralin
Comparable
Implement the Comparable interface in the Beach class. Beaches will be used by threads, so you need to ensure that all the methods are synchronized.
Implement the compareTo method so that when two beaches are compared the method returns a positive number if the first beach is better
or a nega
18
Gawain
Java Core, antas, aralin
Pharmacy
Implement the Runnable interface in the Pharmacy and Person classes.
All threads should run until isStopped is true.
Here's the logic for the Pharmacy class: drugController should make a random drug purchase (getRandomDrug) in a random amount (getRandomCount) and wait 300 ms.
Here's the logic for th
5
Gawain
Java Core, antas, aralin
Synchronized methods
Set the synchronized modifier only on the methods that need it.
The Solution object will be used by threads.
9
Gawain
Java Core, antas, aralin
Superfluous synchronization
The synchronized keyword significantly slows a program, so remove unnecessary synchronized statements in methods.
5
Gawain
Java Core, antas, aralin
Ironing
Back to the daily grind...
Add one synchronized keyword to make diana and steve take turns ironing, since there's only one iron!
Hint: Use class-level locking.
5
Gawain
Java Core, antas, aralin
ApplicationContext
The ApplicationContext class will be accessible by many threads.
Be sure that no data is lost: think about which keyword to put and where.
9
Gawain
Java Core, antas, aralin
ATM
Figure out how the program works.
During testing, the log was found to contain the following:
.....
Deposit 100, account balance 1100
Deposit 100, account balance 1200
Spend 1000, account balance 100
Insufficient money
.....
There's a bug: Money is lost when debiting an account.
Find and fix the bug.
18
Gawain
Java Core, antas, aralin
Transactionality
Make the joinData method transactional, i.e. if it fails, then the data must not be changed.
1. Read 2 file names from the console.
2. Read from the files line by line. Read from the first file into allLines, from the second file — into linesForRemoval.
In the joinData method:
3. If the allLines lis
9
Gawain
Java Core, antas, aralin
Let's count
1. Make it so that the result is calculated for all the array elements, WITHOUT using Thread.sleep in the main(String[] args) method.
2. Correct the synchronized block so that the values array is filled with 1s