Astha Sharma

Ranch Hand
+ Follow
since Oct 15, 2011
Astha likes ...
Android Eclipse IDE Java
Merit badge: grant badges
For More
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 Astha Sharma

hi all

I am going to attend interview with 3 years of experience in Java in a big service based MNC.

Please give me tips and advice for success in interview.

What topics generally they stress in interview ?

how much can I demand? Now I am getting 3.38 lacs per annum.
8 years ago

Ulf Dittmer wrote:You can't, but he can - talk to him to find a mutually agreeable solution.

I talked but he refused to change it. I have just one option to use this xml only.
Thanks for your reply Ulf Dittmer. The xml is designed by another programmer so I can not change it. I did search about SAX parser but not getting any good example for parsing xml with DYNAMICALLY generated tags. Can you please give me some example how to parse xml using SAX parser when I don't know the tag names.
I am trying to parse the following XML. In this XML tags are coming dynamically. Tag names are not confirm. Value of the tag named "strCount" gives total number of tags (str0 to str10). Also the encounter tag can appear multiple times.

I am using simple-xml for parsing. Following is the pojo I created for this, which doesn't work -

Please tell me how can I create pojo for parsing this type of xml.
How can I make the POJO to parse following XML :

I tried creating two Objects is class list1 - tempName as String and encounter as List but it is not working.
I am making a JSP with a counter using query string, so that on clicking button next, the counter increases and on clicking button previous, the counter decreases. This is my JSP page-

The counter value shown is 0 every time on whatever button I click. Even the counter parameter doesn't get added in the URL.
Please check the code and tell me what I am doing wrong?
9 years ago
Great score Sidharth. Congrats
10 years ago
Today I passed OCPJP with 90%.
I am not much satisfied with the score as I was hoping for around 95% but still feeling happy that I am an Oracle Certified Java Programmer now
I studied using K&B scjp 6. I think it is the best book for preparation of this exam. Thanks to Kathy and Bert for such nice study material. I practiced Examlab and Enthuware mock tests and written a lot of codes in notepad ;). My average scores on Examlab and Enthuware were 61% and 79.6% respectively. All these study materials were very helpful for the exam. Many questions I came across on the exam were similar as the questions in these mock tests.
10 years ago
Now I got it. Thanks for the explanation Sresh

Sidharth Khattri wrote:

This can be because of the margin of error in float and double values, which does not return the exact value.
Since float and int is of 32 bits, for the second case, all the bits are used for the maximum value of int, hence for
float f=i;
float doesn't have to - add any precision bit values/or deal with the precision error. So, the down casted value in j will be same as the value in i, hence j==i is true.

While in the first case, since all the 32 bits are not utilized for the value in int i, conversion to float(also 32bit), i.e float f=i, will add some precision bits/or deal with the precision error, when value of "i" will be stored in f. So during down casting the casted value will not be same as the value in "i".

Though I'm not sure, this appears to be the correct reason. Waiting for more responses.

If this is the reason, using double in the second code should print "true false", since double has 64 bits.

But this code prints


While assigning i to f, some information will be lost as value of type float are not precise to nine significant digits.

If above statement is correct, line2 printing false is fine. But why does line1 prints true?
And why does the below code prints true even when Integer.MAX_VALUE>123456789?

Thanks for such nice explanation Andrea

Sidharth Khattri wrote:

Andrea Binello wrote:

Astha Sharma wrote:Why does the code below generates StackOverflowError?

This is a bit tricky. When you do a get on a hash-table based map, the map must first calculate the hashCode of the key. In the above code, the key is the HashMap m2. The hashCode of HashMap (see source code of AbstractMap) is the sum of hash codes from all Entries. The Entry calculates its hashCode using hashCode of key and value. But one key is the map m2 (put just before) .... and so calculates the hashCode of m2 using all entries .... and this goes theoretically to the infinite ..... causing somewhere a StackOverflowError.

But there's nothing in m2, why would it infinitely calculate the hashcode for m2?

For calculating hashcode of HashMap m2, it is needed to retrive hashcodes of all entries of HashMap m2. m2 is itself an entry inside m2. Thus process of retrieving hashcode for m2 will go on recursively.
Why does the code below generates StackOverflowError?

Question from enthuware mock test-

Correct statement-
"Both the objects will be stored in the HashMap however retrieving them using the Info objects as keys will not be possible."


In this particular case, since the keys (i.e. the two Info objects) are unequal as per their equals() method and even though their hashcode are same, the HashMap will work properly for them. Both the objects will be stored and retrieved. However, the retrieval will fail only for Info objects that break the rule of equals() and hashCode() are put in the map.

Here I don't understand the line written in bold. What does it mean? It would be great if anyone can give some example of Info objects breaking rule of equals() and hashCode().