Why doyou pass string[] argv to main?

I was just wondering why when you call the main method you pass a string array tto it? I just always did it without thinking about it and now im looking at the following code that uses argv-
public static void main(String[] argv)
        try
            for(int i=0; i < argv.length; i++)
                if(argv.endsWith(".class"))
I can't figure out why its using argv and what it's doing.

If that method were invoked by the VM while someone
started it up on the command-line like this (let's
pretend the class that main method belongs to is
called Foo):
java Foo one two three
The strings "one", "two", and "three" are stuffed
into a String array of size 3, and passed to
main(String[] argv). argv is that array.Thanks, I understand what the code is doing now.

Similar Messages

  • What is the use of passing String[] args in main() method?

    what is the use of passing String[] args in main() method?
    Is there any specific use for this ?

    actually my sir asked me the same question & I gave
    the same reply as given by you........but he further
    asked what is the use of this also??
    ie accepting cmd line args at runtime??is there any
    specific purpose ??Apart from the one you just mentioned? No

  • Why we use string args[]  in void main()

    why we use string in void main in java?

    Because that's roughly how C did it and Java is based on C.
    You can get all the input arguments using JMX, but it's rather complicated and not useful except in obscure cases.
    (I use it to determine if a unit test is running in debug and change the timeouts in my tests so I can step through a test without it stopping at a random point due to a time out)

  • Standard/common handling void main(String argv[])

    i would like to have a parent class to handle the void main(String argv[]), but I can't instantiate my child class because I dun know it's name.
    any way to get that? or any alternative way to handle the void main(String argv[]) in common? million thanks.
    eg:
    public abstract class parent {
    public static void main(String argv[]){
    // i need to know which child is been run by java childclass
    // so that I can instantiate a new object and call the run method
    public abstract void run();
    public class child1 extends parent{
    public void run(){}
    public class child2 extends parent{
    public void run(){}
    }

    Class.forName(name).newInstance();
    provided I know name=what, right?
    how do I know ppl calling using
    java child1?
    or
    java child2?
    both will go use same
    public static void main(String argv[])
    in parent class.

  • Need of String args[] in main()

    Hai all, i had a small doubt regarding the usage of String args[] in main function. When we are not passing any parameters to the program also, we have to give this String args[]. why should we do so. I mean when we pass some arguements to the program then there is the usage of String args[] but when we are not passing also, we have to give String args[] in the main function. why is it made mandatory?

    There is only one method signature that the JVM will call. This is part of the Java specification.
    The String[] args parameter represents the command line arguments. If there were none, the array will be empty.
    Think about it: imagine there were two versions, one with and one without the String[] args parameter, and your application doesn't expect any command line arguments, so it implements only the version with no parameter at all. What would happen if the user decides to provide some command line arguments just for fun?

  • Why do we need static for main() .........?

    Why do we need static for main method
    class Sample
    public static void main(String args[])
    System.out.println("HI EVERYONE");
    }

    The Java virtual machine is another term for the Java interpreter, which is the code that ultimately runs Java programs by interpreting the intermediate byte-code format of the Java programming language. The Java interpreter actually comes in two popular forms: the interpreter itself (called java) that runs programs via the command line or a file manager, and the interpreter that is built into many popular Web browsers such as Netscape, HotJava, and the appletviewer that comes with the Java Developer's Kit. Both of these forms are simply implementations of the Java virtual machine, and we'll refer to the Java virtual machine when our discussion applies to both. When we use the term java interpreter, we're talking specifically about the command line, standalone version of the virtual machine; when we use the term Java-enabled browser (or, more simply, browser), we're talking specifically about the virtual machine built into these Web browsers.
    excerpts Orelly "Java Threads" Chapter 1. (If you don't believe me). Did i do any fundamental wrong by saying interpreter ? Is that a Sin ?
    That is why i told concentrate on what answer I gave regarding the question. I am not going to argue any more. If you don't like my comments then I am Sorry :(

  • Why we are using cluster tables mainly HR

    can any plz tell me why we are using cluster tables mainly HR???

    Nice question -
    Am making my guess based on whatever little I know;
    PCLn are <i>file</i> systems and not a traditional (RDBMS) table system. Each File may contain one or more data clusters. SAP Defines data clusters thus -
    <i>A data cluster is a grouping of several data objects. Elementary fields, field strings and internal tables can be grouped in a data cluster</i>.
    <i>Example</i>:<i>Clusters B1 and B2 in files PCL1 and PCL2 are relevant to time evaluation, as is cluster PS, which stores the generated schema</i>.
    The reason why file system of data storage is used instead of DB Table system may be for the purpose of storing voluminous data (Payroll and time) and ease of retrieval during processing (RDBMS may hv tough time in this). Also probably because of SAP's origin from Mainframe.
    Why data clusters are used -? Probably data clusters are an offshoot (or part) of File system
    Pls feel free to contradict the above. Actually DB experts can throw more light on this..
    Regards
    Chandra

  • Passing strings to method with Object as parameter?

    I'm having some trouble with comparing a string from my main class to another string stored in an array object in my ADT class using a method called remove. When I compare a string I enter with a string object I have stored in an array, I don't get the correct boolean return value (i.e. the two are equal - true). I thought that strings are objects by default but I'm wondering if I need to declare the string I am passing to the 'remove' method as an object?
    Any suggestions?
    Here is the main class and method from the ADT class (Set) I'm calling.
    Thanks,
    Mark
    import javax.swing.JOptionPane;
    public class TestSet {
    public static void main(String[] args) {
    //create set1
    Set set1 = new Set();
    String stringS1;
    // insert a string or strings into set1
    for(int i = 1; i < 50; i++){
    stringS1 = JOptionPane.showInputDialog(
    "Enter string " + i + " of set1");
    set1.insert(stringS1);
    System.out.println(set1);
    String stringCont1 = JOptionPane.showInputDialog("Do you wish to
    continue?" +
    "\n 1 for yes, 2 for no");
    int cont1 = Integer.parseInt(stringCont1);
    if (cont1 == 2)
    break;
    } // end for
    // remove a string from set1
    for(int i = 1; i < 50; i++){
    stringS1 = JOptionPane.showInputDialog(
    "remove a string of set1");
    System.out.println(set1.remove(stringS1));
    public class Set {
    private final int MAX_INDEX = 50;
    private Object list[];
    private int numItems = 0;
    //Creates a new, empty Set object which can store 50 objects
    public Set() {
    list = new Object[MAX_INDEX];
    // if any occurrances of item are in the set, removes one
    // Precondition: set is not empty
    // Postcondition: set may have one less item
    // success is set to true if item was removed
    // Returns: true if value was removed
    public boolean remove(Object item)
    throws SetIndexOutOfBoundsException {
    boolean success = false;
    int index = 0;
    if (numItems > MAX_INDEX) { // index out of range
    throw new SetIndexOutOfBoundsException("out of bounds exception on" +
    "remove");
    } // end if
    while (index < numItems && !success){
         if (list[index] == item)
              success = true;
         else
              index++;
         } // end while
         if (success){  // if one was found, it is at list[index]
    for (int position = index + 1; position <= numItems - 1; position++)
              list[position - 1] = list[position];
         numItems--;
    } // end if
    return success;
    } // end remove
    // output all list contents
         // Precondition : NONE
         // Postcondition: bag is unchanged
         public String toString() {
              String result = "[ ";
              for (int i = 0; i < numItems; i++)
              result = result + list[i] + " ";
              result = result + " ]";
              return result;
    }

    flounder wrote:
    cotton.m wrote:
    -- this message brought to you be the Jive Forum software sucks donkey balls foundationWhere can I donate?I'm hoping to stick that in enough threads to make for interesting Google results in the hope (faint) that it might inspire some embarrasment to Jive.
    I mentioned elsewhere before I think that I have now come across Jive on other sites as well. Same bugs, holes and shit as here. Sun has certainly not proved competent, thoughtful or careful in addressing issues, rolling out new versions and other maintainence however the real fault is that Jive is terrible shit that nobody should use ever.
    For example you remember all that terrible nonsense with the goatsex and the changes to profiles (and the other worse things that could have been done but weren't)? You can do that on 9 out of 10 Jive forums in the wild (in fact you can do exactly that on the 6 other Jive forums I have come across).
    And some of these are big companies too. It's the worst forum software ever and I wish it wasn't written in Java.

  • Passing String Which Has Single Quote Row/Value to a Function Returns Double Quoate

    Hi, I'm getting weird thing in resultset. When I pass String which has single quote value in it to a split function , it returns rows with double quote. 
    For example  following string:
    'N gage, Wash 'n Curl,Murray's, Don't-B-Bald
    Returns:
    ''N gage, Wash ''n Curl,Murray''s, Don''t-B-Bald
    Here is the split function:
    CREATE Function [dbo].[fnSplit] (
    @List varchar(8000), 
    @Delimiter char(1)
    Returns @Temp1 Table (
    ItemId int Identity(1, 1) NOT NULL PRIMARY KEY , 
    Item varchar(8000) NULL 
    As 
    Begin 
    Declare @item varchar(4000), 
    @iPos int 
    Set @Delimiter = ISNULL(@Delimiter, ';' ) 
    Set @List = RTrim(LTrim(@List)) 
    -- check for final delimiter 
    If Right( @List, 1 ) <> @Delimiter -- append final delimiter 
    Select @List = @List + @Delimiter -- get position of first element 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    While @iPos > 0 
    Begin 
    -- get item 
    Select @item = LTrim( RTrim( Substring( @List, 1, @iPos -1 ) ) ) 
    If @@ERROR <> 0 Break -- remove item form list 
    Select @List = Substring( @List, @iPos + 1, Len(@List) - @iPos + 1 ) 
    If @@ERROR <> 0 Break -- insert item 
    Insert @Temp1 Values( @item ) If @@ERROR <> 0 Break 
    -- get position pf next item 
    Select @iPos = Charindex( @Delimiter, @List, 1 ) 
    If @@ERROR <> 0 Break 
    End 
    Return 
    End
    FYI: I'm getting @List value from a table and passing it as a string to split function.
    Any help would be appreciated!
    ZK

    fixed the issue by using Replace function like
    Replace(value,'''''','''')
    Big Thanks Patrick Hurst!!!!! :)
    Though I came to another issue which I posted here:
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a26469cc-f7f7-4fb1-ac1b-b3e9769c6f3c/split-function-unable-to-parse-string-correctly?forum=transactsql
    ZK

  • When using pop up editor windows on a Joomla 1.0.15 website the URLs selected in the pop-up are not passed back to the main window

    The Joomla content management system version 1.0.15 provides a content editor which uses pop-up windows to select images and files. When using any of these pop up editor windows since 3.6.9 the URLs selected in the pop-up are not passed back to the main editor window.
    Up until FF 3.6.8 there were no problems, but FF 3.6.9 and 3.6.10 both exhibit this same problem, as does FF 4 Beta 6. (Support Question raised on this forum in early September when 2.6.9 was released but no response)

    Do you have that problem when running in the Firefox SafeMode?
    [http://support.mozilla.com/en-US/kb/Safe+Mode]
    ''Don't select anything right now, just use "Continue in SafeMode."''
    If not, see this:
    [http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes]

  • Problem with prepared statement where cluase when passing string value.Help

    I am updating a table using the following code. I am using string parameter in where clause. if I use Long parameter in where clause with ps.setLong , this code is working. Is there any special way to pass string value? Am I doing anything wrong?
    ===================
    updateMPSQL.append("UPDATE MP_Table SET ");
         updateMPSQL.append("MPRqmt = ?,End_Dt = ? ");
              updateMPSQL.append("where POS = ? ");
              System.out.println(updateMPSQL.toString());
              con     = getConnection(false) ;
              ps      = con.prepareStatement(updateMPSQL.toString());
              ps.setLong(1,MPB.getMPRqmt());
              ps.setDate(2,MPB.getEnd_Dt());
              ps.setString(3,MPB.getPos());
    result = ps.execute();
              System.out.println("Result : " + result);
    ==========
    Please help me.
    Thanks in advance.
    Regards,
    Sekhar

    doesn't Pos look like a number rather than a string variable?
    if I use Long
    parameter in where clause with ps.setLong , this code
    is working.
    updateMPSQL.append("where POS = ? ");
    ps.setString(3,MPB.getPos());

  • Failure using {CALL } syntax & passing string params w/ # (hash)

    We are experiencing a problem calling functions using the {CALL } syntax and passing string parameters that contain # (hash) symbols. Apparently, something interprets the # inside the string literal and fails the call.
    We use this syntax with procedure calls from a Java applet to an Oracle 8i database using the 8.1.6.2.0 ODBC Oracle driver. The applet is running under the Java 1.3.1 plug-in and we are using a third party JDBC, type III, driver from JDataConnect to link the applet to the Oracle ODBC driver.
    Any insight on this would be greatly appreciated.

    What's the result of con.getAutoCommit()?
    You might try con.setAutoCommit(true) to see if that sorts it.
    /k1

  • Why can I only charge from mains ? .

    Why can I only charge from mains ? . If I charge via cigarette lighter it says not compatable and trickle charges .
    Tried two sources of USB ends and cables .
    Is there a software glitch ?

    Buy an adapter designed for iPads.

  • Kinda urgent    please help pass strings to doubles and strings to ints

    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a double

    cupofjava666 wrote:
    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a doubleThink he means blank.
    Check the Wrapper classes (Double, Integer) in the api.
    parseInt() parseDouble() both take a string and return a primitive.
    String s = null;
    if(s == null) should do the trick!
    Regards.
    Edited by: Boeing-737 on May 29, 2008 11:08 AM

  • Why jvm maintains string pool only for string objects why not for other objects?

    why jvm maintains string pool only for string objects why not for other objects? why there is no pool for other objects? what is the specialty of string?

    rp0428 wrote:
    You might be aware of the fact that String is an immutable object, which means string object once created cannot be manipulated or modified. If we are going for such operation then we will be creating a new string out of that operation.
    It's a JVM design-time decision or rather better memory management. In programming it's quite a common case that we will define string with same values multiple times and having a pool to hold these data will be much efficient. Multiple references from program point/ refer to same object/ value.
    Please refer these links
    What is Java String Pool? | JournalDev
    Why String is Immutable in Java ? | Javalobby
    Sorry but you are spreading FALSE information. Also, that first article is WRONG - just as OP was wrong.
    This is NO SUCH THING as a 'string pool' in Java. There is a CONSTANT pool and that pool can include STRING CONSTANTS.
    It has NOTHING to do with immutability - it has to do with CONSTANTS.
    Just because a string is immutable does NOT mean it is a CONSTANT. And just because two strings have the exact same sequence of characters does NOT mean they use values from the constant pool.
    On the other hand class String offers the .intern() method to ensure that there is only one instance of class String for a certain sequence of characters, and the JVM calls it implicitly for literal strings and compile time string concatination results.
    Chapter 3. Lexical Structure
    In that sense the OPs question is valid, although the OP uses wrong wording.
    And the question is: what makes class Strings special so that it offers interning while other basic types don't.
    I don't know the answer.
    But in my opinion this is because of the hybrid nature of strings.
    In Java we have primitive types (int, float, double...) and Object types (Integer, Float, Double).
    The primitive types are consessons to C developers. Without primitive types you could not write simple equiations or comparisons (a = 2+3; if (a==5) ...). [autoboxing has not been there from the beginning...]
    The String class is different, almost something of both. You create String literals as you do with primitives (String a = "aString") and you can concatinate strings with the '+' operator. Nevertheless each string is an object.
    It should be common knowledge that strings should not be compared with '==' but because of the interning functionality this works surprisingly often.
    Since strings are so easy to create and each string is an object the lack ot the interning functionality would cause heavy memory consumption. Just look at your code how often you use the same string literal within your program.
    The memory problem is less important for other object types. Either because you create less equal objects of them or the benefit of pointing to the same object is less (eg. because the memory foot print of the individual objects is almost the same as the memory footpint of the references to it needed anyway).
    These are my personal thoughts.
    Hope this helps.
    bye
    TPD

Maybe you are looking for

  • Issue in free SSL cert installation on Weblogic using keytool and Keystore

    Link which we used to follow below mentioned steps:- http://download.oracle.com/docs/cd/E13222_01/wls/docs81/secmanage/ssl.html#1167001 http://download.oracle.com/docs/cd/E13222_01/wls/docs81/plugins/nsapi.html#112674 Steps: 1) To generate keystore a

  • Error in Uploading of Documents into Portal through KM

    Hi All,       I Am new to KM, i am uploading the Word Documents into Portal through KM, this is the path : Content Administrator->KM Content->Documents---> here i am creating one folder after that i am uploading one Word Document into through Folder-

  • Graphical Display of Organisation Structure

    Hi All, I know we can view the Tree structure of Org Units reporting relationship in R/3 just dont know how to...Please guide me which transaction I should use to display the reporting structure in graphical format in R/3. Useful answers will be awar

  • Is there any tutorial for SAP Java Backend Development?

    Hi everyone, I am following the "How To - Part 1: Build an Agentry based app from scratch connecting to a SAP ERP back-end" to learn Agentry by myself. There are some Java code when creating the Steplet, StepHandler and Bapi that I dont understand. I

  • Duplicating contacts in Phonebook n whatsapp

    my iPhone 4S phone book contacts has been duplicate in All contact, and in whatsapp it duplicates all contact, that's mean each contacts show up twice, how can i fix it??? Many thanks to all expertises..