• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Questions that are based on examples given in Java Language Specifications

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 coderanch.
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
 
Igal Ore
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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......
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 58
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Igal Ore
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 58
Firefox Browser Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Enthuware Software Support
Posts: 4910
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic