Kedar Pethe

Ranch Hand
+ Follow
since Jul 17, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kedar Pethe

gurpeet singh wrote:i think you are confused between widening reference and widening primitive conversions. these are two seperate things. if Dog class subclass Animal and we write Dog d = new Dog(); Animal a = d; here widening reference conversion is happening. when we do long l = 989; here widening primitive conversion is happening. int is promoted to long implicitly. so and int can be promoted to Object in your example. first it is boxed to Integer wrapper which is then assigned to Object reference variable and hence widening reference conversion. Rest is explained by Pritish



Thanks!!
Hi guys!! I gave my SCJP 6 exam today!!
Passed with 85%.. Im on cloud 9...
As mentioned in K&B book "..you won't find a
larger or more willing community than on the JavaRanch.com Big Moose Saloon
certification forums.."

MoOse rOcks!!
K&B book was more than sufficient! I also got some examples from that of K&B book, exactly the same which i had prepared!
Awesome job - Kathy & Bert!!!
9 years ago
I passed today with 85%. Didn't spend a penny on commercial softwares!! :P
1. Score 100% compulsary on javaranch Rules round up game .
2. Preparation- Answer only the review questions at the end of each chapter from khalid mughal scjp 1.6 book. It shows many new tricks, which you might have missed!!
3. Use free ExamLab software by Devaka Coorey. - Give 3 exams
4. Reread the kathy sierra book's 2-minute drills, until you have concepts crystal clear!!
5. Don't waste time giving mock exams, if you make the same mistakes again & again, reread that objective from kathy & sierra, till you can apply those concepts in code.

Understood. Thanks Henry and Dan!!
Given code-


I am unable to understand the output.
How come at second output line after Thread-1 0, control shifts to main?? If join() call is after the for loop,
why is it getting called immediately after Thread-1 0
Shouldn't For loop be completed??
Which is the current thread when we think of invoking join() inside run() method??

James Boswell wrote:

Look at your method signature above and then look at what you are attempting to pass to the go method:



Notice the type for variable l?



Understood.. i should have passed the instance variable of anything that extends A, instead!!

Gaurangkumar Khalasi wrote:Try out with
instead of
And try to figure out your problem!!!



Got it! Thanks gaurang!!
Why doesn't the following code compile?


What is wrong with <T extends A> ??

Anurag Jai wrote:Hi Kedar....

As you know "finally" block is always executed, so when any exception is thrown from catch block......the exception in the finally block would be thrown from the exception instead of any exception occurring inside the catch or try block.


Thanks!

Pritish Chakraborty wrote:Follow the flow control, Kedar!

You throw an exception in the try block, which is silently caught by the catch block.

The catch block then rethrows the exception. Now either it will move up the call stack (out of main()), or it will be caught again.

But in the last fragment of code, a finally block is placed. A finally block runs regardless of whether an exception is thrown. In this case the exception *is* rethrown from catch, and is 'caught' by finally, which forcefully executes. I always considered finally as an offshoot of the catch(...) clause in C++ but let's not go there, finally has some fundamental differences.

Now if we rethrow from finally, the exception is thrown out of main() and is caught by the JVM, which prints the stack trace after halting the program execution.

Now try this - don't throw a new exception from finally. Post the result.



Understood. That cleared my doubt!!
Thanks!
It should be "Hello" instead of "abc", i mistyped!
No in i) one object is created, and ii) two objects are created!
You can refer K&B, Chapter 6: Strings.
About the hashCode, two different strings with the same value are represented by only one "Hello", two "Hello" 's are NOT present in the pool.
s,s1 and s2 will point to the SAME one "Hello" string in the pool.
Got it. Thanks Jeanne & Pritish for the explaination!!
Given-



What happened to the exception thrown from the catch block? Did it get lost?
In i) only one String object is created. This object will be placed in the String constant pool.
In ii) two objects are created. Object one- String constant "Hello" to be placed in the String constant pool, Object two- String object with value "abc"

Do this after the two statements add the statement below and see the output

Reason- All reference variables refer to the same "Hello" string in the String constant pool.
int hashCode() - returns Object ID number(may not be always unique)

Now change the value of s2 to "Hellllo" and the output is-
69609650 69609650 -1824599884



Hope this helps!!