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 Array Indexes And Compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array Indexes And Compiling" Watch "Array Indexes And Compiling" New topic

Array Indexes And Compiling

Craig Oliver

Joined: Aug 25, 2003
Posts: 21
So far I have found Java to be very strict with compiling and run time exceptions if things are not spot on. I was surprised the following compiled and ran okay considering there is no index given for arguments array when printed by method1.
public class MyClass
public static void main(String arguments[])
MyClass mc = new MyClass();
public void method1(String arguments[])
I was expecting compile error. In C, this would make sense as it would be pointer to start of character array, but in Java I do not understand what happens here. When I ran as
>java MyClass a b
it printed stuff like [java.lang.String;@cac268
Why was no error given or what is story with no index given when reference array?
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
Arrays are Objects in Java, so what you are seeing is the effect of calling the toString() method on the array Object - its the object reference rather than its actual contents.
I agree. Here's the link:
subject: Array Indexes And Compiling
jQuery in Action, 3rd edition