This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

code too long

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all of you for quick reply & suggestions.

Regards,
Sanjeev.
 
No, tomorrow we rule the world! With this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic