Francisco J. Bermejo

Greenhorn
+ Follow
since Mar 02, 2011
Francisco J. likes ...
Eclipse IDE Java Ubuntu
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Francisco J. Bermejo

Hello everyone!! I passed OCPJP 6 last Monday!! I'm very happy and proud of my score, 96%. I found the exam pretty easy compared to the K&B's OCP Practice Exams or Ethuware's.

For those interested in knowing, these were my steps to get certificated:
  • I read two times K&B's SCJP book. This an excellent book, and a must-have for anyone willing to pass this exam.
  • I expanded my knowledge on difficult topics by reading some chapters of M&R's Programmer's Guide to Java SCJP Certification. I found this book quite boring compared to K&B's though.
  • I bought OCP Java 6 Practice Exams by K&B. Excellent tests, helps toughen you up! Great work again, Kathy and Bert.
  • I purchased a copy of Enthuware mock exams, and did all the 13 exams (my average score was 83%). Like OCP Java 6 Practice Exams book, these tests are really tough! This helped me to put into practice what I learned. I recommend Enthuware to anyone, they have a great costumer support, always willing to solve any doubt on their tests. My only complain is the fact that some questions were mainly focused on operator precedence (which is no longer an exam topic). By the way, I'm planning to continue using this software to keep me in shape for job interviews .


  • Finally, I would like to thank everybody in this amazing forum. I'm very grateful to you, because you solved every doubt I posed!
    12 years ago

    Andreas Svenkson wrote:

    EDIT: Then again, I find it odd that there would be a question on something that isn't guaranteed bevhaviour in the first place... Francisco, could you post the entire question please?

    // Andreas



    Hi Andreas, this is the original question (v6.2.401):

    The following code snippet will print 'true'.


    And the options are:
    - True (marked as correct)
    - False

    Paul Clapham wrote:Let's suppose, just as a hypothesis, that when you compare an int to a float, the int is first converted to a float. Wouldn't that make your posted code behave exactly as it does behave?


    That seems to be a nice answer to why this prints true:


    But this still puzzles me...:
    Hello everybody! As I have a doubt on type conversion, I'd like to know your opinion.
    According to JLS 3rd edition:

    Conversion of an int or a long value to float, or of a long value to double, may result in loss of precision-that is, the result may lose some of the least significant bits of the value. In this case, the resulting floating-point value will be a correctly rounded version of the integer value, using IEEE 754 round-to-nearest mode (ยง4.2.4).


    JLS

    But then why this prints true??

    If we try to convert the maximum integer value to a float, shouldn't the resulting float value be rounded as result of the loss of precision? Then why we get true when comparing those values?
    FYI this comes from a Enthuware question. Thanks in advance!

    Stephan van Hulst wrote:The object referenced by c2 is still reachable (through c2).


    Oops, you are completely right!! Thanks very much Stephan
    Hi again! Bert and others confirmed that 5 objects are eligible for GC, but I'm very confused now. This is because after reading Roel's answer I thought that:

    Francisco J. Bermejo wrote:Until now I simply assumed (wrongly) that in this kind of questions the garbage collector did not run until the asked line is reached.


    And by chance I found this question from the K&B Study Guide that (apparently) confirmed my new thoughts. It's question 1 from the 3rd Chapter:

    This question asks us hoy many objects are eligible for GC when // do Stuff is reached. According to the book the correct answer is C. (2 objects), because:

    "Only one CardBoard object (c1) is eligible, but it has an associated Short wrapper object that is also eligible."



    If there are 5 objects eligible in my previous question, why aren't 4 objects eligible in this (c1, c2 and their respective Short objects)?

    Roel De Nijs wrote:
    It's true that a total of 5 objects are created, but when reaching line 5 just 4 will be eligible for garbage collection (because 1 of the created objects became already eligible on another time, so this object could already be garbage collected when reaching line 5).



    I understand what you mean. Until now I simply assumed (wrongly) that in this kind of questions the garbage collector did not run until the asked line is reached. Thank you very much for your time Roel!

    Stephan van Hulst wrote:I think it should be theoretically possible for id == 0 to hold true twice, because id = 1 - id is not an atomic operation, and id is also not volatile. I guess in theory P Q P Q should be a possible outcome. Let's see if someone else can comment on this.


    Yes I think you're right too!

    Mark Spritzler wrote:As someone who wrote questions for the 5.0 exam. Yes, the Thread questions are just like this one. And you really have to be picky and make sure you check everything that could possibly happen. Or you could do what I did and just guess on those darn Thread questions. ;)


    Thanks for the tip Mark!

    micha koern wrote:Oh Right!
    Try this:


    The output is false, so there is really a new Object- i agree 5 Objects are eligible.



    Anybody else?
    By the way, I'd like to know the authors' opinion to know if in the real exam I should be so picky . Bert?

    Hareendra Reddy wrote:Hello all,

    so id would be id == 1 again (remember almost nothing in Java threads is guaranteed, and so is the order of execution of threads). Therefore both threads would execute the method pick() .


    Your reasoning is right but when the value of id is 1 then the else block is executed printing "RSRS".I feel that P Q P Q is not possible because id can't be made to zero for both the threads.


    Hi Hareendra, you're right, I was wrong about pick() being executed two times. It is release() which could be (in theory) executed twice. I cannot update my first post any longer. But as I said just above in my previous response, what it is wrong is the reasoning shown in the book about why answer D is incorrect.

    Dennis Deems wrote:I have run this code several times. I never got RSRS, but a few times I did get RSPQ, and once RPQS. I do not think P Q P Q or RSRS are possible.


    Yes, I'm quite sure that the situation that I mentioned is nearly impossible to occur in today's computers, but the fact is that in theory it could be... So the correct answer to why D. is wrong should be because id variable NEVER equals 0 in both threads, and therefore you'll never get printed PQPQ as result of invoking pick() twice.
    But I insist, the book says that answer D is wrong because:

    The line id = 1 - id; swaps of id between 0 and 1. There is no chance for the same method to be executed twice.

    That explanation is simply wrong according to my reasoning.

    micha koern wrote:

    There is no chance for the same method to be executed twice


    This refers to the synchronized methods that are not responsible for your problem.


    Mmmm, I don't think so, I believe the authors symply mean that no method will be executed twice. It has anything to do with the fact that they are synchronized (on different locks by the way).