• Post Reply Bookmark Topic Watch Topic
  • New Topic

maximum number of statements in a method  RSS feed

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there a limit for the number of statements in a java method or is it possible to have any number of statements in a java method ?

Thanks in advance.

John
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Technically I'm not aware of there being a restriction, but I would be wary of writing bloated methods performing more than one task and running into several hundered lines. Always best practice to split something up into several smaller methods to avoid confusing code. Also makes it easier to track bugs IMO.
 
John Mallavalli
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes..I understand that its a bad practice to have bloated methods. I just wanted to know if at all there is any restriction on the limit for the number of statements in a java method.
Anyway thanks for your response.

- John
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if such limit exists but there's a maximum size of bytecode compiled method. It's 64KB.
[ August 26, 2004: Message edited by: Vlado Zajac ]
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I recall, there is a limit on the size of a compiled method based on the number of byte codes - not the number of lines. I think the limit is due to the fact that jumps are coded in 16 bits so your compiled method must be less than 32K in size. This limitation should be familiar to anybody who has coded in assembly language.
Bill
 
John Mallavalli
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!