Skip to main content
added 39 characters in body
Source Link

Exception handling

It is not customary to let the main method throw an exception. At the very least you can catch the base Exception class and use printStackTrace() to print the error message and related debug info.

IO handling

  1. This program only deals with one file. However, it is good practice to remember to close every external resource. That includes files, database connections (and other related resources, like prepared statements and result sets), network sockets, etc. not closing resources may result in resource leaks that can escalate to JVM crash. Java 7 introduced the try-with-resources construct that allows the compiler to automatically handle resource closure as well as error handling.

  2. Java 7 also introduced the "new io" java.nio package that improves IO handling in Java. the Files.readAllLines() is a convenient method that reads whole file into List of Strings (and also internally handles the external resource). (alas, no equivalent writeAllLines())

Naming conventions

gradesString is a List of Double items. the name is very confusing.

Exception handling

It is not customary to let the main method throw an exception. At the very least you can catch the base Exception class and use printStackTrace() to print the error message and related debug info.

IO handling

  1. This program only deals with one file. However, it is good practice to remember to close every external resource. That includes files, database connections (and other related resources, like prepared statements and result sets), network sockets, etc. not closing resources may result in resource leaks that can escalate to JVM crash. Java 7 introduced the try-with-resources construct that allows the compiler to automatically handle resource closure as well as error handling.

  2. Java 7 also introduced the "new io" java.nio package that improves IO handling in Java. the Files.readAllLines() is a convenient method that reads whole file into List of Strings (and also internally handles the external resource).

Naming conventions

gradesString is a List of Double items. the name is very confusing.

Exception handling

It is not customary to let the main method throw an exception. At the very least you can catch the base Exception class and use printStackTrace() to print the error message and related debug info.

IO handling

  1. This program only deals with one file. However, it is good practice to remember to close every external resource. That includes files, database connections (and other related resources, like prepared statements and result sets), network sockets, etc. not closing resources may result in resource leaks that can escalate to JVM crash. Java 7 introduced the try-with-resources construct that allows the compiler to automatically handle resource closure as well as error handling.

  2. Java 7 also introduced the "new io" java.nio package that improves IO handling in Java. the Files.readAllLines() is a convenient method that reads whole file into List of Strings (and also internally handles the external resource). (alas, no equivalent writeAllLines())

Naming conventions

gradesString is a List of Double items. the name is very confusing.

Source Link

Exception handling

It is not customary to let the main method throw an exception. At the very least you can catch the base Exception class and use printStackTrace() to print the error message and related debug info.

IO handling

  1. This program only deals with one file. However, it is good practice to remember to close every external resource. That includes files, database connections (and other related resources, like prepared statements and result sets), network sockets, etc. not closing resources may result in resource leaks that can escalate to JVM crash. Java 7 introduced the try-with-resources construct that allows the compiler to automatically handle resource closure as well as error handling.

  2. Java 7 also introduced the "new io" java.nio package that improves IO handling in Java. the Files.readAllLines() is a convenient method that reads whole file into List of Strings (and also internally handles the external resource).

Naming conventions

gradesString is a List of Double items. the name is very confusing.