wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Questions that are based on examples given in Java Language Specifications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Questions that are based on examples given in Java Language Specifications" Watch "Questions that are based on examples given in Java Language Specifications" New topic
Author

Questions that are based on examples given in Java Language Specifications

Igal Ore
Greenhorn

Joined: May 10, 2012
Posts: 6
Hello ranchers !!!

i'm still preparing for OCPJP 6.0 exam, that occurs on this Friday, wish me luck on this, and for a moment doing enthuware mock exams, that mostly are excellent questions and well explained answers for them, but observing that some of questions are almost direct copy-paste from JLS, like here :

What will be the output of compiling and running the following program?


class CloneTest
{
public static void main(String[] args)
{
int ia[ ][ ] = { { 1 , 2}, null };
int ja[ ][ ] = (int[ ] [ ])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}

You had to select 1 option:
a) It will not compile because Arrays cannot be cloned like this as clone() is not public.
b) It will not compile because either clone() should be in try-catch block or main should have throws clause.
c) It will print 'false false' when run.
d) It will print 'false true' when run.
e) It will print 'true true' when run.

I will not mentioned here an answer, so any who prepares themselves to exam should try to figure it out ,
But if you would look on Example 10.7-2. Shared Subarrays After A Clone in JLS7, you will find identical code !
This is not first occurence of quite tricky questions, even that this one marked as Easy by enthuware , but i'm not totaly agree with this grade, that are originated by subtle understanding of JLS document.

From people that took already this exam or OCPJP 7.0 part 1 or 2 is it worthy investment of time to read carefully JLS document, which is not smallest in the world, and not easiest reading neither, 3 days before an exam ?

Any insight are welcome ...
Thanks


OCPJP 6.0
Igal Ore
Greenhorn

Joined: May 10, 2012
Posts: 6
One more example:

Which of the following code snippets will compile without any errors?
You had to select 3 options


a)while (false) { x=3; }
b)if (false) { x=3; }
c)do{ x = 3; } while(false);
d)for( int i = 0; i< 0; i++) x = 3;

Again i will not mentioned completely correct answers, where just to point out:
reply b) is correct, as mentioned in list of exceptions on 14.21 Unreachable Statements chapter, in my copy of JLS 7 on page 446, just before Chapter 15 Expressions starts .
Grrrrr......
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

regarding your first question -->
clone perform shallow copy . Please read shallow copy here .
so now you should able to get the concept

and second one --> because java compiler is designed like that :-)

before SCJP(very near), I do suggest you to concentrate mock exams more ... it may be better idea to avoid reading JLS, IMO.



Igal Ore
Greenhorn

Joined: May 10, 2012
Posts: 6
Thanks Seetharaman Venkatasamy, for explanation about questions, or more correct about answers for questions

What i would like to hear from people passed exams, did you really encountered those kind of questions on real exams ?
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Igal Ore wrote:One more example:

Which of the following code snippets will compile without any errors?
You had to select 3 options


a)while (false) { x=3; }
b)if (false) { x=3; }
c)do{ x = 3; } while(false);
d)for( int i = 0; i< 0; i++) x = 3;

Again i will not mentioned completely correct answers, where just to point out:
reply b) is correct, as mentioned in list of exceptions on 14.21 Unreachable Statements chapter, in my copy of JLS 7 on page 446, just before Chapter 15 Expressions starts .
Grrrrr......



I tried to compile and run the above options and found that all can compile and run without any error. Is it right?


Always believe in yourself
Igal Ore
Greenhorn

Joined: May 10, 2012
Posts: 6
Normally a) can not get compiled since there an unreacheable code in while loop

program.java:5: error: unreachable statement
while (false) { x=3; }
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Igal Ore wrote:Normally a) can not get compiled since there an unreachable code in while loop

program.java:5: error: unreachable statement
while (false) { x=3; }

You are right , i tried it again and got the same answer as yours
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3254
    
    2
JLS has tons of example code but we have selected only those that we believe are important for the exam. So for this exam, we do not recommend people to go through the specification except in case of a few sections that are important for the exam.

HTH,
Paul.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
sharma ishu
Ranch Hand

Joined: Sep 10, 2012
Posts: 70
Paul Anilprem wrote:JLS has tons of example code but we have selected only those that we believe are important for the exam. So for this exam, we do not recommend people to go through the specification except in case of a few sections that are important for the exam.

HTH,
Paul.

Could please elaborate, like which topics could seek help from the specification.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions that are based on examples given in Java Language Specifications
 
Similar Threads
JQplus
what is the Output?
problem with clone.......
clone method
clone() with arrays??