The following is a summary of new content that I learned on August 2nd (one topic after another is not correlated).
The map that I wanted to print had the Subject class object as a key and a list of Score class objects as its value.
// for context, this is the map field
private Map<Subject, List<Score>> subjectScores = new HashMap<>();
// printing out the map
System.out.println("Below is the printed map including its keys and values!");
for (Map.Entry<Subject, List<Score>> entry : subjectScores.entrySet()) {
// get the key and value of each entry
Subject subject = entry.getKey();
List<Score> scoreList = entry.getValue();
// print them out
System.out.println("Subject: " + subject.getSubjectName());
for (Score score : scoreList) {
System.out.println("Score: " + score.getScore());
}
}
A query vairable is optional whereas a path variable is not.
For example in a Google search, if you don't fill in a query variable, you would be searching without a search keyword, which leads you back to the main page. Similarly, supposed that you initially limited your search to 'from May 15, 2023 to May 15, 2024'. Later on if you take out the beginning date in your query, you would simply get all the searches prior to May 15th, 2024.
// without search keyword
https://www.google.com/webhp?hl=en&sa=X&ved=0ahUKEwiP8YnPt9qHAxWAi68BHTdGIhgQPAgK
// with search key words "hello world"
https://www.google.com/search?q=hello+world&sca_esv=ee98ebe28384d87e&hl=en&sxsrf=ADLYWIJcO76j2s5NuZq4gON0AZvog8OknA%3A1722743832408&source=hp&ei=GPyuZu6MFouivr0P5KHfmQs&iflsig=AL9hbdgAAAAAZq8KKKr708-YF34plwHsz7ThWb8Dav1k&ved=0ahUKEwju-KrxuNqHAxULka8BHeTQN7MQ4dUDCBc&uact=5&oq=hello+world&gs_lp=Egdnd3Mtd2l6IgtoZWxsbyB3b3JsZDIIEAAYgAQYywEyCBAAGIAEGMsBMggQABiABBjLATIIEC4YgAQYywEyCBAAGIAEGMsBMggQABiABBjLATIIEAAYgAQYywEyCBAAGIAEGMsBMggQABiABBjLATIIEAAYgAQYywFI5GVQglhY5WRwAngAkAEAmAHdAaABng2qAQUwLjkuMbgBA8gBAPgBAZgCDKACuw2oAgrCAgcQIxgnGOoCwgINEC4Y0QMYxwEYJxjqAsICBBAjGCfCAgoQIxiABBgnGIoFwgIKEC4YgAQYJxiKBcICChAAGIAEGEMYigXCAgsQLhiABBjRAxjHAcICBRAAGIAEwgIFEC4YgATCAgoQABiABBgUGIcCwgILEC4YgAQYxwEYrwHCAg0QLhiABBhDGMkDGIoFwgILEAAYgAQYkgMYigXCAg4QLhiABBjRAxjHARjLAcICCxAuGIAEGNQCGMsBmAMF4gMFEgExIECSBwUyLjkuMaAHiHs&sclient=gws-wiz
💡 This would explain why when you write functions within the main method, you will often get errors telling you to change your method to static!
Because the main function that starts our program is static, some people seem to think that static methods runs automatically without being called. However, static methods also do not run automatically unless they are explicitly called. The main method is called by the Java runtime environment as the starting point of the program. Therefore, other static methods will only run if they are called within main or another method.
Static variables and methods in Java get memory allocation even if they are not explicitly referenced or called in the program. That's why even if no instance of the class is ever created, the static variable can still be accessed using the class name because it exists as soon as the class is loaded.