wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Java Array Initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Array Initialization" Watch "Java Array Initialization" New topic
Author

Java Array Initialization

Kiran Sonaje
Greenhorn

Joined: Aug 23, 2004
Posts: 23
I am getting lot compilation errors while compiling the program below.



The errors are occuring on all the lines commented in the above code.
I'm specifically interested to know why the line "hms = new float[2][5];" fails in compilation.
Can anybody please explain this to me?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3170
    
  10
You always need to be careful when declaring several arrays on one line.
The lineis actually decalring a two dimensional array of floats and a one dimensional array of floats. It is equivalent to

Declare all your arrays on separate lines and then it should be more clear.


Joanne
Kiran Sonaje
Greenhorn

Joined: Aug 23, 2004
Posts: 23
Hi Joanne,

Thanks for the reply.

For the above java code I am getting following compilation error




As per your suggetion if it is one dimensional array how does compiler complaining about 3 dimensional array. What you explained is solution for compilation and i am expecting what is the root cause for this? How JVM is handing this mechanism.

Waiting for reply .

Thanks

Kiran
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3170
    
  10
My mistake.
will declare a three dimensional array. So the reason for your compilation error is that you are trying to assign a two dimensional array to a three dimensional array reference.
Kiran Sonaje
Greenhorn

Joined: Aug 23, 2004
Posts: 23
Thanks Joanne

But this is not really i was expecting. I wanted why not how?

This is the answer, hope it will help you out.






Thanks

Kiran
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Array Initialization
 
Similar Threads
Simple prob
Array two dimension
2 D Arrays
java.lang
time comparison between given periods