wood burning stoves 2.0*
The moose likes Java in General and the fly likes using getopt() in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "using getopt() in Java" Watch "using getopt() in Java" New topic
Author

using getopt() in Java

Ashwin Tadepalli
Greenhorn

Joined: Feb 01, 2001
Posts: 27
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
Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
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


Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Ashwin Tadepalli
Greenhorn

Joined: Feb 01, 2001
Posts: 27
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

Joined: Feb 01, 2001
Posts: 27
Hi Tanveer,
Yes it did work as you have said and looks pretty decent.Thank you so much Tanveer.Bye.
Thanking you,
Ashwin

 
wood burning stoves
 
subject: using getopt() in Java