• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string concatenation

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the output for this code?

Now try it with this: java Test * ??
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My guess would be you should see
0:*
Are you getting something different?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using cygwin shell on windows and it wildcard sends in all filenames. doh!
Any other String works correctly.
Not really sure how to command-line pass in a character that is also a wildcard in the shell.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to run it with
java Test "*" to get the 0:* output.
Not too sure which one but either the Java runtime or OS (I'm running Windows, don't know if this is true for other OS's though) picks up on the wildcard character * in the command line first and takes it to mean that you want to pass all filenames as parameters.
This has been discussed before so you could try to do a search to find more about it.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a problem in Windows, Unix, and Linux. You must put quotes around the *.
It is not a Java Problem since the OS changes it before Java ever sees it. It happens in C programs too!
[ April 03, 2003: Message edited by: Thomas Paul ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's called filename globbing, if I remember correctly. Just a feature of UNIX like shells.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Monisha, Eric, Junila, Thomas, Barry.
I don't know about you, but in this study group I get so focused on syntax, I forget about real-world effects.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
* is a wildcard for searching for filenames. So when u use it in the command line args[0] will return the name of the first file in the directory in which ur class file resides.
 
reply
    Bookmark Topic Watch Topic
  • New Topic