ByteLegend Walkthrough Part III

Welcome to part 3 of this walkthrough!

We have conquered Method and Field in Java Island in the last part.

Now we are halfway to the end of Class and Object. Let’s go!

Java Island (Class and Object)

  1. (87 stars) NullPointerException Challenge 1. Hint: fix createNewCat(). Reading recommendation: https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it 
  2. (90 stars) NullPointerException Challenge 2. Hint: fix createNewCat().
  3. (93 stars) Reference and Value Challenge 1. Reading recommendation: https://www.geeksforgeeks.org/reference-variable-in-java/ 
  4. (96 stars) Reference and Value Challenge 2. Hint: check all three files to find the logic behind how values are passing via the references. 
  5. (99 stars) Reference and Value Challenge 3. Time to learn deep copy: https://www.tutorialspoint.com/what-is-deep-copy-explain-with-an-example-in-java 

Congratulations! You have finished Class and Object. Let’s keep exploring this island!

Java Island (Data Structure)

  1. (102 stars) Data Representation Challenge 1. Time to learn data types: https://www.w3schools.com/java/java_data_types.asp 

This is a sneaky question, don’t waste too much time on it. Answer: https://github.com/ByteLegendQuest/java-data-type-max-value/commit/4b2a64ab955a86b647a149cd2f3049129813029d 

  1. (105 stars) Data Representation Challenge 2. Time to learn type casting/conversion: https://www.w3schools.com/java/java_type_casting.asp https://www.geeksforgeeks.org/type-conversion-java-examples/ 
  2. (108 stars) Data Representation Challenge 3. To save you some time, try this precision: return Math.abs(a – b) <= 1e-10;

Reading Recommendations: https://www.baeldung.com/java-comparing-doubles https://www.geeksforgeeks.org/double-equals-method-in-java-with-examples/ 

  1. (111 stars) Type Conversion and Promotion Challenge 1. Hint: Revisit the readings in Data Representation Challenge 2. 
  2. (114 stars) Type Conversion and Promotion Challenge 2. There are many different ways, methods, or functions to complete this task. Here is mine for your reference: https://github.com/ByteLegendQuest/java-implement-type-casts/commit/623ab1975148b10bdc59d2b0338368bfe0130d77 
  3. (117 stars) Autoboxing and Unboxing Challenge 1. Hint: add some statement in compare(). Reading Recommendation: https://www.tutorialspoint.com/what-are-the-differences-between-an-integer-and-an-int-in-java 
  4. (120 stars) Autoboxing and Unboxing Challenge 2. Hint: Use Integer.parseInt(a) to change String a to integer; use String.valueOf(num) to change a number into String.
  5. (123 stars) Autoboxing and Unboxing Challenge 3. Hint and Reading Recommendation: https://www.baeldung.com/java-integer-parseint-vs-valueof 
  6. (126 stars) Java Array Challenge 1. Hint: Use array.length to check the length of the array.
  7. (129 stars) Java Array Challenge 2. Revisit the examples of parseInt and valueOf.
  8. (132 stars) Java Array Challenge 3. Hint and Reading Recommendations: https://www.geeksforgeeks.org/arrays-copyof-in-java-with-examples/ 

https://www.geeksforgeeks.org/system-arraycopy-in-java/

Congratulations! We have finished Data Structure!

This is the halfway point of this game. Java is not that hard, right?

To be continued…

ByteLegend Walkthrough Part II

Welcome to part 2 of this walkthrough!

For the past month, I was focusing on my capstone project and the rest 3 courses to graduate from my CS degree. Meanwhile, I explored some more tech about Flask in Python and database knowledge.

I am planning to finish this walkthrough in 6 parts, each part would cover about 40 stars. I will try my best to publish the remaining 4 parts before Christmas.

Thanks for your time and patience.

Java Island (Method and Field)

  1. (43 stars) Java Field Challenge 1. Create a Static Field. In this task, you are asking to create a static variable (public static String message = “Hello”;) in Challenge.java to understand what is a static field. For more details, I recommend you to read this: https://stackoverflow.com/questions/797964/what-is-the-exact-meaning-of-static-fields-in-java
  2. (46 stars) Java Field Challenge 2. Implement a SWAP function using static variables and then destroy the tower. Hint: create a temporary variable.
  3. (49 stars) Java Method Innovation. Learn the meaning of refactor, find the similarity and solve the puzzle, then destroy the tower. 

Recommended reading: https://refactoring.guru/refactoring

  1. (52 stars) Local Variable and Scope Challenge 1. Fix the compiling issue. Hint: like C++, declare the variable and then assign it a value. 

Answer: https://github.com/ByteLegendQuest/java-fix-local-variable-scope/commit/68ac8ca0626909c53fd8f7a90dd7b61c741291b6

  1. (55 stars) Local Variable and Scope Challenge 2. This is an easy but tricky task. Learn how to use constructor and “this” in a class. 

Answer Option 1: https://github.com/ByteLegendQuest/java-fix-local-variable-shadowing/commit/ec5f655d339670e58f03a828df6e1dbcd9126435 

Answer Option 2: https://github.com/ByteLegendQuest/java-fix-local-variable-shadowing/commit/dbb5b8309912e95476943b72dc5f0ad1304cfed9

  1. (56 stars) Now, go to Dungeon: Debugger. It is time to learn how to set a breakpoint to debug! Click on the “Debugger” Chest. Clone the project into your local IDE. Open Main.java, then click the space next to line number 29. It is the line to return the result variable. You should see a red dot like in the picture if you are also using IDEA.

Now debug this file by clicking on the bug button in the top bar or find it in the Run dropdown or simply press Ctrl + D and then find the result variable value in the right bottom window. Copy that string and submit it to earn a star. You should get a Chest key to earn 100 golds.

  1. (57 stars) Click on the “Conditional Breakpoint” Chest. Similarly, clone the project and open Main.java. This time, put a breakpoint at line 20. Then right click the red spot to add the condition. The rest of the steps are the same as the last task.
  2. (60 stars) Method Recursion Challenge 1. Go back to Java Island. It is time to practice some recursion algorithms. Have fun! 

Answer: https://github.com/ByteLegendQuest/java-fix-factorial/commit/4ac28744954f2539110edf79822946346ae035b1 

  1. (63 stars) Method Recursion Challenge 2. Fibonacci Question. 

Recommendation Reading: https://leetcode.com/problems/fibonacci-number/ 

Congratulations! You completed the Method and Field Section. Let’s move on!

Java Island (Class and Object)

  1. (66 stars) Class and Object Challenge 1. Learn what a class is in Java. 

Recommended Reading: https://www.w3schools.com/java/java_classes.asp 

  1. (69 stars) Class and Object Challenge 2. Learn what an object is in Java. Use the sword to destroy the tower.
  2. (72 stars) Instance Field. Hint: Check the Cat.java file in the pet folder.
  3. (75 stars) Instance Method. Hint: Use “this.name”.
  4. (78 stars) Instance Constructor Challenge 1. Time to learn constructor: https://www.w3schools.com/java/java_constructors.asp 
  5. (81 stars) Instance Constructor Challenge 2. Time to learn overloading constructor: https://www.geeksforgeeks.org/constructor-overloading-java/ 
  6. (84 stars) Instance Constructor Challenge 3. Hint: According to Home.java, you will need to design two overloading constructors in Cat.java.

To be continued…

Part III: https://blogs.oregonstate.edu/ligan/2022/11/23/bytelegend-walkthrough-part-iii/

PS: A typo found and reported to the development team:

Game Data Contributor: https://github.com/ByteLegendQuest/java-fix-local-variable-scope/tree/main?v=1669157188260#readme    English version contains CN chars

Transactions in Databases

I am in charge of the backend database part of our capstone project. Therefore, I am taking CS340, Introduction to Database, at OSU at the same time. In the design and implementation of our capstone project’s database, I start to understand the importance of database transaction.

When creating a database management system to store, retrieve, and run queries on data, we usually design the entity relationship diagram and the database schema based on the entities and attributes of the objects in a system. Then after the creation, a database transaction performs the unit level of update to this system to provide the data updates. For example, in an e-commerce system, users, products, and locations are entities; orders are the database transactions. Each order contains the information about which user requires what quantity of which products from which locations. Based on this order, the user will pay some amount of money; the store will receive such an amount of money; some amount of product A will be removed from location X; the exact amount of product A will then be delivered to the user’s address. A straightforward transaction record would ensure the database not to be interfered by multiple concurrent access and to cause some errors. Plus, even when an error did happen, the database could rollback based on the related transaction. Therefore, a set of properties of database transactions was concluded as Atomicity, Consistency, Isolation, and Durability.

Atomicity guarantees that each transaction is treated as a single “unit”, which either succeeds completely or fails completely.[1] This is similar to what happens when we fail to install something on our laptop. If an error occurred, no matter at the 1% or the 99% of the processing bar, every installation would be rolled back. This means a single transaction only runs in a whole. If the transaction contains actions related to multiple entities, every action will be consistently done; one action’s failure means the whole transaction never happened. 

Because of the transaction’s atomicity, the database will have the property of consistency. This is saying that after the creation of a database with only entities and attributes and without any data, i.e. this is an empty database, the database has been ensured to be integrated as a whole database. Then, both before and after a transaction was updated, the database will remain the integration, which means the wholeness of the database would be invariant. This property prevents illegal transactions.

Transaction isolation determines how transaction integrity is visible to other users and systems.[2] It guarantees the database management system to be able to handle concurrency controls by setting different isolation levels. The precedence of isolation levels is a big topic to study. I will leave this topic for now. Lastly, a database needs to be durable, which means two things. First, after each transaction is processed, the update to the data in this database is permanent. Second, this update will be recorded by the database management system and shouldn’t be lost under any circumstances.

In general, the study of transactions and the set of properties allow us to remember the importance behind database design. Personally, I would highly recommend everybody to revisit these concepts before starting a system design.

References

  1. https://en.wikipedia.org/wiki/ACID
  2. https://en.wikipedia.org/wiki/Isolation_(database_systems)