Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

command line invocation

 
Sanjana Sharma
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


and command line invocation : java try a b c

what should the output be?

I get no output at all...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"try" is a reserved keyword. Did you manage to compile it ??
 
Sanjana Sharma
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, i had used some other class name actually.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post your class again, exactly as it is.

I get no output at all...

No error either ?
 
Henry Wong
author
Marshal
Pie
Posts: 21194
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I ran it (with the class named to something else), I get "b c" as the output.

Henry
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So did I.
 
Death Arte
Greenhorn
Posts: 21
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir Christophe Verré is correct.. Try is a reserved word.

i try this..

 
Rob Spoor
Sheriff
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjana Sharma wrote:Sorry, i had used some other class name actually.

Please PostRealCode next time.
 
Sanjana Sharma
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

this is the class i used. Now , when i complied and ran this program on a friends system , i got the output as b c.

i tried running it on my system. I get this.. Screenshot of output attached.
i am confused now. How can i get the output in another system and not on mine??
Please refer to the attached file.
output.jpg
[Thumbnail for output.jpg]
output screenshot
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You likely used different arguments at your friend's computer.

Try changing the 1 in your for loop to 0. Java arrays are 0-based.
 
prem pillai
Ranch Hand
Posts: 87
Java Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you say
there is only one command line arg.
But when you say
there are 3

now have a look at your code to understand why its not printing in your machine.
 
Sanjana Sharma
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prem Sir, you just hit the target !
i found the answer .

thanks a bunch everyone .
i love this place
 
Rahul Sudip Bose
Ranch Hand
Posts: 637
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjana Sharma wrote:Prem Sir, you just hit the target !
i found the answer .

thanks a bunch everyone .
i love this place


Taking your question 1 step further. How do i enter a string with spaces in it as one string and not separate strings ? For example : welcome to java is 1 string and not 3. It is followed by rahul bose which is another string. ie args contains only 2 strings.
 
Stephan van Hulst
Bartender
Pie
Posts: 5893
63
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surround your argument in double quotes in the command prompt.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic