How do i write huge programs in java??i need to write a 8000 lines program?
Utkarsh
2011-08-04 11:12:56 UTC
i had written my full program in the 'main' function but an error saying "code too large" is displayed...pls help me find an alternative way of writing such a long program
Three answers:
?
2011-08-04 11:30:04 UTC
I'm not really familiar with Java, but after some digging it seems that the Java bytecode has a method limit of 64k bytes. If you exceed that limit it will throw the "code too large" error.
Try refactoring your code and separate out some functions into different classes and put them in a package.
If this is indeed the root of your problem, what were you thinking cramming all that code into a single main function?
deonejuan
2011-08-04 19:33:57 UTC
You break your code up into logical packages especially if it is a GUI program.
Use methods. Putting everything into main makes the JVM want to load everything into the heap as a static program.
Create an Object in main(). Example:
public class BattleshipGalacta {
public static void main( String [] args ) {
new GattleshipGalacta().init();
}
private void init() {
int x = 0;
int y = 1;
run();
}
private void run() {
System.out.println("How old are you?");
}
}
}
Warren
2011-08-04 18:39:52 UTC
Read a book on object-oriented design/principles and then redesign your program
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.