If "String[ ]args" is a valid syntax, why "int( )func" is invalid?

May sound stupid but,
If "String[ ]args" is a valid syntax, why "int( )func" is invalid ?

I know Java creators have made String[ ]args as valid for easy understanding and readabilityThey did that to effect a major improvement over the confusing 'C' syntax. In 'C', if you haveint a[], b, c, d; (i) the 'array-ness' only applies to a; (ii) you have the datatype distributed on both sides of the variable name; (iii) you have multiple datatypes being declared in one line of code (both int and int[]). All of which Gosling (and I) found counter-intuitive. In Java if you writeString[] a,b,c;they are all arrays, and the entire datatype is on the left before any identifiers. It's a better syntax.
but isn't this same procedure can also be followed in functions?But (a) the current syntax isn't confusing or counter-intuitive; (b) changing it wouldn't improve 'easy understanding'; and (c) multiple functions aren't declared in a single line of code anyway.
So your question is pointless.

Similar Messages

  • 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 should i write main(String[] args)?

    Hello,
    I don't know why i am obliged in the main function of the class to send an array of string as parameters?
    Thanks

    Actually I think this is a great question!
    main()
    Any java application has to have a main method to do anything, but as you gain further into java and object orientated practices you will start writing lots of stuff that do NOT have a main method but are *.java and *.class files, neither will they do anything unless they are attached to a program with a main. Andthen as you get DEEPER still you might even have 'private synchronised void main(String[] args)' - though not too often.
    Why an array of strings? Hmmm ...pauses ...thinks, there is no obvious reason, other than the fact that if you're going to pass parameters from 'java ...' command line to the application. This is, logically, the most potentially useful data type to have. There may well be other reasons for this, so the answer to the second part of your question is a logical deduction - it may not be right.

  • Why can't created an object in the "public static void main(String args[])"

    Example:
    public Class Exp {
    public static void main(String args[])
    new Exp2();-------------> To Occur Error
    Class Exp2 {
    public Exp2()

    You can't create an inner class within main, because
    it is a static method. Inner classes can only be
    created by true class methods.This is not correct. You can create an inner class object in a static method. You just have to specify an outer class object that the inner class object should be created within:
    Exp2 exp2 = new Exp().new Exp2();

  • String[] args fights String... args

    Hi,
    I thought this error message was a joke at first, but it's for real:
    Arrayz.java:15: cannot declare both in(java.lang.String,java.lang.String[]) and in(java.lang.String,java.lang.String...) in krc.utilz.ArrayzPlease, would anyone care to offer an opinion as to WHY the compiler does not differentiate between String[] args and String... args. Obviously String... args is implemented internally as String[] args, but that really shouldn't effect the interface... and if they are internally equivalent then wny not allow a syntax that effectively declares both in one... It's just that I would have thought it was possible (and desirable) for the compiler & JVM to do the required parameter matching for both definitions... in my mind the calling parameter list of (String, String, String) is distinct from (String, String[]) ... Or does java (like C/C++) internally not differentiate between the types reference-to-String and reference-to-array-of-Strings and reference-to-array-of-array-of-Strings ????
    I'm just a tad miffed about this... I mean, it's easy to work around in at least a dozen simple ways, it's just that the compiler didn't do what I expected it to do, so it should just pull it's socks up, and, well, you know, Work!
    Here's the code... complete with compiler error.
    package krc.utilz.stringz;
    public class Arrayz
        * returns true if the given value is in the args list, else false.
        * @param value - the value to seek
        * @param args... - variable number of String arguments to look in
      public static boolean in(String value, String... args) {
        for(String a : args) if(value.equals(a)) return true;
        return false;
      //Arrayz.java:15: cannot declare both in(java.lang.String,java.lang.String[]) and in(java.lang.String,java.lang.String...) in krc.utilz.Arrayz
      public static boolean in(String value, String[] array) {
        for(String s : array) if(value.equals(s)) return true;
        return false;
    }Thanx all. Keith.

    I didn't know that. Cool!
    package forums;
    class VarArgsTester
      public static String join(String FS, String... args) {
        if (args==null) return null;
        if (args.length==0) return "";
        StringBuffer sb = new StringBuffer(args[0]);
        for (int i=1; i<args.length; i++) {
          sb.append(FS+args);
    return sb.toString();
    public static void main(String[] args) {
    System.out.println(join(" ", "Your", "momma", "wears", "army", "boots"));
    String[] words = {"But", "she", "looks", "very", "nice", "in", "them"};
    System.out.println(join(" ", words));
    I was expecting a compiler error from the line[
    pre]System.out.println(join(" ", words));
    Thanks ~Puce.

  • Servermgrd[584]: FIXME: IOUnserialize has detected a string that is not valid UTF-8, "v\035\363d".

    All,
    I am having a very odd problem.
    I have recently setup a Mac OS X Mavericks Server for the purposes of NetRestore.
    Everything setup fine, no issues whatsoever and the server has been running non-stop for the past 78 days.
    I've already imaged about 100 MacBook pros off of this server without a problem.
    This morning I come in, start up an MBP that needs to be imaged and it sees the netrestore volumes and attemps to boot to it
    then stops and doesn't go anywhere.
    I've had my NBI's on an external firewire 800 drive (1TB Lacie Rugged) and its been working fine.
    I've checked my logs numerous times and the only error I can find is: servermgrd[584]: FIXME: IOUnserialize has detected a string that is not valid UTF-8, "v\035\363d".
    The exact same error keeps repeating every 10 seconds or so.
    I read in another forum that sometime Mavericks Server doesn't like NBI images on external volumes, so I moved them to the standard /Library/Netboot/NetBootSP0 folder on the boot volume and turned off the external drive.
    I'm able to NetRestore again now, but the process is far slower then it was previsously and the error above still persists.
    I've rebooted the server, stopped and restarted the services, made sure no changes have been made on the network, and fully updated the server via software update.
    Any ideas would be greatly appreciated!
    Thanks in advance.

    I post some other error.
    I don't understand why some times when I reboot I don't get any errors and why some Ive this:
    Mac OS X Versione 10.4.9 (Build 8P2137)
    2007-04-26 09:26:54 +0200
    At revision 7057.
    Apr 26 09:27:02 MacBook diskarbitrationd[49]: SystemUIServer [265]:15143 not responding.
    Apr 26 09:27:02 MacBook /System/Library/Frameworks/ApplicationServices.framework/Frameworks/ATS.framewo rk/Support/ATSServer: FIXME: IOUnserialize has detected a string that is not valid UTF-8, "ˆ®˜Ëî^?Ío".
    Can any help me to found the problem???????
    Thanks so much to all

  • Is this a valid syntax for main() function

    hi
    here is a very basic question...
    is this signature a valid entry point to an application..?
    public static int main(String[] arg)
    i compile it and it gives me no error but when i run it, it throws an exception in main...
    I am asking this question because one of the certification books has a question which says that this is a valid signature.
    please do let me know ur comments...
    thanks a lot.

    thanks for all the replies....
    it compiles and here is the run time error that i get
    Exception in thread "main" java.lang.NoSuchMethodError: main
    also the book is Complete Java2 Certification study guide 2nd Ed Sybex
    chapter 1, page 26, question 3.
    which of the following sig. are valid for the main() method entry point of an application
    a> public static void main()
    b> public static void main(String arg[])
    c> public void main(String[] args)
    d> public static void main(String [] arg)
    e> public static int main(String [] arg)
    so the answers shud be b,d and not b,d,e right?
    thanks

  • Error 1 occurred at Scan From String (arg 1)

    I am communicating with the AT Trainer 5000 via serial port to USB converter.
    I installed all drivers of converter successfully and it is shown in MAX as com port. I also installed VISA software. 
    I am using labview 2013 version.
    When I connect the hardware to PC via usb to serial converter, try to run the program for seeing of real time graphs, I am receiving this error Error 1 occurred at Scan From String (arg 1) whereas there is no waveform shown in waveform chart. 
    Also read buffer didn't show an incoming data at read buffer.
    Other details for this error is
    Possible reason(s):
    LabVIEW: An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
    Also pics of error is:
    Program is also attached. Please checked the also.
    Expert please help me how to get rid of this error.
    Attachments:
    Project.vi ‏23 KB

    Since you are using the termination character, you should not use the Bytes At Port property node.  Just set the number of bytes to read for the VISA Read to something really high (larger than what you expect in a single transmission).  The VISA Read will stop reading once the termination character is reached.
    Now, what is the format of the data coming from the instrument?  I see you are converting an ASCII Hex string into a number while trying to also turn it into a double.  That is likely why you are getting your error.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions

  • Newbie to java(String[] args and String args[])

    what is the difference is it just that the arguments/parameters givven with the program are assigned to String (String[] args) or that they are assigned to args (String args[]) and why do you have to define the args part if yo don't assign something to it..
    might seem a dumb question, but hey, when i say i'm new at it i mean new!!!!

    Dear newbie,
    when one issues a command on dos prompt like
    c:\>java YourProgramName , then how would the program know where to begin executing the code. To make it standard and simple java.exe locates the method named main which has a particular signature that is , you can only define one main method as
    public static void main(String [] args){
    // remaining code
    1. public [Access Specifier ]This method has to be declared public because it will be accessed from outside the class by jvm.
    2. It is declared static because you are not allocating any memory to this class by the new operator for the main method to be executed by jvm. Only static methods and variables can be accessed without the need to create object of the class where they are defined. So when you say static, the jvm automatically allots memory to this method, accesses it and starts to execute the code declared in main method. All methods and variables (which are not defined static) have to be accessed by creating objects of the class in which they are defined.
    So if you have a class which has static main(String args[]) and another method int multiply() which is not static, then to use it in main you will have to create an object of the class where it is defined.
    public class yourClass{
      public int multiply(int a, int b){
       return a*b;
       public static void main(String args){
           System.out.println("Product of 5*6 = "+ 5*6 );
            // you can not say
            // System.out.println(multiply(4,5)); because multiply is not a static method and main can not access it directly so what you have to do is
         yourClass yourObject=new yourClass();
       System.out.println("Product is "+ yourObject.multiply(4,5));
    } 3 Return type is void because this method does not return any value.
    4. (String [] args) is equivalent to (String args []). Java has provided this functionality and what one is doing here by either statement is making a String array named args. "[]" before or after args just implies that the Variable args is of Type String Array.
    5. The Use of this signature for main method is that you can pass command line arguments which then your code can manipulate to give result, ie say if your main sums up two numbers
    //when hard coded
    public static void main(String args){
    System.out.println("Product of 5*6 = "+ 5*6 );
    //Using command line arguments
    public static void main(String args){
    int a=Integer.parseInt(args[0]);
    int b=Integer.parseInt(args[1]);
    System.out.println("Product Of "+a+"*"+b+" ="+ a*b);
    }So you see the difference ? in case 1. you have to recompile the code to find the product of say 8 and 7 whereas in command line argument you just say
    c:\>java findProduct 7 8 // for product of 7 and 8
    c:\>java findProduct 15 8 // for product of 15 and 8 ...
    ie the classs need not be recompiled....
    hope that helps you
    best wishes and regards,
    gaurav

  • String[] args == String args[] ?

    Why are there two ways of declarating an array?
    e.g.: int[] bla;
    or int bla[];
    What's the difference? And what's Suns recommendation?
    e.g.: public static void main(String[] args)
    or public static void main(String args[])
    I always made it the first way...

    Why are there two ways of declarating an array?
    e.g.: int[] bla;
    or int bla[];
    What's the difference? And what's Suns
    recommendation?Apart from being textually different, nothing. They generate the same byte codes.
    Sun does not have a recommendation as far as I know. My recommendation is to use which ever you think makes your code easier to read.

  • What happens when main(String[] args)

    Hi techies,
    I am trying to understand, "how the JVM invokes public static void main(String[] args)".
    I had gone through JVM tutorial, and found that there are 2 different types of classloaders 1. bootstrap loader 2. user defined class loader.
    I had gone through java api for class loader class. i did not find the method main(String[] args).
    I am having confusion whether bootstrap loader calls main(String[] args)(or) userdefined classloader calles main(String[] args).
    Why do we have to give String[] args as argument to main??
    can you guys guide to understand this .
    regards,
    Krishna

    Hi techies,
    I am trying to understand, "how the JVM
    invokes public static void main(String[] args)".
    I had gone through JVM tutorial, and
    found that there are 2 different types of
    classloaders 1. bootstrap loader 2. user defined
    class loader.
    I had gone through java api for class
    loader class. i did not find the method
    main(String[] args).
    I am having confusion whether bootstrap
    loader calls main(String[] args)(or) userdefined
    classloader calles main(String[] args).
    Why do we have to give String[] args as
    argument to main??
    can you guys guide to understand this
    regards,
    Krishnawell, you won't find main(String[] args) in the docs for ClassLoader, since it's not a method on ClassLoader!
    the bootstrap loader loads, verifies, prepares and initializes the class for which you pass the fully.qualified.name into the JVM, and looks for the static method on that class called 'main' which has a single argument, an array of Strings, and no return type ( I'm not 100% sure of that last part actually - I'll try it ) and begins a thread of execution on that method. from there, your program is run
    we have to give an array of Strings in order to pass arguments into the program
    it can't be a user-defined classloader that does this, because most of the time there won't be a user-defined classloader!

  • (String args[])

    public static void main (String args[])
    Probably the most famous line in Java.
    However, something just struck me. In my 4 months of programming experiance, I have yet to use the args[] array... I know 'args' is just a variable name, and it can be changed..... but, where do we use it? or rather, is there any use of it? I dont recall ever using it.... or even seeing code which uses the args array
    I just tried public static void main (int x) ..... didnt work.....
    I think it MAYBE has something to do with main being a thread. But I dunno ANYTHING about threads >.<

    I see what you mean. But, why an array of Strings? Why
    not an array of Objects?
    or an array of integers?Since main is intended as the entry point, and is likely to be called from the command line, String is the most appropriate. If it were int (or Integer) you couldn't do "java Foo Joe Shmoe". If it were object, you'd have to be able to handle LinkedList, JFrame, ResultSetMetaData, etc. What meaning would that have? And if you're writing main with the expectation that it's the only way into your program from the command line, you know that all that can from from that path is String (okay, numbers, but that's an easy mapping), so why would you have handling for those other types?

  • How to call java with public static void main(String[] args) throws by jsp?

    how do i call this from jsp? <%spServicelnd temp = new spServicelnd();%> does not work because the program has a main. can i make another 2nd.java to call this spServiceInd.java then call 2nd.java by jsp? if yes, how??? The code is found below...
    import java.net.MalformedURLException;
    import java.io.IOException;
    import com.openwave.wappush.*;
    public class spServiceInd
         private final static String ppgAddress = "http://devgate2.openwave.com:9002/pap";
         private final static String[] clientAddress = {"1089478279-49372_devgate2.openwave.com/[email protected]"};
    //     private final static String[] clientAddress = {"+639209063665/[email protected]"};
         private final static String SvcIndURI = "http://devgate2.openwave.com/cgi-bin/mailbox.cgi";
         private static void printResults(PushResponse pushResponse) throws WapPushException, MalformedURLException, IOException
              System.out.println("hello cze, I'm inside printResult");
              //Read the response to find out if the Push Submission succeded.
              //1001 = "Accepted for processing"
              if (pushResponse.getResultCode() == 1001)
                   try
                        String pushID = pushResponse.getPushID();
                        SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                        StatusQueryResponse queryResponse = sp.queryStatus(pushID, null);
                        StatusQueryResult queryResult = queryResponse.getResult(0);
                        System.out.println("Message status: " + queryResult.getMessageState());
                   catch (WapPushException exception)
                        System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
                   catch (MalformedURLException exception)
                        System.out.println("*** ERROR - MalformedURLException (" + exception.getMessage() + ")");
                   catch (IOException exception)
                        System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
              else
                   System.out.println("Message failed");
                   System.out.println(pushResponse.getResultCode());
         }//printResults
         public void SubmitMsg() throws WapPushException, IOException
              System.out.println("hello cze, I'm inside SubmitMsg");          
              try
                   System.out.println("hello cze, I'm inside SubmitMsg (inside Try)");                         
                   //Instantiate a SimplePush object passing in the PPG URL,
                   //product name, and PushID suffix, which ensures that the
                   //PushID is unique.
                   SimplePush sp = new SimplePush(new java.net.URL(ppgAddress), "SampleApp", "/sampleapp");
                   //Send the Service Indication.
                   PushResponse response = sp.pushServiceIndication(clientAddress, "You have a pending Report/Request. Please logIn to IRMS", SvcIndURI, ServiceIndicationAction.signalHigh);
                   //Print the response from the PPG.
                   printResults(response);
              }//try
              catch (WapPushException exception)
                   System.out.println("*** ERROR - WapPushException (" + exception.getMessage() + ")");
              catch (IOException exception)
                   System.out.println("*** ERROR - IOException (" + exception.getMessage() + ")");
         }//SubmitMsg()
         public static void main(String[] args) throws WapPushException, IOException
              System.out.println("hello cze, I'm inside main");
              spServiceInd spsi = new spServiceInd();
              spsi.SubmitMsg();
         }//main
    }//class spServiceInd

    In general, classes with main method should be called from command prompt (that's the reason for main method). Remove the main method, put the class in a package and import the apckage in your jsp (java classes should not be in the location as jsps).
    When you import the package in jsp, then you can instantiate the class and use any of it's methods or call the statis methods directly:
    <%
    spServiceInd spsi = new spServiceInd();
    spsi.SubmitMsg();
    %>

  • 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

  • How to pass (String[] args), as a parameter.

    * StringMethods
    * @author (Robin)
    * @version (1)
    public class StringMethods
        private String[] args;
        private int numArgs;
        public void printIt(String[] args)
            System.out.print ("You have entered " + numArgs + " Strings");
                if (numArgs > 10)
                    int temp = numArgs;
                    System.out.print (", the last " + (numArgs - 10) + " will not be processed.");
                    numArgs = temp;
            for (int i = 0; (i < numArgs) && (i < 10); i++)
            System.out.println ("[" + i + "] : " + args[i] + " is " + (args).length() + " characters long.");
    public void getArgs(String[] input)
    numArgs = input.length;
    arraycopy(input, 0, args, 0, numArgs-1);
    arraycopy(input, 0, args, 0, numArgs-1)This is my method class for my main method StringArray.
    What I want to know is how to pass command line arguments, i.e. {"example1", "example2", "example3"} from my main method to my method class?

    * StringMethods
    * @author (Robin)
    * @version (1)
    public class ArgMethods
    private String[] args = new String[0];
    private int numArgs;
    public String[] input = {"null", "null"};
    // constructor that takes string args to be manipulated by methods
    public ArgMethods(String[] input)
    numArgs = input.length;
    String[] args = new String[numArgs];
    System.arraycopy(input, 0, args, 0, input.length);
    public void printIt()
    if (args.length > 0)
    System.out.print ("You have entered " + numArgs + " Strings");
    if (numArgs > 10)
    int temp = numArgs;
    System.out.print (", the last " + (numArgs - 10) + " will not be processed.");
    numArgs = temp;
    for (int i = 0; (i < numArgs) && (i < 10); i++)
    System.out.println ("[" + i + "] : " + args[i] + " is " + (args).length() + " characters long.");
    else
    System.out.println ("You must enter at least one String at the command line.");
    public void reverseIt()
    if(args.length > 0)
    int next = args.length-1;
    for (int index = 0; index < args.length/2; index++)
    String temp = args[index];
    args[index] = args[next];
    args[next] = temp;
    next--;
    * StringArray
    * @author (Robin)
    * @version (1)
    public class stringArray
    public static void main (String[] args)
    int numArgs = args.length;
    // correct for output if strings less than 10 and greater than 0
    if (numArgs > 0)
    System.out.print ("You have entered " + numArgs + " Strings");
    if (numArgs > 10)
    int temp = numArgs;
    System.out.print (", the last " + (numArgs - 10) + " will not be processed.");
    numArgs = temp;
    for (int i = 0; (i < numArgs) && (i < 10); i++)
    System.out.println ("[" + i + "] : " + args[i] + " is " + (args[i]).length() + " characters long.");
    else
    System.out.println ("You must enter at least one String at the command line.");
    ArgMethods test = new ArgMethods( args );
    // test.printIt();
    // test.reverseIt();
    // test.printIt();
    *almost finished -- posting this up here so i can get it at home ((only accessible e-mail down plus can't find pen drive))..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for