aspose file tools*
The moose likes Beginning Java and the fly likes Regarding big java files... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regarding big java files..." Watch "Regarding big java files..." New topic
Author

Regarding big java files...

Deepti VB
Greenhorn

Joined: Jan 19, 2005
Posts: 1
Hi Everyone,

I've got 2 questions:

1. In my knowledge maximum size of a java .class file can be 64K. Is it true?If yes then what happens if I've .java file having code so big in size that it would exceed this limit.

2. In C++ to make things clean i can write different methods of a class in different .cpp files, Is any such feature exist in java too...or if a class of mine is having 1000 functions i'll have to write all of them in the same .java file?

Regards,
Deepti
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

1. No. Where did you read this?
2. It doesn't sound like spliting methods out to different files helps make things cleaner, but I thats what you like I'm afraid you can't do it in Java.

This is a bit of a catch-all statement, but: if you have a class which has 1000 methods(there are no functions in Java) then I'd review your design. A class which does that much would have to be very much the exception not the norm. For example in the app I'm working on just now (which has c4000 classes), I can only think of one which has more than around 20 methods and its a wrapper class to some legacy functionality provided in a different language.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24185
    
  34

There are some limits imposed by the class file format. There can be no more than 64K fields in a class, for example, nor more than 64K methods in a class. A single method can have no more than 64K local variables, nor more than 255 arguments.

You'd have to try mightily to write a class horrifying enough to bump into any of these limits, but there is one that people do hit from time to time: the bytecode for a single method is limited to 64K bytes. This essentially never happens in normal coding, but it can arise in two special situations: first, if someone is trying to translate an old, badly-written C or FORTRAN program line-for-line into Java, all inside the main() method; or second, in machine-generated code (if, again, the generator is a badly-written one.)

I concur with Paul's assessment that classes should be small(ish) and do one thing well, and such a class will never come anywhere near any of these limits.


[Jess in Action][AskingGoodQuestions]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
There is also a limit of 64KB per method in a classfile.
We've run up to that limit several times in large JSPs, prompting the largest of them to be cut up into sections which are dynamically included into the result.

If you have to worry about having too many methods in a class you're almost certainly in need of a very hefty lesson in design...


42
Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
interesting figures..
 
Don't get me started about those stupid light bulbs.
 
subject: Regarding big java files...