Page 1 of 1

About Question enthuware.ocajp.i.v7.2.882 :

Posted: Fri Sep 19, 2014 4:44 am
by thchuong
I hate those kind of questions because they means nothing in term of checking your knowledge, just to trick people. During the exhausting 120min I can't pay my attention to every trivial single aspect like missing ")" or ";" or "else" and with stupid code formats like
if () {
//bla bla....
}{
//bla bla....
}

If the purpose is to trick people why not just make things simple and write the whole code in one single line to even trick people more??!

And, finally, the font for code in your viewer is very small and hard to see.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Fri Sep 19, 2014 10:24 am
by admin
Hello,
Missing else is a scenario that is tested on the exam.

Regarding small font: Size of the font is system dependent. You can increase the font how much ever you need by running the viewer with command line argument as explained here: http://enthuware.com/index.php/advanced ... -font-size

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Sun Dec 14, 2014 6:54 pm
by jmrego
Yes, I completly agree with thchuong. Imagine what could happen in a drivers license exam? :D And if the args array is never null why the expression args == null is allowed by the compiler? Language design? ;)

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Thu Jul 02, 2015 6:57 pm
by broono
So,
if(hasParams){
System.out.println("has params");
}{
System.out.println("no params");
}

This is not an initialization block because it's inside a method?
If that was at members level, it would be an initialization block, therefore being run only when an instance of the class is created, correct?

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Thu Jul 02, 2015 7:39 pm
by admin
broono wrote:So,
if(hasParams){
System.out.println("has params");
}{
System.out.println("no params");
}

This is not an initialization block because it's inside a method?
Yes.
If that was at members level, it would be an initialization block, therefore being run only when an instance of the class is created, correct?
Correct.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Mon Sep 28, 2015 12:12 pm
by Roibeard
Is this...
is it that:

in a ternary operator:

if the code before ? resolves as "true":

The value before : is selected.


And if the code before ? resolves as "false"
the value after : is selected.

So that in this case: the value resolves as false (because main's args[] can't be null) so the value after : is selected - which happens to be the value 'true'.

Is that what happened here?

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Mon Sep 28, 2015 7:13 pm
by admin
Roibeard wrote: if the code before ? resolves as "true":

The value before : is selected.


And if the code before ? resolves as "false"
the value after : is selected.
Yes. Here is a good article explaining this operator: http://alvinalexander.com/java/edu/pj/pj010018
So that in this case: the value resolves as false (because main's args[] can't be null) so the value after : is selected - which happens to be the value 'true'.

Is that what happened here?
Yes.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Tue Sep 29, 2015 2:08 pm
by Roibeard
Ok, thank you.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Sat Feb 25, 2017 3:31 pm
by AndaRO
Where is written that args is not null?

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Sun Feb 26, 2017 12:13 am
by admin
AndaRO wrote:Where is written that args is not null?
Did you read the explanation provided with the question? That is what the question is testing you on. You need to know the fact that args is never null even if no arguments were passed on the command line.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Tue Apr 11, 2017 11:28 am
by dxie1154
I just ran some code that involved a code block in the main method.
The code block executed, so code blocks in methods execute whenever the method is run?

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Tue Apr 11, 2017 12:26 pm
by admin
Yes, that is correct.

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Fri Jun 22, 2018 12:33 pm
by flex567
why is there no mention that this is "Instance Initializer Block". Is it not that?

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Fri Jun 22, 2018 10:01 pm
by admin
No, it is not an instance initializer block because the given block is inside a method.
https://stackoverflow.com/questions/398 ... tion-block

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Sat Jun 23, 2018 11:21 am
by flex567
how is this called?

Re: About Question enthuware.ocajp.i.v7.2.882 :

Posted: Sat Jun 23, 2018 9:19 pm
by admin
It is invoked when the method is executed. It is like any other code in that method.