Imad Aydarooos

Ranch Hand
+ Follow
since Nov 02, 2010
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
10
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Imad Aydarooos

dear Hrishikesh, check the following topic in the JLS

14.7 Labeled Statements

Regards
Yesterday, I gave Exam Lab "the impressive work by Devaka Cooray " final exam my first try. After 3 hours of trying to figure out the correct answers, I scored only 44%. I get depressed, frustrated, tired and down, because today is my scheduled OCPJP exam.
While I’m going to the PROMETRIC center I tried to convince myself that it doesn’t matter if would fail, because I can try another time , but thinking of the investment I did on studding java(I read it alone, but I have to fly to another country to take the exam) and also thinking about what I could say to my wife about the money I lose for travelling and staying away and after that coming home with empty hand.
Anyway with all this ideas in my head, sadness in my heart I enter the Exam center and……………
I passed…………….. What a joy
I got 76% and here is my list of thank you
Bert Bates and Kathy Sierra Book, its amazingly great and in the spot
All pretenders, sheriffs and, Java Ranch cowboys who are running after the cow objects and who are setting in the bar to get drunk with the API’es.
Guy’s you really ROCK
I know, I know this certificates doesn’t mean I’m now the JAVA GURU, but at least it proves that I can start to learn Java
What else “VIVA JAVA RANCH”
11 years ago
Dear KK Krish, because this forum is specialized to SCJP, no one can help you here ..beter to check the belw link in other Java Ranch forum
JDBC Forum
and welcome to Java Ranch
I agree with you Ankit, this is mentioned in Set Interface API

A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by its name, this interface models the mathematical set abstraction.


But I think this is due to the lazyness of the documenting people in Sun or "I don't know whom", because its apperantly the above quote is copied litteraly from the API of the Set Interface before the NavigableSet

regards
[EDIT]ed for spelling mistakes, sorry[EDIT]
Thanks to all of you thanks Hrishikesh , but I find all the answers here
JLS Classes 8.4.3.1 abstract Methods

and a quote "An instance method that is not abstract can be overridden by an abstract method. " go to the above URL for more reading

Regards
dear Hrishikesh Yeshwant Alshi , thanks for your reply, but this is not the cause of my confusion, please look at the code I posted and answer the following questions:
1- is go() in A is an implementation for abstract go() in B? " I guess the answer is no, but I need an explanation".
2- is go() in B is an overriding of go() in A ? " is it legal to inhert an implemented method and then abstract it, because I think this is what happened [explanation backed with quotes please] !!"
3- if the above is not true, why the (class Abstract) didn't inhert go() method from A?

Regards
Those guys from ExamLab make you scratch your head and spend all the night with rolling eyes and boiling head
I loved them , look at the code below " the idea is from ExamLab edited by me"

I know its ok for class A to be abstract without a single abstract method, but what is the concpet behind the other ideas?? thank you for elaborating on this.
[EDIT] ed many times for seek of clearness and spelling mistakes[EDIT]
the same book page 563

Optionally, you can
construct a TreeSet with a constructor that lets you give the collection your own
rules for what the order should be (rather than relying on the ordering defined by
the elements' class) by using a Comparable or Comparator. As of Java 6, TreeSet
implements NavigableSet.



Actually the natural order is determind by the programer who implemented the compareTo() method from the Comparable interface into the elements.
but if you wish a different ordering you can only use: Compartor as the TreeSet constructors shows TreeSet API:"This also applied to the Map Interface"

TreeSet()
Constructs a new, empty tree set, sorted according to the natural ordering of its elements.
TreeSet(Collection<? extends E> c)
Constructs a new tree set containing the elements in the specified collection, sorted according to the natural ordering of its elements.
TreeSet(Comparator<? super E> comparator)
Constructs a new, empty tree set, sorted according to the specified comparator.
TreeSet(SortedSet<E> s)
Constructs a new tree set containing the same elements and using the same ordering as the specified sorted set.

Kathy and Bert SCJP BooK page 562

Set Interface
A Set cares about uniqueness—it doesn't allow duplicates. Your good friend the
equals() method determines whether two objects are identical (in which case only
one can be in the set). The three Set implementations are described in the following
sections.



My diffrent reading for the above:
for uniqueness HashSet and LinkedHashSet use the equals() method, but TreeSet uses the object compareTo() method inhertied from the Comparable interface to determine uniqueness, even if the object does not has an equals() or hashCode() methods. " This also applied to the Map Interface"
Mabroook (Congratulatin in Arabic) hope you be always in success in your future
11 years ago

Abimaran Kugathasan wrote:Why don't you check with the API


Dear Abirman, I already checked the StringBuilder API before I wrote what I wrote and below is from the append method in the API check what in Bold:

public StringBuilder append(String str)Appends the specified string to this character sequence.
The characters of the String argument are appended, in order, increasing the length of this sequence by the length of the argument. If str is null, then the four characters "null" are appended.

Let n be the length of this character sequence just prior to execution of the append method. Then the character at index k in the new character sequence is equal to the character at index k in the old character sequence, if k is less than n; otherwise, it is equal to the character at index k-n in the argument str.


Parameters:
str - a string.
Returns:
a reference to this object.
--------------------------------------------------------------------------------

Kathy Sierra and Bert Bates Book "Sun Certified Programmer for java 6 Study Guide" in Chapter 6: Strings, I/O, Formatting, and Parsing, in page 440 while they are tackling StringBuilder methods. below is a quote from the book:

public StringBuilder delete(int start, int end) This method returns a
StringBuilder object and updates the value of the StringBuilder object that invoked
the method call.


The above phrase is applied almost to all the StringBuffer and StringBuilder.
I think the correct phrase must be:
"this method returns a refrence to the StringBuilder object that invoke the method and updates the value of the StringBuilder object as well"
Regards

Yaron Landesman wrote:Hi,

This behaviour of instance variables is like of static variables. It looks as if there are two s Strings here, one for B and one for C, and the s of C is not the s inherited from B. But if Java uses late binding and the actual object instance is a C, how it gets the s of the B? I guess the answer requires some knowledge of JVM internals .

Thanks.


as you know, for method overriding there are two methods one in the super and one in the sub with the same signature,so, actually there is first a cmpile time binding which bind the super type refrence to the method. At run time when the JVM checks the object it will finds out that its actually a sub object, but since the method signatures are the same the JVM is cabable of invoking the method on the sub object.
for the instance variable its a littile bit different. The first step will be done as usual: there is super refrence and the instance variable will binded to the super type refrence,but in this case at runtime what you will choose:
1- there is no Polymorphism ( means if there is two instance variable with the same name the runtime obect will see only the instance variables declaread in the class/interface of the refrence variable).
2- because of the above the binding will happen only at compile time with regard to the type of the refrence either its super type or sub type. and according to this either the super instance variable or the sub instance variable will show up.
3- if instead of accessing the instance variable like this(b.s), you used an instance method to print its value, then the story is different and the printed value will depend on the type of the object at run time: please try this code commented and un commented

Imad Aydarooos wrote:Dear Maren Fisher , it works like this:
1- if you assign a String literal to a String variable the JVM will check the String Pool for a similar String object, if it finds one it will be assigned to your variable, else the String object will be created using your String literal and will be added to the String Pool.
e.g: String s = "if not in the pool, create one. If in the pool assign to s";

2- When using the new keyword you are forcing the JVM to create your String object in the heap, anyway the JVM will chick the String Pool after creating your String object in the heap: if there is a similar String object nothing will happen, else the new created String object will be added to the String Pool.
Regards


Sorry Maren Fisher and other readers, I'm wrong in statment 2, and if you used the new keyword nothing will be added to the String Pool, objects will be created in the heap.
please read this :
Strings, Literally