We have very specific goals in 314 concerning what we want to learn and evaluate you on. Therefore, some Java features are disallowed.
In general if a programming assignment specification does not disallow a feature, method, or class from the Java standard library and it isn't listed here, you may use it. If you are unsure post to the class discussion group for clarification.
The keywords break and continue can be used to write cleaner code, but the vast, vast majority of beginning programmers misuse them to create code that is more difficult to understand without improving readability or efficiency. Instead of having all the exit conditions at the top of a loop the break and continue keywords are used to scatter the exit conditions throughout the code, making it harder to understand.
Therefore break and continue shall not be used on programming assignments in 314. After CS314, go nuts! Use them all you want.
You may return from inside of loops if it leads to cleaner and more logical code, but avoid returns buried deep inside loops.
Do not use the return statement to exit early from a void method,
Those features are for another course, not the current version of CS314. We will discuss them near the end of the course if time allows.
Do not use the Java 8 functional features such as lambdas, streams, and method references.
Do not use the var keyword or local variable type inference.
try / catch blocks are meant for exceptional situations that cannot be handled with standard control structures. For example, if we are reading from a data source (file) on a remote computer and that data source is deleted while our program is running, we cannot avoid that with standard control logic. Thus the use of a try catch block for an exceptional situation outside of our control.
Compare that to looping through an array. Some programmers misuse try / catch blocks instead of standard control structures. This makes the code confusing as we expect try catch blocks to be used for those exceptional circumstances.
Example. Given an array of ints add up the first 10 elements of the array or all the elements of the array if the length of the array is less than 10.
int sum = 0;
try {
for (int i = 0; i < 10; i++) {
sum += data[i];
}
} catch (ArrayIndexOutOfBoundsException aiobe) {
// oh well, less than 10 elements, nothing to see here, move along
}
int sum = 0;
int i = 0;
int LIMIT = 10;
while (i < data.length && i < LIMIT) {
sum += data[i];
i++;
}