Anand Surya

Greenhorn
+ Follow
since Apr 24, 2018
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Anand Surya

Joel McNary wrote:. . . Perhaps you are confused by the fact . . . .



Now I understood, I have just iterate the map and I got it. Thanks once again.
3 years ago
Hi Joel thanks for the reply.

As you suggested I have tried with below code


And getting this output

Map : {emp1=Employee [id=1, name=Anand, city=Pune]}
Map : {emp2=Employee [id=2, name=AKS, city=KOP], emp1=Employee [id=1, name=KKC, city=Pune]}

And as you said "Since both references refer to the same object, any change to the object is visible by all the references, so when you print out the map it is printing out the changed value."
Then why it has stored into the same when I have only get the object and setname to "KKC". Sorry but still I am not getting could you please explain more.

Thanks a lot

3 years ago

Tim Holloway wrote:Do I read this correctly?" It looks like you only put one entry into the Map, but pulled and printed it twice.



Hi Tim,

Yes you have read it correctly, when I have tried this I am also bit confused with HashMap working.
I don't know how it has been inserted the value into the hashmap when I have called setName property.

Thanks
3 years ago

Carey Brown wrote:What makes you think these two objects have the same key? Note that 'id' is not the key the way it has been written.



Hi Carey,

Thanks for your reply. I am not sure but as I have putted with String "emp1" as a key in map.put("emp1", emp1);
And after getting the object from the key "emp1" and I have just changed the Name property of object Employee.
I guess it has to replace the existing objects name from "Anand" To "KKC" but seems like it has been added into the map.

And if key is not the same then how it has inserted second value into the map as I have changed the name of existing object of the map.

Thanks a lot, please correct if I am wrong anywhere
3 years ago
Hi Everyone,

I am not understands that how multiple values or objects can associate with one key in HashMap.

I have tried below example,



Output :

Map : {emp1=Employee [id=1, name=Anand, city=Pune]}
Map : {emp1=Employee [id=1, name=KKC, city=Pune]}

Can you please explain me the output and how hascode and equals has worked here, as if I comment the overridden hascode and equals methods still the output is the same so confused in hashcode equals contract.

Thank you in advance.
3 years ago

Tim Holloway wrote:I have a bigger doubt. DON'T WRITE YOUR OWN SECURITY. Unless you are a full-time professionally-trained security professional, it's about 95% certain that someone can crack your security system. And, based on what I've seen over the years, about an 85% chance that non-technical people will be able to bypass security in 15 minutes or less. That includes systems designed by the in-house "genius".

J2EE/JEE defines a standard container-based security subsystem. In nearly 20 years, I've never heard of it being breached. It's pre-written, pre-debugged, tested by security pros, well-documented, and best of all, it blocks most security attacks before they can attack the web application itself. Consider using it.

Spring also provides a finer-grained security system itself, which I believe actually can work in concert with container security.

So there's no excuse for writing your own security management in most cases.



But still I did not understood, how actually one Spring singleton scope(e.g. LoginUser) bean works for multiple users on the same context or container?
6 years ago



Hi Team,



What is the reason that PersonImmutable class is not correct immutable class?
6 years ago
Thanks a lot Stephan.
I have one more doubts like, you said

"That means if you inject a UserLogin for two different user sessions during the same lifetime of the application, both will have the same UserLogin instance injected."


Who creates different sessions and injects the UserLogin is the Spring container creates or else and how?

Thanks once again.
6 years ago
Is it related to Singleton scope is Stateless. If yes then please explain how?
6 years ago
Hi Experts,

I have doubt like,

Suppose I have bean UserLogin with the default scope i.e Singleton(only once instance per container(correct me if my understanding is wrong)).
And I have web application it contains the one container with one context which has my bean(UserLogin bean) with Singleton scope.
Now I have logged in WebApplication with UserBean and suppose there is another user has logged in on the same WebApplication with the same UserLogin bean.

My question is how container manages the above scenario as UserLogin bean has Singleton scope and multiple users can login at a same time with the same bean instance.

Appreciate your help..!

6 years ago