File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Maximum number of lines Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Maximum number of lines" Watch "Maximum number of lines" New topic

Maximum number of lines

Ravi Tanuku

Joined: Apr 06, 2005
Posts: 9
Is there any limit on the maximum number of lines in a java class and a java method?
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Don't think so. Why don't you write a really big method and find out?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

I don't know if there is a theoretical limit, but if there is, it wouldn't be very interesting to know. There certainly isn't a practical limit.

In real life, you should never write classes that are so big that the compiler can't handle them - because if the compiler can't, then the programmer certainly can't.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
There seems to be a limit of 64KB byte code within a method, which would also limit the amount of source code you can stuff into it. That's a feature of the JVM, so there's no way around it. There's a thread on this topic here.
[ September 05, 2005: Message edited by: Ulf Dittmer ]
I agree. Here's the link:
subject: Maximum number of lines
It's not a secret anymore!