The first question is what do I need to do to fix the following code?
The error I am getting says that it reached the end of the file while parsing. What am I doing wrong?
The other question has to do with understanding the following code and what I am being asked to do.
"Can any errors or exceptions occur from the user failing to input arguments at runtime, or by putting certain arguments in at runtime? What will print if the user inputs nothing?
What will print if the user inputs an argument or several arguments?"
"Can any errors or exceptions occur from the user failing to input arguments at runtime, or by putting certain arguments in at runtime? What will print if the user inputs nothing?
What will print if the user inputs an argument or several arguments?"
I don't understand what I am supposed to do.
What exactly are you stuck on? You just have to imagine you are running the code from the command line with or without some command line parameters and then work out what the code will do in each case.
Rajdeep Biswas wrote:Why not? Without any arguments passed while executing the class, the String[] blocks will have null or not?
Not. It would be a 0-length array.
Winston
Hi Winston,
I can think of 2 situations:
1. No args passed, the array is not constructed. So no question at all about its properties as the array does not exists!
OR
2. The args array has String type blocks, and the default value of String is NULL. So args[0].hashCode() [any instance method or else] will return a NullPointerException
Stuart A. Burkett
Ranch Hand
Joined: May 30, 2012
Posts: 319
posted
0
Rajdeep Biswas wrote:1. No args passed, the array is not constructed. So no question at all about its properties as the array does not exists!
Yes it does. If no arguments are passed the array exists and has a length of zero.
Rajdeep Biswas wrote:
I can think of 2 situations:
1. No args passed, the array is not constructed. So no question at all about its properties as the array does not exists!
OR
2. The args array has String type blocks, and the default value of String is NULL. So args[0].hashCode() [any instance method or else] will return a NullPointerException
Why not just print args in your main, and take a look what it prints..
You will get a nice looking hashcode telling you that its not null.
OCPJP
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
4
posted
1
You cannot get a null element in the command‑line arguments. You can pass new String[]{null, null, null}, but that array reference does not point to null. It is in fact the same as new String[3].