File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Will memory be allocated 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 » Beginning Java
Bookmark "Will memory be allocated" Watch "Will memory be allocated" New topic

Will memory be allocated

faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Hello ranchers ,

If we write

int a[] = new int[10];

we know 40 bytes of memory will be allocated .

but what if i write

int a[] = new int[0] ;

will memory be allocated , if yes why ?

Thanks in advance
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Your basic assumption is invalid. You don't know that 40 bytes will be allocated -- you know that more than 40 bytes will be allocated, but you don't know how much more. A zero-element array does indded have a finite size, but the size is dependent on the JVM implementation, not something you can find out from the Java language itself.

[Jess in Action][AskingGoodQuestions]
faisal usmani
Ranch Hand

Joined: Jan 14, 2006
Posts: 139
Thanks sir ,

got the point
I agree. Here's the link:
subject: Will memory be allocated
It's not a secret anymore!