Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Ankit Gareta

Ranch Hand
+ Follow
since Mar 28, 2011
Ankit likes ...
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 Ankit Gareta

Hi All,

please look at this link, mouse over effect .

I want exactly this type of effect while rolling the mouse over the image, that portion of the image will show in enlarge mode.

How can i do that ?

Thanks in advance.

Vicky Wang wrote: then I would assume the following code should be able to find Dog:

but the output is null.

Why is that?

Hi Vicky, that should not be null if you correctly override equals and hashCode method..
Hi Frits,

Frits Walraven wrote:Hi Ankit,

The Session object lives on the Server, the reference to a Session object lives in the browser (in a Cookie). If you kill the browser, the reference is lost, but the Session object is still on the server.

If you restart the server, the Session object will be destroyed. The Servlet-container builders, however, can provide a service that will recreate the Session object after a shutdown/restart of the server (e.g. by serializing and de-serializing the Session objects). As the specifications don't require that a Session object should be recreated after a shutdown/restart of the server you can conclude that B is correct


Thanks for you reply, So session object lives on server, so there is two reference of the session, one is in server and another is in browser's cookies.
so if i cleared all the cookies of the browser, that will not affect on session object that are stored in server, right ? session stored in server can be deleted only by invalidate method of HTTPSession while server is running.

Hi All,

Sessions are stored depends on web-browsers(means stored in cookies depends on web-browser),
So i think when the servlet container restarts doesn't make a signal to invalidate session value that stored , so i think the answer B is wrong.
But i don't read the spec till.

wrong me if i wrong.

sharma ishu wrote:
How much can a person score in the real exam if he scores 70% in these exams.

around 90%..
Hi ishu ,

You must be implement Runnable in this case,
Try "Thread.sleep(5000)", because the method sleep is defined in Thread class. OR use static import .

If you extends Thread then it should not be compiler error

Hi David,

Thread's sleep method is static,so t1.sleep() means only the current thread that's executing will go to sleep..

In this example, all 3 thread will execute and all 3 will go to sleep at their i's value reach to 250 once, and sleep to 600 milliseconds after 600 milliseconds they will executing remaining for loop.
Now it can be possible that they all can execute within 1 sec or little more..(can't say exactly).
but as options said it's possible to finish within that time, but not as 10 minutes (Its too long time to finish).

hope that will help,

Hi soujanya,

You will not get any topic mainly regarding Swing (as you told borderline topics).

kathy sieera's mock exams are tuff. That can't be tell how much is enough. but if you will get 70% on that mock exams , you have a good chance to reach at least 90% in real exam.

Hi Sudhanshu,

Yup, You are right, the behavior is like that.

Sudhanshu Mishra wrote:
... at compile time the refernce's type is checked but is it not true that at runtime ...

No. At runtime also the method invoked based on the Reference Type. So, the reference type has a method then it invoked otherwise error.
If you are not clear in this, then i afraid , you are not getting method overriding correct also.

So make clear that, object is whatever type, the method invoked only of reference-type, if method override take place then it will call the method of object type(subclass).

Hope that will help.

Hi sudhanshu,

Sudhanshu Mishra wrote:
........ how come a method got invoked just based on reference, while the actual object is something else.
The method invoked was of superclass, while we have object of subclass only.

You know that in JAVA every method invoked based on that reference type.
your question is why based on reference type not in actual type ? That's the way JAVA is working.

maybe that will help you :

...... all the Java primitive types have well-defined standard sizes, so all primitive values can be stored in a fixed amount of memory (between one and eight bytes, depending on the type). But classes and array types are composite types; objects and arrays contain other values, so they do not have a standard size, and they often require quite a bit more memory than eight bytes. For this reason, Java does not manipulate objects and arrays directly. Instead, it manipulates references to objects and arrays. Because Java handles objects and arrays by reference, classes and array types are known as reference types. In contrast, Java handles values of the primitive types directly, or by value.

Hi David,

Both the examples are correct.

In first example,
Animal b = new Horse();
Here, reference is type Animal and object is type Horse.
Overriding is the Runtime-polymorphism. so overriding take place only runtime not compile time, and method call of object b depends on reference type.
here method calls the Animal's method compile time and at runtime due to the object is type Horse , so the method override take place and runs the Horse's object...

but in your second example,
Animal h = new Horse()
h.buck() gives compile time error , because Animal doesn't have a buck() method.

Hope that will help.
Thanks Seetharaman, I forgot that...

sharma ishu wrote:
This code allows you to use instances of Stuff as keys in Maps or not? And why?

Why it will not allowed to use instance of Stuff as key ?
In any map you can use Stuff as a key, no compilation error.

But in TreeMap , you can't use Stuff object as a key, because in TreeMap the key should be implement comparable interface not comparator, so in TreeMap it gives run-time error...

sharma ishu wrote:
.... problem is from "Practice Exam by Kethy and Bert" 2011. Page 204-Ques.22.

The question you spotted is about sorting, so NameCompare comparator sort the collection in descending order as "return; ".

Hope that will help you.

Hi Yin, As you first read the exception chapter , at that time you will understand that things....

Yin Stadfield wrote:Atleast expound on number (5). It may declare runtime exceptions on any interface method implementation regardless of the interface declaration. (5)

That's says : You can declare any runtime exception , regardless you don't declare in your interface method.