1

Do we have any number of lines limit in a Method ,like wise limit for variable and methods in java? And also I was getting compilation error when I was Assigning 100000 ints to one int array, is there any limit for the same?

Error in eclipse:Too many constants, the constant pool for Tst(this is class) would exceed 65536 entries

damodaram
  • 67
  • 11

2 Answers2

3

Do we have any number of lines limit in a Method

Maximum size of a method in Java 7 and 8

65535 bytes Long// But we should take care of Java coding standards, code should be readable

,like wise limit for variable and methods in java?

Max name length of variable or method in Java Maximum Method Name Length

NO limit as such// But we should take care of Java coding standards, code should be readable

And also I was getting compilation error when I was Assigning 100000 ints to one int array, is there any limit for the same?

100000 should be fine, should not be an issue

SIZE 100000,

int num[] = new int[100000];

SIZE Integer.MAX_VALUE,

int num[] = new int[Integer.MAX_VALUE];

Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit

In Java, arrays internally use integers (int not Integer) for index, the max size is limited by the max size of integers. So theoretically it is 2^31-1 = 2147483647, which is Integer.MAX_VALUE. But in recent HotSpot JVM it has been observed that the max size of array can be Integer.MAX_VALUE - 5.

Error in eclipse:Too many constants, the constant pool for Tst(this is class) would exceed 65536 entries

Refer Java “too many constants” JVM error

Community
  • 1
  • 1
Ankur Singhal
  • 26,012
  • 16
  • 82
  • 116
  • for last question,{1,2,3,....................}(if we initialize int array with 100000 integers) I was getting compilation error – damodaram Dec 08 '15 at 10:57
  • Error in eclipse:Too many constants, the constant pool for Tst would exceed 65536 entries – damodaram Dec 08 '15 at 11:06
0

You can write whatever you need, since you don't reach the JVM's limit of 65535 bytes of bytecode per method. But be careful, a method with too many code lines is usually associated with a "bad" design... If you can, try always to split the tasks, make it as more specific as you can a huge method is Not always flexible, robust and reusable