简体   繁体   English

有多少变量,我们可以在java类中编写多少个方法,以及我们可以在java方法中编写多少行代码?

[英]how many variables, how many methods can we write in java class and how many lines of code can we write in java method?

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? 当我向一个int数组分配100000个int时,我也遇到了编译错误,是否有相同的限制?

Error in eclipse:Too many constants, the constant pool for Tst(this is class) would exceed 65536 entries eclipse中的错误:太多常量,Tst的常量池(这是类)将超过65536个条目

Do we have any number of lines limit in a Method 我们在方法中是否有任意数量的行限制

Maximum size of a method in Java 7 and 8 Java 7和8中方法的最大大小

65535 bytes Long // But we should take care of Java coding standards, code should be readable 65535字节长 //但我们应该关注Java编码标准,代码应该是可读的

,like wise limit for variable and methods in java? ,像java中变量和方法的明智限制?

Max name length of variable or method in Java Maximum Method Name Length Java 最大方法名称长度 中变量或方法的 最大名称长度

NO limit as such // But we should take care of Java coding standards, code should be readable 没有限制 //但我们应该照顾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? 当我向一个int数组分配100000个int时,我也遇到了编译错误,是否有相同的限制?

100000 should be fine, should not be an issue 100000应该没问题,应该不是问题

SIZE 100000, 尺寸100000,

int num[] = new int[100000];

SIZE Integer.MAX_VALUE, SIZE Integer.MAX_VALUE,

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

Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit 线程“main”中的异常java.lang.OutOfMemoryError:请求的数组大小超过VM限制

In Java, arrays internally use integers (int not Integer) for index , the max size is limited by the max size of integers . 在Java中,数组内部使用整数(int not Integer)作为indexmax size is limited by the max size of integers So theoretically it is 2^31-1 = 2147483647 , which is Integer.MAX_VALUE . 所以理论上它是2^31-1 = 2147483647 ,它是Integer.MAX_VALUE But in recent HotSpot JVM it has been observed that the max size of array can be Integer.MAX_VALUE - 5 . 但是在最近的HotSpot JVM中,已经观察到数组的最大大小可以是Integer.MAX_VALUE - 5

Error in eclipse:Too many constants, the constant pool for Tst(this is class) would exceed 65536 entries eclipse中的错误:太多常量,Tst的常量池(这是类)将超过65536个条目

Refer Java “too many constants” JVM error 请参阅Java“太多常量”JVM错误

You can write whatever you need, since you don't reach the JVM's limit of 65535 bytes of bytecode per method. 您可以编写所需的任何内容,因为每个方法没有达到JVM的65535字节字节码限制。 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 但要小心,一个代码行太多的方法通常会与“坏”设计相关联......如果可以的话,请尽量分割任务,使其更具体,因为一个巨大的方法并不总是灵活的,强大且可重复使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM