Melanie Jones

Greenhorn
+ Follow
since Dec 16, 2005
Merit badge: grant badges
For More
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 Melanie Jones

You're understanding is right!!

Just a little change in your code and everything will sync in..



- Mel



As the compiler said, EOFException is never thrown within the try block, so it's smart enough to tell you that your catch block for an EOFException is never going to be used and is simply code that will never be used. As for getting an error when you call main1(), since main1() declares that it throws two checked exceptions, the call to main1() must either be wrapped in a try/catch block or main() itself must declare that it also throws these exceptions.



As told the call to main1() method should be inclosed that is the main method. THats where you are calling from! You have moved the main1() method to try/catch block!!!

When JVM starts it looks at the public static void main(String[] args) and in you updated class it has nothing to execute. (only 1 commented line...so there's no output)

Uncomment the call to main1() in main() and surround it by try/catch.

- Mel
No Inheritance applies only for parent-child relationship....but IS-A relation can be applied to anything that passes the actual instanceof test!!

So an implementer class IS-A (instanceof) the interface its implementing but they definetely they do not share the parent-child relationship!!

Also IS-A can be applied to any higher level hierarchies...

class A {}
class B extends A {}
class C extends B {}



An instance of C will pass the IS-A test for A. As intance of C is kindof grandchild of A.

On a similar kind this can be adapted for interfaces...

interface A {}
interface B {}
class C implements A, B{}



An instance of class C will pass the IS-A test for both A and B.

- Mel



- Mel
Key Rule here is that if any two objects are meaningfully equivalent (return a true while using the .equals() method) then their two hashcodes should be the same. So (x.equals(y)) is true then (x.hashCode()==y.hashCode()) is true.

(x==y) indicates the two objects are pointing to the same location hence the objects have the same value and as per the rule above the same hashcodes!!

I think with this you can figure out the results are a) and c). Also true true true is also possible.

- Mel
Instance variables are initialized only after the corresponding constructor completes execution...So I guess b=0 is because of the default value of int instance variable!! Not sure if this makes sense?

- Mel
Lets see...

void call ( ) is an overridden method. Object Type determines which overridden method is called at runtime.

Because the object created is the Q05 child object...both the parent constructor and the child constructor calls only the child objects call method!! Hence the result!!

- Mel
yeah I understood how Java works in this scenario....


public void findOut(Integer y)
{
// Line 1
y = null;
}



At Line1 inside the method "findOut" both Integer y and the calling method's Integer x keep pointing to the same location (the same object on the heap)...

Execution of "y = null;" is just way of telling (in K&B words ) OK!! enough of you pointing to same location as x...now point to nothing!! So y is lost to the world but the Integer x still holds the reference!!

Im Clear!!

- Mel
Need some additional clarification...


public void findOut(Integer y){
y = null;
}



My understanding....
In the above method the argument passed to the method "findOut" is an Object Reference. Meaning its just a some combination of bit-pattern that takes us back to the same object from the calling method.

So Integer y in the method "findOut" and the Integer x in the calling method should be pointing to the same object on the heap as "y" inside "findOut" is only a reference...am I right??

If right then I guess when Integer y in the method "findOut" is set to null then the corresponding Integer x in calling method will also be assigned to null and hence becomes eligible for GC...

Let me know if I am missing something here??

- Mel
#1 is patially true
ArrayList can store elements that are Objects. So any reference to a type Object can be directly stored. A primitive like int can be still be store provided its converted to an object. Ex. Integer. ArrayList can also store a null.

#2 True.
Much cannot be explained about this. The definition of ArrayList is like:

public class ArrayList extends AbstractList implements List, RandomAccess, Cloneable, Serializable

#3 True
Refer to the API...http://java.sun.com/j2se/1.4.2/docs/api/

#4 Definetely elements are not sorted in an ArrayList.
Only in TreeSet and TreeMap elements are stored in the ascending order. Both TreeSet and TreeMap implement the SortedSet and the SortedMap interfaces. ArrayList implements only the List interface hence the elements are not automatically stored in the sorted order.

Hope this helps!!

- Mel
18 years ago
Hey thanks for the update too!!

I almost forgot "/" operation depends on the operand types!! Guess I was

All the best in your preparation!! 1.4 or 1.5??

- Mel
You are using a "/" operator which would perform only integer division. The result of using this operator is only the integer part of the entire divison operation!! Hence the result is only 1 and not 1.42

Casting and the truncation has not connection.

Truncation is because of the operator "/"

- Mel
Typically, implicit cast happens for all "widening" conversion. Putting a smaller thing (int) in a larger container (long).

Conversely, putting a large value (int) into a small container (byte) is caller "narrowing". This requires explicit cast.

If more details are required on this refer K&B for 1.4 Ch#3 Pg - 113. (thats is if you have the book)

Thanks
Mel
As long as the return type is larger the result would be automatically casted to long!!! (long can hold an int)

Its only when the return type is smaller like a byte an explicit cast is required!!

byte test( int x, float y) {
return (byte)x/7;
}
For WSAD this might be a good link...

http://www.redbooks.ibm.com/abstracts/sg246957.html?Open

Though I dont have much inputs on the certification front!!

Thanks
Mel
Congrats!!

Would you be able to tell me some reasons for attempting 1.4 when the next version is available??

I�m still trying to figure out which exam to opt for? (Between 1.4 and latest version). I do have 3 yrs of exp in Java but I very well understand thats not going to help me out much for the Certification mode of Questions.

I�m just starting off with getting certifications...so don�t want to take a big leap and also have a great fall at the same time!!

Any inputs??

- Mel
18 years ago