Hi,
Question 1:
I am getting not a statement error on the following
java code sample (assume this is within a class and in the main method)
if(true)
Object o = new Object(); //# 1
But the error goes away if I do:
if(true)
{
Object o = new Object(); // # 2
}
My interpretation of why the compiler throws the error at #1 is that the scope of the variable is ambiguous in that context and wide open to interpretation. So the compiler cannot decide the correct scope. But in # 2, by enclosing the statement within curly braces, the scope becomes clear i.e. the scope is local within the block. Hence the compiler is happy.
Is my interpretation correct? Kindly provide your views.
==============================================================================================================
Question 2:
This question is about the JVM. The question is "When does a JVM run on my machine"?
Is it when I open a command window and type "java MyClass"" ? i.e when I run a java program? Does it mean if I open ten command windows and run "java MyClass" on each one of them, then am I running ten different JVMs on my machine?
If this is true, is each JVM independent of each other i.e. they aren't aware of each other and they have their own memory space / heap etc. etc. i.e. each JVM lives in its own world not being aware of the other JVMs whatsoever?
Thanks for your help in clarifying these questions.