CS1103 Learning Journal Unit 4 - Recursive Descent Parsers, Generic Programming and Java Collection Framework
This week, I learned about BNF (Backus-Naur Form), recursive descent parsing, generic programming, Java collection framework, iterators, equality and comparison, and generics and wrapper classes (UoPeople, n.d.). Firstly, BNF can express the syntax rules of programming languages, and it plays an important role in the compiler’s design. Secondly, recursive descent parsing is a method used to parse phrases. Thirdly, generic programming means writing a program for many types of data, such as ArrayList
In the discussion forum, I detailed the advantages and disadvantages of the equals() method and the alternative for equality. First, the equals() method is a method of the Object class, and all subclasses of the Object class inherit this method by default. The equals() method has advantages and disadvantages. On the one hand, the advantage of this method is that it can easily compare whether the references of two objects are the same, and some methods, such as String, override the equals() method by default, so one can use it directly to compare the content of the two strings. On the other hand, the disadvantage of the equals() method is that not all subclasses override the equals() method by default. In this case, the equals() method can only compare the reference of the object, not the content. If one needs to compare the contents, he/she needs to override the equals() method. Additionally, there are many alternatives to the equals() method, such as the ‘==’, compareTo() and compare() methods. I detailed the compareTo() method with an example in the discussion assignment.
After finishing the programming assignment, I better understand how to use IDE to debug. Specifically, when an exception occurs in the program, one can add breakpoints where an exception may occur and then click the debug button to debug the program step by step. During the debugging process, there are three buttons to choose from. The first is “Step Into”. This button means to step into a sub-method or program to execute. The second is “Step Over”, which means to execute this line of code without going inside the method. The third is “Step Out”, this button means continue to execute until the current subroutine returns (UoPeople, n.d.). In addition, during the debugging process, one can also use comments to invalidate parts of code and then judge whether this code segment is abnormal through the running result. For example, the program BuggySearchAndSort.java in the programming assignment cannot be stopped normally after running. To determine which method caused this infinite loop, I commented on the highly suspicious selectionSort() method, ran the code, and found that the program won’t get caught in an endless loop anymore after running. Therefore, I can assert that this infinite loop is caused by the selectionSort() method.
In conclusion, through this week’s study, I have a deeper understanding of generic programming, the Java collection framework. In addition, through the practice of programming assignments, I have mastered how to use IDE to debug programs and thus solve bugs.
Word count: 618
References
1.Eck, D. J. (2019). Introduction to Programming Using Java.
http://math.hws.edu/javanotes
2.University of the People. (n.d.). Learning Guide Unit 4.
https://my.uopeople.edu/mod/book/view.php?id=279543
3.University of the People. (n.d.). Lab 8 Unit 4.
https://my.uopeople.edu/mod/page/view.php?id=279550