jimmy halim

+ Follow
since Nov 28, 2006
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 jimmy halim

My exam's report details :
* Declarations, Initialization and Scoping : 100%
* Flow Control : 100%
* API Contents : 90%
* Concurrency : 84%
* OO Concepts : 90%
* Collections/Generics : 100%
* Fundamentals : 90%

I think the toughest is questions about thread, there's 1 questions about predicting possible output and that's really give me headache
13 years ago
Finally I take SCJP exam yesterday and passed with 94% score (more than I expected)

Although I just been here for several weeks but Javaranch really help me in achieving this
Thanks for all ranchers in SCJP section

And of course special thanks to Kathy Sierra and Bert Bates for their excellent book

[ December 11, 2006: Message edited by: jimmy halim ]
13 years ago
I don't think inherited methods mean have a copy of it on subclass. (I'm not sure though)
Because it's not overridden in subClass the method's owner still the superClass
And because variable cannot be overridden the superClass' methods will reference to superClass' variable

Other ranchers have any answer, reference or idea?

How about the idea checking is there any way to get the object reference.
If there's no way the get the object through variables, arrays, collections, etc then the object is eligible for garbage collection

From the example if we want to check that object that created at : "I i1 = new I();" . Is it eligible for garbage collection after calling method m1(), just check if you can get any reference to it.

Because an object is eligible for garbage collection is when no live thread can access it.

Drawing diagram that Mark said also a great way to describe references, my idea is just another fast and simple way (although maybe dangerous )
It's because unlike methods, variables aren't be overridden but shadowed

look at this sample:


If you called the variable/field from a method it will reference to the class variable which the method called. If the method is overridden by the subclass, then the variable at subclass is called. If not then the parentclass' variable is called.

When you accessing variable directly (not via method) then it's depends on class type not instance type (example: line 3)

You can access parent variable using super, example : super.msg from subclass' method
IMO from the mock exam SCJP 1.4 is much easier than SCJP 5
(I'm not certified yet, planning to take SCJP 5 exam this Dec 11)
I was preparing for 1.4 then I change my mind to take 5 instead 1.4, and I feel there're really alot new things to learn (not to mention trickier questions )

If you don't have enough time taking SCJP 1.4 instead SCJP 5 in my opinion is a wise decision

Read K&B book & try several mock exam for try out (there're alot free & commercial mock exams)

Does anyone know...

In terms of the exam, when it states
"1.An anonymous inner class may be declared as final "
is the answer going to be false, since you cannot apply modifiers to an anonymous inner class. Or will it be true, because anonymous inner classes are implicitly final?

It seems that you could get this question wrong even if you understood anonymous classes?

Yes I also wondering what will be the right answer, it's ambiguous
At first sight I though the question is about declaring explicitly.

Thanks alot to Abdul Rehman for the JLS info

Maybe the questions should be clearer with stating if it's explicitly or not
IMO the right answer is C
because the output is "x=1111", so all boolean expression in the question are true


If two objects are equal according to the equals(Object) method, then
calling the hashCode() method on each of the two objects must produce the
same integer result.

from :
(A) x2.equals(x1) == true

Because x1.hashCode()!=x2.hashCode() means x2.equals(x1) == false. If they're equals the should have same hashcode result. So option A is wrong

x3.equals(x4) == false
(B) x3.hashCode() != x4.hashCode()

We cannot determine whether their hashcode is equal or not, because if 2 object are not equals they can have same or different hashcode. And that not violating the contract. So option B also wrong

x5.equals(x6) == true
(C) x5.hashCode() == x6.hashCode()

Their equals so that mean their hashcode should be equal too . So C is right.

from :
x7.hashCode() == x8.hashCode()
(D) x8.equals(x7) == true

Even their hashcode is equal we cannot say the objects also equals. because it's possible and not violating the contract for 2 un-equal object having same hashcode. So D is not correct.

It is NOT required that if two objects are unequal according to the
equals(java.lang.Object) method, then calling the hashCode() method
on each of the two objects must produce distinct integer results. However,
the programmer should be aware that producing distinct integer results for
unequal objects may improve the performance of hashtables.

[ December 04, 2006: Message edited by: jimmy halim ]
I don't mean to discouraged you but 2 weeks without Java background is really hard
Because SCJP questions is really tricky, required you to have some experienced in java plus know the basic details (this is the tricky part)
I cannot give advice other than
- Negotiate with your boss for more time
- Study like crazy in 2 weeks (read mocks exam explaination all day)

Good luck

1.An anonymous inner class may be declared as final
2.An anonymous inner class may be declared as private

I don't think anonymous inner class has modifier beside what inherited from it parent (the inner-class). Modifier used to interact (is-a or has-a) with other classes.
But anonymous class only used once, it has no name.

And I don't have any idea where we can put a modifier in anonymous class

We can only extend 1 class or interface in anonymous class

4.An anonymous inner class can access final variables in any enclosing scope

Like other inner class, it can access any outer class method & property. And final local variable.

5.Construction of an instance of a static inner class requires an instance of the enclosing outer class

because it's static we don't need outer class' instance

From JavaDoc :

This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class's natural ordering, and the class's compareTo method is referred to as its natural comparison method.

So instance of class that implements Comparable expected can be compare properly (not violating the contract) to other instance of same class.

Methods & classes that required input/elements object that implement Comparable
  • Collections.sort(java.util.List)
  • Arrays.sort(Object[])
  • TreeSet
  • TreeMap

  • You're right.
    My mistake, I don't read the option well

    It'll not violating the contract if the equals :

    Using String's length and mathematic (*/+-) operation on equals is really not an equals
    I don't see any misleading here

    When you use:

    Produce :

    It's not the original java.util.ArrayList, it's inner-class from class Arrays.
    The inner-class ArrayList has custom get & set method, it's connecting to the array variables
    So when you change the content of array or list it'll change the same data.
    With this Arrays$ArrayList class you cannot add/remove, it'll give you java.lang.UnsupportedOperationException

    But when you use :

    Produce :

    It's a new Object, the original java.util.ArrayList class. And have no connection with the Array variables.

    Maybe the book just not explicit say that the asList() method return a inner-class in class Arrays that declare like this

    [ November 30, 2006: Message edited by: jimmy halim ]
    An abstract class can be compiled successfully even if it's extend concrete class, there's no compiler error on that

    The compiler error is when :
    - you instantiate an abstract class
    - putting final & abstract modifier together
    Because option D isn't violate the equals or hashcode contract.
    It's not optimal but not violating the contract


    You will get a lot 2 Object that not equal but has same hashcode, although it's maybe not optimal but it's not violating the contracts
    Because every equals object will generate same hashcode return.

    So creating stricter (more variable involved) equals than hascode will not violating the contract. But if you created stricter hashcode than equals you violating the contract :
    "If two objects are equal according to the equals(object) method, then calling the hashCode() method on each of the two objects must produce the same integer result."

    I hope I explain it clearly
    Pardon me if there're something wrong with my grammar or vocab