• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Two questions.

 
Greenhorn
Posts: 24
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67682
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And have you really been told to call classes things like Q21? That is a very poor name for a class.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"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.
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if args is null ?

WP
 
Campbell Ritchie
Marshal
Posts: 76862
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How on earth could args be null in a main method?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you post questions from a book, mock exam or some other source, then please tell us where you copied them from - QuoteYourSources.
 
Ranch Hand
Posts: 231
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Rajdeep Biswas
Ranch Hand
Posts: 231
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 679
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 375
1
Python Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Campbell Ritchie
Marshal
Posts: 76862
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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].
 
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic