Java Programming Study Notes

MBA,PgDip Researcher
August 8, 2026
❤️ Reference Acknowledgments: A heartfelt gratitude to Professor Christos Chrysoulas for delivering such an amazing and inspiring Java programming course!❤️
Also a special thank you to Teacher Tess Watt for her wonderful academic support and dedication to the students.❤️
I would also like to express my sincere appreciation to the amazing administrative team, especially Miss Debbie Ross and Richard Knight, for their outstanding assistance and continuous support in helping students succeed throughout this Master’s degree program.❤️
Thank you all for your dedication, encouragement, and commitment to our success! 🙏🎓
This review reflects the author's learning and thoughts based on the materials covered in the MSc Computer Science online degree provided by the Heriot-Watt University based in Edinburgh, United Kingdom, delivered on the Coursera platform.
Tips and Tricks in Java
This section is for Java beginners who are learning the basics of Java syntax. It provides simple tips and tricks to help you understand the common syntax differences.
It also includes practical tips for solving math problems related to modulo and identifying the Java exception hierarchy, helping you write more reliable Java programs.
Table of Contents
1.1 Difference between the == Operator and the .equals() Method
1.2 throws Clause vs. Multiple Exceptions in a Single catch Clause
A common Java syntax difference to remember is the separator used between exception types.
1. throws clause → use comma ,
With a throws clause, multiple exception types are separated by commas:
void readFile() throws IOException, SQLException {
// ...
}The comma separates the exception types in a list of exceptions that the method may throw.
This is similar to how commas separate method parameters:
void foo(int x, String y) {
// ...
}2. Multiple exceptions in a single catch clause → use pipe bar |
When handling multiple exception types in a single catch clause, the exception types are separated by a pipe bar |:
try {
// ...
} catch (IOException | SQLException e) {
// Handle either exception
}Here, IOException | SQLException represents alternative exception types that can be handled by the single catch block.
In other words, the same catch block handles either an IOException or a SQLException.
/** Easy trick:
Multiple exception types → one catch clause → use |
In other words:
**/
"Catch an
IOExceptionor aSQLException."
The catch parameter e represents the exception caught from either alternative.
Why are the separators different?
They represent different grammatical constructs in Java:
| Syntax | Separator | Meaning |
|---|---|---|
throws IOException, SQLException | , | A list of exception types the method may throw |
catch (IOException | SQLException e) | | | Multiple alternative exception types handled by one catch block |
So a useful memory trick is:
, = list| = multiple alternative exceptions
The Java Language Specification defines these separately: a throws clause contains a comma-separated list of exception types, while a multi-catch parameter uses | between alternative exception types.
Easy way to remember
throws IOException, SQLException
// ↑
// "and/or list"
catch (IOException | SQLException e)
// ↑
// "or"So:
throws → use comma ,
multiple exceptions in single-catch → use pipe |
For more info, see: Oracle Documentation
1.3 Java Exception Hierarchy
U..