Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum number of methods a Java class can have?

Tags:

java

class

I am thinking to build a VERY large Java class, is there any limit on the number of methods the Java class can have? Can it go into the millions of methods?

update: The purpose is, yes, to make a "God" class.

like image 766
Phil Avatar asked Dec 03 '10 03:12

Phil


People also ask

How many methods should a class have in Java?

a) Methods should not have more than an average of 30 code lines (not counting line spaces and comments). b) A class should contain an average of less than 30 methods, resulting in up to 900 lines of code. c) A package shouldn't contain more than 30 classes, thus comprising up to 27,000 code lines.

How many methods are too many in a class?

In PMD, the default behavior of the TooManyMethods rule is to identify and flag classes with 10 or more methods as potential errors. This is just an arbitrary number, though.

How many methods does Java have?

There are two types of methods in Java: Predefined Method. User-defined Method.

What is the maximum number of Java?

The int type in Java can be used to represent any whole number from -2147483648 to 2147483647.


1 Answers

According to the Java class file specification the limit is 65535:

4.10 Limitations of the Java Virtual Machine

The following limitations of the Java virtual machine are implicit in the class file format:

  • The number of methods that may be declared by a class or interface is limited to 65535 by the size of the methods_count item of the ClassFile structure (§4.1). Note that the value of the methods_count item of the ClassFile structure does not include methods that are inherited from superclasses or superinterfaces.
like image 100
John Kugelman Avatar answered Sep 20 '22 00:09

John Kugelman