search

Home  >  Q&A  >  body text

Do the parameters in the main method in Java have to be String[]args?

Ask me, does anyone know?

ringa_leeringa_lee2773 days ago832

reply all(3)I'll reply

  • 阿神

    阿神2017-05-17 10:09:39

    If you don’t know, then you think you must.

    This thing is inherited from the unix (C) command.

    Normally, the main function of a C program is

    普通情况下这么写
    int main(int argc char **argv)
    有些情况下这么写
    int main(int argc, char *argv[], char **env)
    
    argc为参数数目
    argv为字符串数组。
    char **argv = char *argv[] = char argv[][]

    You can think that in terms of the main function, java is just a layer of packaging, that is, the java packaging only cancels argc and replaces argv from a two-dimensional character matrix to a string array.

    java’s args = C’s **argv,
    C’s argc = java’s args.count() (or args.length())

    reply
    0
  • PHPz

    PHPz2017-05-17 10:09:39

    The variable name can be changed, but the String array type cannot be changed. . . .

    reply
    0
  • 阿神

    阿神2017-05-17 10:09:39

    It can also be String... args
    haha

    reply
    0
  • Cancelreply