Max size of a JAVA CLASS

D

Deepak Nayal

Can anybody please let me know what is the maximum size of a JAVA class
file?

What is the maximum number of methods in a JAVA class?

This is kinda urgent. :)

Thanks in Advance.
Deepak
 
T

Thomas Schodt

Can anybody please let me know what is the maximum size of a JAVA class
file?

There is not specific limit.
I guess a theoretical maximum size be established from the data available
in the VM Spec.
What is the maximum number of methods in a JAVA class?

That will be limited by the constant pool.
The maximum number of entries in the constant pool is 65536.
Each method takes up several entries. Read the VM Spec for details.
 
A

Alex Hunsley

Deepak said:
Can anybody please let me know what is the maximum size of a JAVA class
file?

What is the maximum number of methods in a JAVA class?

This is kinda urgent. :)

Thanks in Advance.
Deepak
Just out of interest, why is the maximum size of a java class or limit
on number of methods relevent? i.e. why or how have you ended up with
such a huge class?
alex
 
J

jerome moliere

Alex said:
Just out of interest, why is the maximum size of a java class or limit
on number of methods relevent? i.e. why or how have you ended up with
such a huge class?
alex is just plain right :)
I'd like to add that the only relevant information is the max size for
methods which is bound to 64k. but this limit is not really a limit,
because who could maintain code with such methods ? :)

My 2 cents
jerome
 
M

Michael Borgwardt

jerome said:
alex is just plain right :)
I'd like to add that the only relevant information is the max size for
methods which is bound to 64k. but this limit is not really a limit,
because who could maintain code with such methods ? :)

Oh, it's quite easy to end up with such large method when you put large amounts
of literal data into the code. Or when generating code (whit does not have to be
maintained). Or both.
 
D

Dale King

Thomas Schodt said:
There is not specific limit.
I guess a theoretical maximum size be established from the data available
in the VM Spec.


That will be limited by the constant pool.
The maximum number of entries in the constant pool is 65536.
Each method takes up several entries. Read the VM Spec for details.

Note that the limits will be going up in JDK1.5.
 
J

John C. Bollinger

Deepak said:
Can anybody please let me know what is the maximum size of a JAVA class
file?

Practically unlimited, if you're talking about the possibility of
swelling a class file with useless garbage. Even if you want to
restrict yourself to class files that a real, general-purpose java
compiler might produce, the upper limit is still pretty high: hundreds
of megabytes, certainly; possibly as much as about two gigabytes.
What is the maximum number of methods in a JAVA class?

See the JVM spec:

http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#88659

That doesn't tell the whole story, because the various constraints are
not independant. For instance, although there is room in the method
table for 65536 methods, each one requires a minimum of two entries in
the runtime constant pool, in which there are only 65535 positions
available. On the other hand, that limit doesn't apply to methods
inherited from superclasses. Each method (of any class) that you invoke
in your class' code requires a total of six (if I've counted them
correctly) entries in the constant pool, although some of these could be
shared with other method invocations.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top