The moose likes Developer Certification (SCJD/OCMJD) and the fly likes command line arguments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "command line arguments" Watch "command line arguments" New topic

command line arguments

Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
I have a StartClient class that acts as a proxy between starting in local or remote mode. in local mode I start the client java -classpath . suncertify.client.StartClient local db.db
In remote mode I start the client java -classapth . suncertify.client.StartClient remote <ipaddress> <port>.
This adds the mode of connection to the command line is this going to lose me points and should I create a simple GUI to handle the connection mode ?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

These command lines may only take configuration parameters selected from this list:
DNS name of the server
Port number used by the server
Data file name(s)
security manager policy file

Taken from the specs.
Ok on that note. it looks like in local mode you are using the db.db file in the root directory, or the directory you are running the java command from. Since this is the case and you probably put that in your readme.txt file that that is where it shoudl reside, then you can reduce your command line arguments to just IP address if you want Remote mode.
What you will need to do is put the location of the db.db file in your code.
and append a "/db.db" to it to pass the location of the db file.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Nigel, did you note that you can infer the mode simply from the number of command line arguments? (In fact, in my submission the port was optional; I simply used the File class to see if the specified database location existed as a file, if not, I would treat it as a hostname).
Mark, I'm not sure I'm happy with the idea of hardwiring something like the file location in the code. The assignment allows you to specify it as a command line option, why not do that?
- Peter
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I did it that way because I knew the db.db file would be in the jar directory. I put that in the readme, and in the specs it states that you can move the db.db file wherever you want to.
As long as the db.db file is where the jar file is, it will always work.
The suncertify/db directory in this distribution also contains your database file, "db.db". You may not modify this file, but you may move it if you wish.

This was in the readme part of the specs
The location of your db.db file.

I did not lose any points for this. plus by coding this in my code, I left out the "User" problems that occur if they put the wrong information in the command line. You know those wacky users.
I agree. Here's the link:
subject: command line arguments
It's not a secret anymore!