Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2007, 01:49 PM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with passing args

I would realy appreciate if someone could explain me how to pass values like arguments of command line :)

 
Old February 6th, 2007, 10:24 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

OK, they get passed to your main method when you write something like:
Code:
public static void main (String argv[]) {
The argv[] is an array of Strings made out of your commandline arguments. Here's an example:

Code:
// tmp.java
public class tmp {

    public static void main (String argv[]) {
        for(int i=0; i < argv.length; i++) {
            System.out.println("Got this on the commandline:" + argv[i]);
        }
    }

}
And the output:

Code:
charlie@charlie:~$ javac tmp.java
charlie@charlie:~$ java tmp hello world
Got this on the commandline:hello
Got this on the commandline:world
charlie@charlie:~$

HTH,
Charlie


--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 6 - scaffold error, wrong number of args davidtspf BOOK: Beginning Ruby on Rails 12 August 13th, 2010 11:20 PM
Event - Sender & Event args dash dev C# 2005 9 December 9th, 2007 07:24 AM
Pass multiple args to bat file from console app Andy dg C# 2005 2 February 9th, 2007 03:38 PM
passing vars cassius_b C# 1 July 17th, 2006 07:10 AM
Passing more than one sqlQuery azamat_kd ADO.NET 1 May 23rd, 2006 04:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.