Esther Kak

Ranch Hand
+ Follow
since Oct 11, 2006
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 Esther Kak

Hi all,
I am having a problem attempting questions on garbage collection. I think the way I approach to attempt the question is I am trying to draw some diagrams like...whenever I see an new reference variable, I am pointing to the object that it should be linked to. After that when the variable is reassigned to something else, thats where I fail to redraw. I know that I have to remove the arrow pointing to previous reference and now point to the newly assigned one.
Can somebody please help me understand how I should attempt GC questions...I am getting most of the questions wrong because of my approach. May be I still did not get the concept right.
Here is a simple example I have from whizlabs diagnostic exam.

How many object references will be refering to "Garbage" object at the end of the code.
So this is my approach
x---------> new Integer object 10
y---------> new Long object 100
z ---------> new String object "Garbage"
obj ------> now pointing to the object refered by x (i.e) 10. At this point Integer obj 10 has 2 reference variables x,obj
x--------->z. That means x is now pointing to Garbage. At this point x's reference to 10 is removed and arrow is drawn to "Garbage".
z --------->y. That means z is now pointing to Long obj 100. At this point z's reference to "Garbage" is removed.
y---------->x. That means y is now pointing to Garbage. At this point string obj "Garbage" can be reached by two references x,y.

Please tell if my approach is correct. Should I follow the same approach for all GC questions.
I am trying to relate the example from Chapter5 of K&B with one of the examwatches in Chapter2 (Page 104-Examwatch & Page Page390- Q3). But I have difficulty fixing the unreported exception error while compiling. Can anybody please explain.
Two topics involved here are
1. Overridding a method (I think I understood this right)
Overridding a method of the parent class which declares a checked exception with a method in the subclass that may or may not declare the exception. But if the overridden method declares an exception, it can be a run-time exception or an exception that is not broader than the parent class method.
2. Polymorphic super type reference referring to the subclass type (I still can't understand why the compiler cannot recognize this as the parent class method at compile time. Can somebody please explain this also)

Thank you very much for all the thoughts and especially for the message posted by Neha Daga. I really appreciate your help and time.

how are you planing to give a name to object car if that object do not have any member to do that.

I know that car object has no name instance variable....but I am trying to convert the abstract car into a HondaCar object and then set the instance variable "carname" of HondaCar class.

I am not sure how perfect the example is ...but am trying to learn how I can use an abstract class, the new for-each construct and also casting. Please correct if I am using an incorrect example in the first place
Hi Folks,
I am trying to do some basic coding for using an abstract class but I am having some trouble putting my imagination into coding. Can somebody please help me complete this code. Basically, I want to create an array of abstract cars and convert each abstract one into a hondacar and set the instance variable carname.
Thanks in advance for your precious time and help.
Abstract class

HondaCar class

Hello Folks,
Can somebody please confirm if this summarized list correct. The list is incomplete too with lots of question marks. Please help me complete the list. Thanks in advance.

Access Modifiers for methods
1. Public method
2. Private method
3. Protected method
4. Default method

Non-access Modifiers for methods
1. Final method
2. Abstract method
3. Static method
4. Synchronized method
5. Native method
6. Strictfp method

Combination of ACCESS + NONACCESS modifiers for methods1. final + abstract --> not allowed
2. final + static -----> allowed
3. final + synchronized --> ?
4. final + native --> ?
5. final + strictfp -->
6. abstract + static --> ?
7. abstract + synchronized --> ?
8. abstract + native --> ?
9. abstract + strictfp --> ?
10. static + synchronized --> ?
11. static + native --> ?
12. static + strictfp --> ?
13. synchronized + native --> ?
14. synchronized + strictfp --> ?
15. native + strictfp --> ?
16. final + with {public, private, default, protected} --> allowed
17. abstract + with {only public } --> allowed
18. static + with {public, private, default, protected} --> allowed?
19. synchronized + with {public, private, default, protected } --> allowed
20. native + with { public, private, default, protected} --> allowed?
21. strictfp + with {public, private, default, protected} --> allowed?
Thanks for all the valuable encouragement and suggestions. Hope the second reading will make more sense to me
Hi Folks,

I finally finished reading 7 chapters from K&B book. I know I read the book at a slow pace. When I was reading, most of the topics like polymorphism, casting, statics etc which I thought I knew before were fairly new but I understood them all.

But now, when I look back for a review... I am almost scared I forgot them all and have to study those chapters all over again.

Can somebody please advise if I have memorize any rules besides simply reading the book. Thanks in Advance.
I have a question too... (I have no problem with the output that I ran)

When the control enters main...should it now first see the print statement and print "pre" and continue with the rest of the output?
Then when it sees new C() .... call the contructor of B which in turn calls A's contructor.
Can somebody please reiterate the rules for running static/initialization block and contructors.

Thanks in advance.
I really appreciate your response. But I have one more question before I close with exceptions.
As you said that we have two options
1. use try-catch code for exception
2. duck the checked exception

Here is the example for option1. In this example ---filenotfound is a checked exception.
Can you please help me modify the handlingMethod() to duck the checked exception (that means to use option2)

I think I have to get my basics right with Exceptions. Please help and correct if I am not right.
Example code

  • If a riskymethod() throws a CheckedException, duckingmethod() calls the riskymethod() and does not "handle&declare" the exception, ---compile time error occures(JVM says unreported exception...)
  • If a riskymethod() throws a uncheckedException, duckingmethod() calls the riskymethod(() and does not "handle&declare" the exception thrown by the riskymethod() --- compiles fine---but run time error occurs
  • If a riskymethod() throws an Error, duckingmethod() passes the Error to the main() and does not "handle&declare" the Error thrown by the riskymethod() - compiles fine --but runtime error occurs

  • I understood the rule Handle & Declare
    But in K&B exam watch (page 362) it says

    When an object of a subtype of Exception is thrown, it must be handled
    or declared.

    So...does that mean it can be either handled or declared. How can I apply to my example below.

    As said in K&B if I have a userdefined Exception class like this:

    Suppose, I am throwing the userdefined Exception in the risky method - How do I handle? How do I declare.
    This class has two methods.
    1. One riskyMethod() that throws and exception
    2. One duckingMethod() that calls the riskyMethod.

    And now, in the main() method...I am calling the duckingMethod. I know we have to Handle and declare rule - how do I implement this rule in the above code