Things to remember that came up during Lab
2
Once you have
saved a file in jGrasp, when you recompile it will automatically do a
save. You don’t need to hit the disk
icon to resave the new file.
Scanner is in
java.util so want to include import
java.util.Scanner when you use it.
File is in
java.io so want to include import
java.io.* when you use it.
You catch block
needs
catch (
<ExceptionClass>
<nameOfExceptionObject>)
{
}
Once you have a
<nameOfExceptionObject> you can use it to call the methods of
<ExceptionClass>
A convention I
like to use is to make the <nameOfExceptionObject> match the
<ExceptionClass>.
For example: :
suppose you want
to catch an ArrayIndexOutOfBoundsException, then use the first letter of each
word in the ExceptionClassName) as your <nameOfExceptionObject>
. catch (ArrayIndexOutOfBoundsException
aioobe)
When you have
finished looking at or capturing the output in the jGrasp output window, you
should clear it before re-compiling or re-running your program. That way, the only thing in the output
window will be the current information (which makes it easier to copy and less
confusing to read).
A throws clause
has to be appended to a block header or method header, it can’t be appended to
a single statement.
When you look at
the method PrintStackTrace in the API, it is easy to overlook the one with no
parameters.