Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!

Avinash Tiwari

Ranch Hand
+ Follow
since Sep 20, 2006
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Avinash Tiwari

Hi All,

We keep on hearing the hashmap stores object(key-value pair) in same bucket for same hashcode.

What exactly is a bucket and internal implementation behind it.

Also how exactly is bucket arranged.Is it some array of bucket(data structure) through which iteration is done.

Also what is the implementation of bucket for storing objects with same hashcode but different and how does get() function retrieves or iterates through them

Also during rehashing how is this principle or bucket concept kept in place.

Please let me know

Thanks
Avinash .
8 years ago
Hi All,
Thanks for the reply.
As for basic principles of marker interface , yes I do understand they are kind of metadata to a class which JVM might be using.
However the question I have is , does implementing this interface provides kind of type checking only or do they serve other purpose too.

Like the implementer of the logic checks the type for object and determines whether it is of marker and then proceeds with respective business logic.
Is this the case which drove their existence.

However being at class level , the property was enforced on whole class and subclasses and to provide the marker capability to specific granular elements or methods , annotations were brought in.

Thanks
Avinash
8 years ago
Hi All
I know this question would have been asked several times.
However asking again wth respect to internal working.

Contract says to have hashcode override with equals. Now questions are :
1. Why need hashing.
2. If not implemented hashing , what is pitfall. What will be size of hashmap.
3. If implemented hashcode and not equals and vice versa.
4. What is underlying implementation storing hashcode and how does it work in retrieving the object
5. How does hashing works best with immutable object
6. What is same type of objects and put. What will be size of map then.
7. What exactly is bucket. We talk of bucket but what is actual implementation of same and how does it handle the same.
8. Any other consideration.
9 Do we provide implementation of bucket or provided by java.

Please let me know or if any detailed article covering same will help.

Thanks
Avinash
8 years ago
Hi All
As we know Serialisable is a marker interface and doesn't have any enforced implementation.
Then how does the whole serialization mechanism work. How does JVM knows internally this.

Is there any inbuilt mechanism underlying this.

Also how is marker interface different in terms of annotations. Are they also same or different.

Thanks in advance
Avinash
8 years ago
Thanks you all for your replies.

On similar lines , we say Singleton is one per JVM. So in distributed environment , let's say we have 2-3 JVMs. That means we will have 2-3 Singleton instances.

The question is how do we maintain the state of singleton or determine we have one with all same states.

Please let me know.

Thanks
Avinash
Thanks for the kind reply.

Please help to provide further answers. Apart from singleton usage , where else we can utilize the double check locking or has a chance of being used and the alternatives that might be available.

Thanks
Avinash
Hi
Thanks for the reply.
I am talking in terms of singleton usage.
Can you please let me know better options.
Thanks
Avinash
Hi All,
Generally we see Double check locking in code across many places. I have read many articles and need respected people opinion.

Is there any alternative to double check locking.

Or using volatile and another instance reference in the method we can solve it.

Please let me know.

Thanks
Avinash
What is a service provider interface in actual. Does it applies when you want to create a vendor product and expose the service or it can be utilized in the application developer way too.

What condition precedes usage of this.

Does it have any resemblance with Fa├žade pattern?

Please advice.

Thanks,
Avinash
Yes , its a running code. And as they say any tinkering with running code can be problematic. So far it doesn't seem to be invoking equals or being used. However can't be sure of the background on this usage of equals.
So as a safety net and precaution , overriding hashcode seems to be a safe bet and will not affect the current running anyway.

Thanks everyone for the helpful insights.

Regards,
Avinash
9 years ago
Thanks for the reply.

Please help out with Singleton on non EJB perspective. That would be helpful.

Thanks
Avinash
Agreed. Ideally four comparators are independent in their functioning and perform their respective tasks to complete a collective task.

However this happens to be a legacy code with their equals method overridden. With no history or background of this implementation , it is difficult to fathom the reason for this behavior.

All respective people opinions ( who have helped in this thread) are highly regarded and there are same questions unanswered but touching or removing this equals implementation can have its own risk.

So from code review tool perspective , it seems the possible way is to override the hashcode method with a constant value .

Thanks
Avinash
9 years ago
Hi
With plenty of materials around singleton and I guess being the most widely used pattern across all j2ee applications. How do we truly make a class Singleton in distributed architecture.

We have many constraints like cloning , reflection , class loaders , multi threading , double checked locking etc.

Please help out the near to exact way we can have singleton in place.

Thanks,
Avinash
Hi
My apologies. Maybe I didn't phrase the points correctly.
Consider a case where we have 4 comparators : A , B, C and D

What I meant is if a specific Comparator A compare method uses internally compare methods of B , C and D in its compare method.

Then overriding equals method of A and all internal comparators B , C and D is done.

In this case , overriding hashcode also needs to be done. Because if you use any code review tool like FindBugs etc it points at this and says to implement hashcode too.

Thanks,
Avinash
9 years ago
Thanks all for such prompt and helpful responses.

In the mentioned case , what is happening is :

There is a bigger comparator ( in terms of holding data) lets say HouseComparator (comparing House object) . There is a RoomComparator (comparing room object). Now HouseComparator inturn uses RoomComparator and other sub comparators for arriving at equality of House object.

So equals method of RoomComparator gets defined. Considering this scenario , is it appropriate to define hashcode method. Or we define hashcode with a constant value across all comparators.

This seems like a nested Comparator usage and not sure in such case overriding hashcode method will achieve any purpose or not overriding will do something.

Please let know.

Thanks
Avinash
9 years ago