Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

code too long

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting data from excel sheet & creating a two dim object array.
I am able to generate java code successfully file based on that data excel
But while compilation of that file, I am getting code too long error.
I am able to create two dim object array of 2425 rows but more than that is not working.
I am surprised that there is limit for writing code in java file.
I will appreciate your comments.
Thanks.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I am surprised that there is limit for writing code in java file.


There isn't. Show us your code (or a truncated version if it is very long).
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


able to compile this file.

if I add more records in excel file, I am able to generate java file properly but when I compile it, it gives me error.
[ October 04, 2005: Message edited by: sanjeev mehra ]
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is indeed a limit to the amount of bytecode in a method. Initializing a long array can exceed that limit. Instead of hardcoding the data, write it into a file, and have the class read it in at runtime.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yikes, I'd guess you've run into a system or compiler limit that's not necessarily part of the language spec.

Can you change your code generator to write all the data to a file and read the file in your Java program? Then your code could be very short:


You could probably even open the spreadsheet as a database with JDBC/ODBC or one of the Java COM bridges like JACOB or a special office IO project like POI.

Any of those choices sound appealing?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Stan James:
Yikes, I'd guess you've run into a system or compiler limit that's not necessarily part of the language spec.



It's not explicitly part of the language, but it's implicitly included because it's part of the VM spec. The size of a method's bytecode is kept in a UINT16, so 65535 bytes is the maximum. Not everyone realizes this, but when you write

int[] x = { 1, 2, 3 };

The compiler emits code that looks like

int[] x = new int[3];
x[0] = 1;
x[1] = 2;
x[2] = 3;

and each of those assignments can take quite a few bytes to encode, as the values have to be fetched from the constant pool and put on the stack, the array reference put on the stack, and then the assignment bytecode invoked.
[ October 04, 2005: Message edited by: Ernest Friedman-Hill ]
 
sanjeev mehra
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you for quick reply & suggestions.

Regards,
Sanjeev.
 
You may have just won ten million dollars! Or, maybe a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic