>> -> All the arrays when created are filled with 0, or null. Or is it
>> random numbers?
[quoted text clipped - 5 lines]
> false for booleans
> null for reference types
>>> -> All the arrays when created are filled with 0, or null. Or is
>>> it
[quoted text clipped - 9 lines]
> Not quite. Local variables (including local arrays) do not have
> default values. You are required to initialize them yourself.
Local variables are neither array members nor object fields. There is
no such thing in Java as a "local array". If you mean something like:
void method()
{
int[] iarr = new int[20];
...
}
the 20 members of iarr are, indeed, all initialized to 0.
> <http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.12.5>
>
> But it's never "random." Variables will always be initialized
> somehow
> in Java.
That is "Java (unlike C or C++) never initializes anything to random
values."
I won't say that I'm always right, and I welcome corrections when I'm
wrong, but this isn't one of those times.
Mark Space - 13 Mar 2008 00:47 GMT
> I won't say that I'm always right, and I welcome corrections when I'm
> wrong, but this isn't one of those times.
You said "anything." I'm not correcting you, per se, just clarifying
for other readers who might get confused.
Lew - 13 Mar 2008 01:04 GMT
>> I won't say that I'm always right, and I welcome corrections when I'm
>> wrong, but this isn't one of those times.
>
> You said "anything." I'm not correcting you, per se, just clarifying
> for other readers who might get confused.
He said,
> Java (unlike C or C++) never initializes anything to random values.
That is truth. If something is not initialized to a known value, it generates
a compiler error.
<http://java.sun.com/docs/books/jls/third_edition/html/defAssign.html>
You said,
> Local variables (including local arrays) do not have default values.
That is not truth. Locally declared arrays are initialized to default values.

Signature
Lew
Stefan Ram - 13 Mar 2008 01:03 GMT
>That is "Java (unlike C or C++) never initializes anything
>to random values."
In Java, in
{ final double d = java.lang.Math.random(); }
, »d« will be initialized to a random value.
(Run-time operations, of course, are not done by »Java«,
but by the JVM.)
In C, in
{ double d; }
, »d« will not be initialized to a random value, it will hold
an /indeterminate/ value (ISO/IEC 9899:1999 (E), 6.7.8, p10).
An indeterminate value is not a random value. But then,
actually, there are not random values (is »7« a random value?),
only random sequences.
Lew - 13 Mar 2008 01:05 GMT
>> That is "Java (unlike C or C++) never initializes anything
>> to random values."
[quoted text clipped - 4 lines]
>
> , »d« will be initialized to a random value.
Pseudo-random.

Signature
Lew
Mike Schilling - 13 Mar 2008 02:05 GMT
>> That is "Java (unlike C or C++) never initializes anything
>> to random values."
[quoted text clipped - 4 lines]
>
> , »d« will be initialized to a random value.
Not at all; if you know the algorithm used and the value of its
inouts, you can calculate that value precisely. It's no more random
than l in
long l = System.currrentTimeMillis();
> (Run-time operations, of course, are not done by »Java«,
> but by the JVM.)
[quoted text clipped - 5 lines]
> , »d« will not be initialized to a random value, it will hold
> an /indeterminate/ value (ISO/IEC 9899:1999 (E), 6.7.8, p10).
It's random as far as the programmer is concerned: it could literally
be any bit pattern at all.