Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Ben Pheonix

Ranch Hand
+ Follow
since Dec 11, 2012
Ben likes ...
Tomcat Server Java
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
6
Received in last 30 days
0
Total given
5
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ben Pheonix

Hi everyone.

I am reading AngelikaLanagerDecodingEnum.
I am completely lost in the syntax. Can someone explain me the concept in a more simpler way. By declaring it in such a way, what it the use how its helpful or how we can dissect
the whole syntax,

Thanks.
Dear Chan,

Thanks a ton for clarifying my doubt.

Thanks,
Ben
Dear Batra,

Welcome to Javaranch.

You are synchronizing on instance of thread. If we check the JoinMethodDocumentation, you will see that Thread instance
gets notified when run() method completes. Check the documentation of the join() method.So basically, you execute one explicit notify call
(the one we see in the code), and another implicit notifyAll when the thread is done. We shouldn't synchronize on the Thread object.
Thread toString() methods returns names of all threads in the ThreadGroup, not only name of current Thread. You could even remove your explicit notify
and the behavior wouldn't change due to the implicit notifyAll at the end. Check the modified code below.



HTH,
Ben
Dear Stuart,

Thanks for responding timely but searching on this snippet didn't generate the desired search results. Do you have the link which might
answer my confusion?

BR,
Ben
Dear Stuart,


To me, correct option can be B,D. Then why C,D are correct. Can someone explain this?



This is my question.

BR,
Ben
Hi Everyone,

This is code snippet from Kathy and Bert book chapter-9.



Given fragments are



When the give fragments are inserted, one at a time at line-9 which are true?

The correct options given are :- C,D




To me, correct option can be B,D. Then why C,D are correct. Can someone explain this?

Thanks.
Ben
Hi,
Please Usecodetags while posting a query.
Where are you confused in this? Outside a package a protected member can only be accessed through inheritance. You
Cannot use the parent class reference to access the protected member outside package.

Hth,
Ben
Hi joe!
Thanks for letting me know. Congratulations for passing the exam with flying colors.
BR,
Ben
Hi,

Assertions are in theory for testing code invariants, assumptions that must be true in order for the code to complete properly.
The example shown is testing for valid input, which isn't a typical usage for an assertion because it is, generally, user supplied.
Assertions aren't generally used in production code because there is an overhead and it is assumed that situations where the invariants fail
have been caught as coding errors during development and testing. LINE-5 and LINE-13 are trying to validate the input, that's why they are
in-appropriate usage ofassertion. Additionally, your assumption is correct that test2 can be used for some other way also, but currently the
author is talking about context of the example so in this example, the way assertion has been used is in-appropriate.

Correct syntax of assertion is

assert <boolean expression>;



Program is using it in a wrong way.



means: a MUST have a lenght equals 2 else is an error. Please check OracleDocumentation

HTH,
Ben
Hi Tim,

Thanks a ton. I understood the concepts and it makes more sense now. Thanks a ton.

BR,
Ben
Hi Tim,

Thanks for reverting back quickly. So it means that instance of java.lang.Class is shared among all instances of the class and java.lang.Class is
kind of a property shared between all instances of the class.

BR,
Ben
Hi Everyone,

I am reading static method synchronization in java. Where i read static methods get a lock on object of java.lang.class. I was trying to understand the concept of java.lang.class and its role in static method synchronization and i have these questions.

1. I was reading the blog where it says every class in Java has an instance of java.lang.Class and all instances of a class share this object. Instance of java.lang.Class describes type of object? What is the role of java.lang.Class here? How does it describes type of object?

2. Secondly for static method synchronization, we need to get the monitor of java.lang.Class. Why is that? Why do we need its instances lock not our class lock?

Can someone elaborate on it. I am really sorry because it sounds a pretty basic question but i am pretty new to this concept.

Thanks,
Ben
Dear Greg,

Thank you very much. The answer was much clearer by your explanation. Thanks a ton.

Thanks,
Ben