Forums Register Login

Explain the output? ( Anonymous Arrays)

+Pie Number of slices to send: Send
Class A{
public static void main{
System.ou.println(new int[] {1,2,3,4,5});
}
}

What dose it print in the output screen and why???


Thank you in advance.
+Pie Number of slices to send: Send
Hi Srikanth,

Code has compiler error!!!
+Pie Number of slices to send: Send
Did you compile and run it? If not do so. If you do not understand the output that was printed, then ask again.

And please check our JavaRanch Naming Policy and change your displayed name to conform with it. I believe that you have been previously requested to do so in another topic's thread.
+Pie Number of slices to send: Send
As Chandra Bhatt pointed out, the code you have presented here is just wasting peoples' time.
+Pie Number of slices to send: Send
Srikanth,
It gives compiler error because of incorrect use of System.ou.println.
If it is a typing error and it should be Syste.out.println, it will output the memory address of the array object only. It does not print elements of the array object because it does not access array elements in this code.
-Suman
+Pie Number of slices to send: Send
The correct code
class A{
public static void main (String args[]){
System.out.println(new int[] {1,2,3,4,5});
}
}

would print memory address of Anonymous array
+Pie Number of slices to send: Send
Sorry, it should be System.out.println, not Syste.out.println. My computer has a problem. Suddenly a black screen appears and I miss a letter even if I type it.
-Suman
+Pie Number of slices to send: Send
Hi Srikanth,

I found some interesting observation with your code.

output
[S@1b90b39 --> Sop(new short[] {1,2,3,4,5});
[I@1b90b39 --> Sop(new int[] {1,2,3,4,5});
[B@1b90b39 --> Sop(new byte[] {1,2,3,4,5});

1.Array's are represented as objects in java.
2.Object's toString() method displays fallowing information:
className@hashCode.

in our case its an array.
So for class name it has taken

S for short
I for int
B for byte.
fallowed by @ , 1b90b39(hashcode).

Please get back to me ...
+Pie Number of slices to send: Send
The above pattern works for byte,short,int,float,double arrays.
But will not work for char and long !

Why doesn't work for char:Reason: PrintStream has function which takes char[] and prints the contents.
void println(char[] x)
Print an array of characters and then terminate the line.

Why doesn't work for long:
I too don't know.
But i got this result: [J@1b90b39.

I think its waste of time in certification view point.
Any way have nice time. I think we are crossing boundaries.
+Pie Number of slices to send: Send
Hi Srini,

1- For long prefix "J" J@hashCode
2- for char some three boxes

Good observation! But reason unknown!


reply my equals() post please!!!

cmbhatt
+Pie Number of slices to send: Send
I don't know their reasoning, but the class name for a long[] is [J.



prints [J

The reason that SOP acts differently with a long[], int[], float[], double[], etc. than with a char[] is that there is a method named println in PrintStream which matches char[], but the only println method that the other arrays match is the one that accepts Object.
+Pie Number of slices to send: Send
Both Suman and Vidya wrote that

(whatever) would print out the memory adress of (something).



No way.
Java is platform independent.

Bu.
+Pie Number of slices to send: Send
Date problem.

Can anyone tell me how I can enter following data in publisher table?

PublishID, PublishDate, AuthId
111, 07-06-05, SSS

It is giving problem with entering the date value.

Thanks.
It's never done THAT before. Explain it to me tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 921 times.
Similar Threads
overloading n overriding
Order of Filter Execution
jsp:useBean doubt..
Wats the output..... Explanations needed....
about thread.start() and thread.run()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:44:57.