Win a copy of Rust Web Development this week in the Other Languages forum!

sebastian tortschanoff

Ranch Hand
+ Follow
since Mar 19, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by sebastian tortschanoff

Thank you for your explanation. I thin i've got it now
Hi Martin, Prasad,

thanks for helping me. I think i do now understand. It's all about the return statement and it's positioning.
Since we have no exception, we wont have a return. Therefor the compoundstatement will be reachable.
Since we have a return in try block and catch block, the compoundstatement will be unreachable.

Thanks for your trust in me. I will do the exam within 2 1/2 weeks. When i pass the exam, you will definately hear from me :-)

sincerely yours,
Hi Sandra,

watch this:

What are you printing? Not any value within an Array, but object references. With this enhanced for-loop you're getting a Array-Reference from a twodee-Array. And then you print it. Hence you will get some memory address like this: I@446b7920

Consider this:

What are you printing here? Values of type long.

Hello Salooners,

yesterday i came along some issues with unreachable code.
I am training with enthuware.

Here the questions:

What will the following code print, when run?

  • 13432
  • 13423
  • 14324
  • 12434
  • 12342

  • Explanation:
    Try to follow the flow of control :
    1. in method(1) : i is not 2 so, j gets "1" then finally is executed which makes j = "13" and then the last statement (j +=4) is executed which makes j = "134".
    2. in method(2) : i is 2, so it goes in the if block which throws an exception. So none of the statements of try block are executed and control goes to catch which makes j = "1342", then finally makes j = "13423" and the conrol is returned. Note that, the last statement ( j+=4) is not executed as there was an exception thrown in the try block.

    Now the second question:

    Following is a supposedly robust method to parse an input for a float.... (See Exhibit) Which of the following statements about the above method are true??


  • If input: "0.1" then it will return 0.1 and print finally.
  • If input: "0x.1" then it will return Float.Nan and print Invalid Input 0x.1and finally.
  • If input: "1" then it will return 1.0 and print finally.
  • If input: "0x1" then it will return 0.0 and print Invalid Input 0x1 and finally.
  • The code will not compile.

  • Explanation:
    Note that the return statement after finally block is unreachable. Otherwise, if this line were not there, choices 1, 2, 3 are valid.


    Now i am confused. IMHO the first code-snipped should not compile, like the second example. But how can answer 13432 be correct?

    Could anyone explain

    Thanks in advance,

    sincerely yours

    Take a look in the specification about compound operators (section 15.26.2). You will see that it is defined with a implicit cast... hence, it will compile without the need to cast it.


    Oh men - yes you're right. Compoundstatements do a automatic casting. I've forgott about that. So in this case there will a explicit downcast, even if the value might not fit into, is that right?
    Hello SCJP-Masters. One year ago i missed the scjp-certification the second time by only one question.
    So i tired up.
    Now i am ready to make a last stand.

    My question here is maybe very simple, but it confuses me very much.

    I've done some test with enthuware and came along a question where to put operators into the right boxes.
    I've missed the question.

    here some code:

    I do not understand, why this assignment works:
    When the compiler will safe me from doing this: c = i;
    Why he does not prevent me from doing this
    Shouldn't be there a rangeproblem expected, too?

    Thanks in advance.
    The wait() method must be called from synchronized context otherwise a IllegalMonitorStateException might be thrown, when wait() is invoked on an object.

    The code in main() is lega,l since Thread-Class implements Runnable-Interface.

    The only way to acquire the Monitor of an Objext is to synchronize on it. Otherwise an Exception will be thrown, when wait(), notify() or notifyAll() is invoked on an object from non-synchronized context.

    A thread becomes the owner of the object's monitor in one of three ways:

    * By executing a synchronized instance method of that object.
    * By executing the body of a synchronized statement that synchronizes on the object.
    * For objects of type Class, by executing a synchronized static method of that class.

    None of this happens in this example so an exceptions will be thrown.
    Hello Folks,

    yesterday i've taken my second try on performing the SCJP exam. I've Failed. I have answered 46 questions correct. Actually You need 47 correct answers. Yesterday was my worst day - ever since a long time. Actually because i barely would have made it, with one more correct answer.
    The second thing to worry is, that i now will not get the contracted rise in salary.

    When i left the prometric testcenter i stood transfixed, watching at the sheet of paper with my result, and could'nt understand the world. All about one question - WHY??? Why me?
    I'm really disappointed now.

    I don't know when i will make the third an last try to pass the SCJP.

    The first time i just did the questions from the K&B Book. I Failed with 44%.
    The second time i learned with enthuware and could score to 63%.
    I don't know what to do to get the last 2%. I thought, i was ready, but the ExamQuestions are much more strange than anything i've seen since i am prepping the Exam. Bug's are very hard to spot. Additionally you are really nervous while taking the axam. And you have to focus at least 3 hours. There are no drinks (whater) allowed, no food, no sugar (for additionally brainboost).

    I'm really sad now. Very disappointed. But i'll keep on trying.
    12 years ago
    I'm really disapointed by myself. I hoped so bad, that i'll make it through.
    I've trained very hard, but never reached a score over 57% when doing the MasterExams.
    But i hoped to accomplish.

    I wonder how to pass the exam. There is often so much code in the questions, that i cant overlook everything. Some times the questions will punk you.
    After 2 hours i've got lost of my concentration.

    I thought the questions would be much easyer, but they as hard as in the MockExams from K&B. Not that i havent learned anough or understood less. I know, that i do, but i dont know why - while doing the exam - i was really uncertain about some really easy questions.

    Some other questions i could not answer because i did not understand the meaning.

    I've never programmed in Java. I'm really new to that language. I have practice in C# (only one year). I think, i will never make it through the exam. I'm so fearfull by doing the seccond try in two weeks.

    I dont know any further. I've learned since march 2009 and still i have failed with 44%. I know my weaknesses. But the time to spend while leaarning is so intensive.

    Can anyone tell me how to clear the SCJP?
    12 years ago
    The main thread gets a lock on the Job-class.
    Wait means: "Hey Thread! Stay in Pool, while main-Thread executes and finish (and subsequently releases the lock)."

    Then, any other thread, pointed by the Scheduler, will be selected from the pool. In this case, a thread ,using the same Object (in synchronized context -means getting a lock).

    When this thread calls the method thread.getNumber() (yet the same Object and it's state, too), the number printed will be 999999, no matter how long the other thread is waiting.

    Yo've said:

    According to me it should be in waiting pool state till a notify() is not encountered. right ???

    Thats wrong. When one thread gets a lock and is put into wait, it does not release its lock.
    When this thread is dead or notified, the lock is released. Notify can not provide information which waiting thread will be selected next by the scheduler.
    Have you read the K&B Chapter 7? Everything is explainend quite well in there.

    Yust see this as some kind of making type-safe statements.
    You're declaring an enum-generic (mybe for legacy code) with an type parameter E which must extend enum.

    If the type-Parameter will (why ever) be of type String, for example, the compiler will show you an error, cause E must be of an subtype of enum.
    This will only work on compiletime.

    On runtime (as far as i remember) generics are treated as objects of type Object.
    Hello folks,

    i have a question about (K&B) chapter 7 question 16.

    here the code:

    the output:


    Actually, i do not understand the compareTo-method in combination with Arrays.sort().
    How is it possible to reverse the natural order with compareTo by switching the parameters (like in the example above).

    Can anyone explain me step by step how comparTo() in combination with Arrays.sort() is reversing the natural order?

    Ok. That explains why value 3 is printed.

    Thank you very much for your help

    Probably i will post some further questions about chapter 7. Actually i'm doing the questions.

    See You, and thanks alot.
    Yep, thanks Ankit.

    Maybe it's the weather here in Germany...
    Hello folks,

    i have a simple question about (K&B) Chapter 7 Question 3 a bit modified.
    The issue is the answer.

    Here the code:

    the ouput:


    The answer says:

    "...At runtime the TreeSet will try to sort the elements as they are added..."

    What means this? The TreeSet will be ordered and sorted by the way the elements are added?
    Or do it mean: The TreeSet is ordering and sorting the elements every time a new element is added? <-- I think this is true!

    Also i have a question about the output of the code above.

    look here:

    The TreeSet has 6 Elements, ordered and sorted (0,1,2,3,6,9).

    hasNext() returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

    But when the Iterator it has come to the element wich holds the value 9, will hasNext() return true? If not why is element with value 9 printed though? I'm asking, cause element with value 9 has no next element.

    Can anyone answer this, please?

    Sincerely yours

    I think the last element (with value 9) hast no next and therefor th e while-loop breaks.
    But number 9 is already printed, cause element with value 6 has a next element.