Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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: 24204
44
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: 24204
44
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.
 
catch it before it slithers away! Oh wait, it's a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic