★ wanayoo — archive 1999 http://java.webdeveloper.com/tutorials/java_param/Nouvelle recherche | Portail wanayoo
The World's Largest Wi-Fi Business Event


Find a Web Host With:
CGI Access
DB Support
NT Servers
UNIX Servers
Telnet Access

advanced search
Developer
Downloads
International
Internet Lists
Internet News
Internet Resources
IT
Linux/Open Source
Small Business
Windows Technology
Wireless Internet
xSP Resources

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
Partners & Affiliates
Send Flowers
Dedicated Hosting
Cheap Web Hosting
Internet Marketing
Promote Your Website
Promotional Products
Hotel Reservations
Home Equity Loans
Price Comparison
Used Books
FlashKit
HierMenusCentral
JavaBoutique
JavaScript.com
JavaScriptSource
WebDev Jobs
JustSMIL
ScriptSearch
StreamingMediaWorld
Web Hosts
WebDevelopersJournal WDVL
WebDeveloper.com
WebReference.com
XMLFiles.com
CGI
HTML
Java
JavaScript
Web Design and Promotion
Web Site Development
E-mail Address:


Can you receive
HTML e-mail?

Yes   No

Zip Code:




Tutorials : Using Program Parameters in Java :

Using Program Parameters in Java

by Keld H. Hansen

Introduction

Every programmer will encounter a situation where a choice must be made between various alternative solutions. Should tabular data be sorted in one way or another? What exactly is the graphical layout of your HTML pages? How often should you poll a queue? Most often you'll know the path to take based on the requirements specifications, a design manual or some other kind of documentation, but now and then you'll have to choose without help. Instead of just selecting one solution and hoping the customer will like it when he or she starts using your code, you could make it a "program parameter" or "option".

This means that the actual choice is given to your program in some way at startup time, for example from a configuration file. Programs like command line utilities, where there's no GUI and no database, simply take their data as "program parameters".

In this article we'll look into the various ways you may enter parameters to a Java program:

  1. Command line parameters
  2. Property files
  3. A combination of 1 and 2
  4. System properties
  5. XML files
  6. Databases 

Finally I'll show how you can hide the implementation--at least to some degree.

Command line parameters

Let's start with the most basic and simplest way to enter parameters to a Java program: the command line. We all should know that a Java main program takes a String array as its parameter, and it contains the program arguments given to the Java VM. I deliberately used the word "arguments", since the "parameters" given on the command line are meant for the VM. Entering "java -?" gives the syntax for the Java command:

C:\>java -?
Usage: java [-options] class [args...
            (to execute a class)
   or java [-options] -jar jarfile [
            (to execute a jar file)
. . .

If you have a fixed list of parameters for your program then you simply add them after the class name, but if you'd like to work with optional parameters, you need some way to identify the different parameters.

It's common practice to give the parameters descriptive names, and use a hyphen in front of the name of the parameter. The parameter value(s) then follow after the name. This syntax is, for example, used in the Java command shown above.

It might be fun to write a command line parser in Java once and maybe twice, but the third time it gets rather boring. The Jakarta Commons project has a command line parser called CLI (Command Line Interface), which is simple and efficient to use. There are 3 steps involved when using CLI: define, parse, interrogate

Home / Tutorials / Using Program Parameters in Java/ 1 Next Page


Applet Index
(sorted alphabetically)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z #s
The Java Source
(applets w/source code)

A B C D E F G H I J K
L M N O P Q R S T U
V W X Y Z

How to Add Java Applets to Your Site

New on the Java Boutique:

New Article:
Sun Java Studio Creator Early Access Release
Sun's anticipated release of Java Studio Creator is here at last and Drew was hard at work the day of release. Find out why J2EE developers may have a new addition to their toolbox.


... [more articles]

New Tutorial:

Using Program Parameters in Java
Each of us, as Java programmers will encounter situations where choices must be made between various coding solutions. Should tabular data be sorted in one way or another? What exactly is the graphical layout of your HTML pages? How often should you poll a queue? To better understand what choices to make Keld discusses the various ways you may enter parameters to your Java programs.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

internet.com logo
Learn About the Apache Beehive Project.




Developer News

Oracle Goes SOA with Collaxa Buy

'Express' Route For Windows Coding Hobbyists

WebSphere Takes On Telcos



Database Journal offers SQL courses and other database related resources for beginner to expert developers.


Receive Articles via our XML/RSS feed
XML Feed

Receive Applets via our XML/RSS feed
XML Feed

JavaBytes
JDrawing
JDrawing is a Java swing component for displaying vector graphics and animation.

JB User Poll
What IDE do you use? :
Refer-It
Affiliate Program and Referral Directory.
New on internet.com
Supreme Court Blocks Online Porn Law
High court rules that controversial online porn law to protect children is a violation of free speech.

Cutting Through the Infiniband Buzz
When the Infiniband Trade Association formed five years ago, the consortium set out to rock the networking world and get the combination spec and architecture lead billing over Fibre Channel and Ethernet. We look at where it is today.

Q&A: Ed Kaim, Product Manager, Microsoft
Ed Kaim, product manager on the Developer and Platform Evangelism Division at Microsoft, talks to 15Seconds about the role of the developer in the upcoming Longhorn era.



JupiterWeb networks:

internet.comearthweb.comDevx.comClickZ

Search JupiterWeb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers