-2

In a video of the Oracle University for Java certification, the instructor just said that "the size of args is ten, so we can only send a maximum of ten elements". Has anybody heard of this?

I just tried it and it doesn't seem right.

package tests;

public class MainArgsSize {

    public static void main(String[] args) {
        for (String st : args) {
            System.out.println(st);
        }
    }
}
java tests.MainArgsSize 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Luis Sep
  • 2,384
  • 5
  • 27
  • 33
  • 2
    What is your question exactly? – Tdorno Aug 11 '13 at 16:40
  • 1
    I think the question is whether there is a maximum number of arguments that can be passed to a Java program - as far as I am aware there is none. – devrobf Aug 11 '13 at 16:42
  • 2
    "_In a video of the Oracle University for Java certification, the instructor just said that "the size of args is ten, so we can only send a maximum of ten elements"_" Is this video publicly accessible? – jlordo Aug 11 '13 at 16:42
  • You probably heard wrong or misunderstood something. No such restriction exists. – JavaNewbie_M107 Aug 11 '13 at 16:44
  • @Tdorno: My question is if anybody has heard anything like this. It doesn't make sense to me and she emphasized it. – Luis Sep Aug 11 '13 at 16:44
  • @jlordo: Sorry, it's not publicly accessible. – Luis Sep Aug 11 '13 at 16:44
  • 1
    You can have anything up to Integer.MAX_VALUE arguments (although I think Unix restrict what you can pass) – Andrew Martin Aug 11 '13 at 16:44
  • @AndrewMartin Indeed, there's a list of the number of arguments various Linux distros use here: http://www.in-ulm.de/~mascheck/various/argmax/#results Needless to say none of them are anywhere near as small as 10. – MrLore Aug 11 '13 at 16:50
  • The instructor is posing a problem. He may not mean no Java program can have more than ten arguments, but for the purpose of this assignment you can't use more than 10. (perhaps it could be do to a limitation in the program calling java) – Peter Lawrey Aug 11 '13 at 18:36

2 Answers2

2

From the Java documentation:

A Java application can accept any number of arguments from the command line.

[source]

However, these arguments are passed in the form of an array. From this link here: Do Java arrays have a maximum size?, the size of an array was discussed as being:

Integer.MAX_VALUE - 5

Therefore, that should be the limit.

Edit: Thanks for @MrLore who provided the following link discussing the limits on Unix machines in his comment above:

http://www.in-ulm.de/~mascheck/various/argmax/#results

Community
  • 1
  • 1
Andrew Martin
  • 5,619
  • 10
  • 54
  • 92
0

I'm fairly certain the limit is technically is 2147483647, or Integer.MAX_VALUE. Perhaps the instructor was referring to a business rule for your particular program?

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84