File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes maximum array size in applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "maximum array size in applet" Watch "maximum array size in applet" New topic

maximum array size in applet

may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
What is the maximum size of a array in java applet?
I want to define a very big array,for example: int data[1728000][3] in my applet, then read data from ASCII file into this array, then draw three lines accoring to this array, is it possible?
I tested a smaller array first: int data[72000][3], then tried to draw a three lines in canvas according to this data array. I checked data[][] array, I have got all the data inside the data[][], but when I drew, I only got one line, then I got the error message: arrayindexoutofboundexception:72000 and a lot of other error?
What to do with these? Thanks for your help!!
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
In theory I suppose array size is only limited by the maximum size you can define the array to be, in which case that is the max size an integer can be in Java. Since you get a 32-bit two's compliment number to use then this is 2147483647 - way bigger than 1728000. I would suspect though that creating such a big array would have significant performance issues, especially in an applet. I'd have a look at the BufferedReaders available in for your requirements.
That aside, your problem is not to do with running out of space in an array. An ArrayIndexOutOfBoundException occurs when you try to reference an array element which is beyond the bounds of the defined array. e.g.

Remember that arrays are indexed from 0 not 1. So the maximum index in your 2D array is data[71999][2], and you seem to be asking for the 72000 element.
I agree. Here's the link:
subject: maximum array size in applet
jQuery in Action, 3rd edition