• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

using getopt() in Java

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is there somehow I could use the getopt() feature that C language has for doing command line argument processing in Java.I mean using flags and all that stuff for my argumens. Example syntax in Student Database Program:-
java myClassName -c Insert -s John -i 7635425 -b CS
-l {Java|C|C++|nothing} -a []
Flags Explanation:-
'c' may have the following options:-Insert, Delete, Update,Search 's' Student name(compulsory)
'i' Student id(compulsory)
'b' Stuent Major(compulsory)
'l' Student Computer Language Proficiency(choice)
'a' Student Achievements(optional)
Note:-
Now the command line arguments may be posted in any order,and my program should work correctly.Please do provide any suggestions on how this can be done in Java.
Thanking you,
Ashwin
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
You will need to do something like this:

The args string array will take all the command line argument following 'java MyClassName'
hope this helps
regards
Tanveer
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tanveer,
Thank you very much for your thoughtful advice.I will try to use that code and let you know of any new progress that I have made.
Bye.
Ashwin
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tanveer,
Yes it did work as you have said and looks pretty decent.Thank you so much Tanveer.Bye.
Thanking you,
Ashwin

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!