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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
thchuong
Posts: 8
Joined: Wed Sep 10, 2014 2:42 am
Contact:

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

Post 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.

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

jmrego
Posts: 8
Joined: Wed Dec 10, 2014 6:05 am
Contact:

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

Post 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? ;)

broono
Posts: 1
Joined: Thu Jul 02, 2015 6:55 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Roibeard
Posts: 19
Joined: Sun Jul 12, 2015 6:40 am
Contact:

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

Post 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?

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

Roibeard
Posts: 19
Joined: Sun Jul 12, 2015 6:40 am
Contact:

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

Post by Roibeard »

Ok, thank you.

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

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

Post by AndaRO »

Where is written that args is not null?

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

dxie1154
Posts: 9
Joined: Sat Jan 14, 2017 5:01 pm
Contact:

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

Post 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?

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, that is correct.
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 »

why is there no mention that this is "Instance Initializer Block". Is it not that?

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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
If you like our products and services, please help us by posting your review here.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 »

how is this called?

admin
Site Admin
Posts: 10054
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

It is invoked when the method is executed. It is like any other code in that method.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests