aspose file tools
The moose likes Beginning Java and the fly likes Two questions. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Two questions." Watch "Two questions." New topic
Author

Two questions.

matthew meltzer
Greenhorn

Joined: Sep 08, 2012
Posts: 24

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?"


I don't understand what I am supposed to do.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56179
    
  13

matthew meltzer wrote:The first question is what do I need to do to fix the following code?

Better indentation would allow you to see what's missing. Try properly indenting the code and see how the braces match up.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32651
    
    4
And have you really been told to call classes things like Q21? That is a very poor name for a class.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1152
    
    3

"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.
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

What if args is null ?

WP
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32651
    
    4
How on earth could args be null in a main method?
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12909
    
    3

When you post questions from a book, mock exam or some other source, then please tell us where you copied them from - QuoteYourSources.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 163

Campbell Ritchie wrote:How on earth could args be null in a main method?

Why not? Without any arguments passed while executing the class, the String[] blocks will have null or not?


The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 319
Rajdeep Biswas wrote:Why not? Without any arguments passed while executing the class, the String[] blocks will have null or not?

No. It will be an empty array. i.e. args.length will be zero.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 4739
    
    7

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


Isn't it funny how there's always time and money enough to do it WRONG?
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 163

Winston Gutkowski wrote:
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
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.
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 276

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
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].
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Two questions.
 
Similar Threads
TrynCatch
JQplus
Exception Handling Question from Dan Chisholm's mock exam
ommission of throws legal?
exceptions