Ameen Imtiaz

Greenhorn
+ Follow
since Mar 18, 2013
Ameen likes ...
Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ameen Imtiaz

thanks. Yes maybe i used the wrong term. the site is not down. Just unavailable.

Anyway, thanks for the alternate link. thats what I wanted. I have been waiting to download 0.23.x since yesterday.

Regards,
9 years ago
Try all the mirrors without /common/ and you will be able to entry the directory structure but will only find: chukwa-0.4.0/
9 years ago
Thanks for the reply

but all the mirror site are giving the same error.

Have you clicked on the mirror site and reached the directory structure?

The directory structure of hadoop after /hadoop/ is missing on all the mirror.

please click on the mirrors.
9 years ago
Hi all,

ok is it just me or the hadoop download site (http://hadoop.apache.org/releases.html#Download) is really down? like all the mirrors since yesterday.

any advice. is there any other place to download hadoop.


regards,
9 years ago
The only thing that is guaranteed is that "Yes" will be printed last due to test.join().
Hi,

Can you confirm your statement: "main thread is always of high priority than child thread "?

As far as I Know "the child thread always gets the same priority as the priority of the thread that creates it" As stated on page 725 of K&B book under "Setting a Thread's Priority".

Also, in the Java docs, http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html, It states: "When code running in some thread creates a new Thread object, the new thread has its priority initially set equal to the priority of the creating thread".

Regards,
Remember, there are 2 different things.

1- Reference variable: Used to point / refer to Objects.
2- Object: Instance of a class.

Both have types. So there is the type of a ref. variable and the type of an object.
Before going to explanation lets make some classes:

class Vehicle{}
class Car extends Vehicle{}
class SportsCar extends Car{}


Now lets try to answer the following important question.

What type of objects can a certain type of reference variable refer to?
I will answer this with the words of K&B book. "A reference variable can refer to any object of the same type as the declared reference, or—this is the big one—it can refer to any subtype of the declared type!" (page 99, point 4). Also in case of interfaces, "If the variable is declared as an interface type, it can reference any object of any class that implements the interface." (page 99, point 5)

So if reference variable can refer to objects of subtype then remember that they can NEVER refer to objects of supertypes of the declared type. And this is the most important thing to remember when using casting. We will call this the "Super Rule"

So,

Vehicle v = new Car(); // LEGAL reference variable v referring to a subtype
Car c = new Vehicle(); // ILLEGAL reference variable c can NEVER refer to the supertype Vehicle


Before we move to Casting, Burn this in your mind that reference variables can NEVER refer to objects of supertypes of the declared type.

Reference Variable Casting

Key Points to remember while preforming casting:

  • A reference variable can be assigned any other ref. variable if its type is a subtype of the declared type, implicitly. This is upcasting i.e.

  • Vehicle v = null;
    Car c = null;
    v= c; // can be assigned without casting

  • A reference variable can be assigned any other ref. variable if its type is a supertype of the declared type, BUT explicitly. This is downcasting i.e.

  • Vehicle v = null;
    Car c = null;
    c=(Car)v; // can be assigned by down casting

  • The Super Rule: Reference variable can refer to objects of subtype and they can NEVER refer to objects of supertypes of the declared type.
  • At compile-time compiler only KNOWS the ref. variable type and NOT what type of object the variable is referring to.
  • At runtime the JVM knows the type of the object that the variable is referring to.

  • Lets use the above points in the below examples:

    #1
    compilation: Suceeds. As the reference variable 'v1' is assigned another reference variable 'c' without using any casting. 'c' ref. variable's type is subtype of the 'v1'. No casting required.
    Runtime behaviour: Suceeds. As the reference variable 'v1' will be referring to the object in reference variable 'c' which is of type Car (This was assigned at line 2)
    Casting Type: Upcasting
    #2
    compilation: Fails. As the reference variable 'c1' is assigned another reference variable 'v1' without using any casting. 'v1' ref. variable's type is supertype of 'c1'. This requires explicit Casting to compile.
    Runtime behaviour: N/A. Didn't compile
    Casting Type: downcasting. Must be explicit
    #3
    compilation: Suceeds. As the reference variable 'c2' is assigned another reference variable 'v1' USING explicit casting as it is required because 'v1' ref. variable's type is supertype of 'c1'.
    Runtime behaviour: Suceeds. As the reference variable 'c2' will be referring to the object in reference variable 'v1' which is of type Car (This was assigned at line 5). Based on Super Rule this is OK by JVM
    Casting Type: downcasting. Must be explicit
    #4
    compilation: Suceeds. As the reference variable 'c3' is assigned another reference variable 'v' USING explicit casting as it is required because 'v' ref. variable's type is supertype of 'c3'.
    Runtime behaviour: Fails. As the reference variable 'c3' will be referring to the object in reference variable 'v' which is of type Vehicle. At runtime JVM knows the type of the object in ref. variable 'v' and the Super Rule kicks in which is that a ref. variable can't refer to a supertype.
    Casting Type: downcasting.
    #5
    compilation: Suceeds. As the reference variable 'o' is assigned another reference variable 's' without any casting because 's' ref. variable's type is subtype of the 'o'.
    Runtime behaviour:Suceeds. As the reference variable 'o' will be referring to the object in reference variable 's' which is of type String (a subtype of Object). This is acceptable by JVM according to Super Rule
    Casting Type: upcasting.
    #6
    compilation: Suceeds. As the reference variable 'c5' is assigned another reference variable 'o' USING explicit casting as it is required because 'o' ref. variable's type is supertype of 'c5'.
    Runtime behaviour: Fails. As the reference variable 'c5' will be referring to the object in reference variable 'o' which is of type String. At runtime JVM knows the type of the object in ref. variable 'o' and the Super Rule kicks in which is that a ref. variable can't refer to a supertype.
    Casting Type: downcasting.

    When to use Downcasting?

    There are many situations where you might use downcasting. This all depends on the design and the solution of the problem your are working on. The example in K&B Book is very good. You will come to understand the importance and usage of this concept as your experience in software development increases.

    Also in k&B book once you come to the Collections and Generics chapter, will see some usage of downcasting.

    One of the places where you need downcasting is when you override equals(Object o) method!

    I hope this helps.
    Just remember that Appropriate mean to fullfilling the contracts. i.e.

    If x.equals(y) is true, x.hashCode() == y.hashCode() MUST be true.

    So to know whether the implementation is appropriate, you have to check the code of both equals() and hashCode().
    Legal:
    means correct syntax. compiles successfully. Follows the override rules. Also, hashCode should override and not overload. All this will make it Legal and correct hashCode().

    Appropriate:
    Fullfills the contracts. i.e. two equal objects have equal hashcodes.

    Efficient:
    Has to do with the algorithm / formula used to return the value. Should be distributed as evenly as possible.

    Examples:

    1) Below code shows illegal hashcode. Has incorrect override

    2) Below code shows legal and appropriate implementation of hashCode() as it fulfills the contract. Although its highly inefficient.


    3) Below code shows legal BUT inappropriate implementation as it does not fulfill the contract. The equal() is based on Person's name. So two objects with same name are "meaningfully equivalent" BUT the hashcode() will not always be same as its is based on age. So the hashcode() does not fulfill the contract which is that if two objects are equal, their hashcodes must be equal as well

    To make the above class appropriate for Sets and Maps, we have to change the hashcode() implementation in such a way that when two objects are equal according to the equals(), then the hashCode() of both objects must return same value. Below is one possible solution:


    As the String's hashCode() is very efficient, hence we have made our hashCode() implementation LEGAL, Appropriate and also very efficient.

    I hope this helps.

    First of all, overriding has to do with Polymorphism. The overriding methods are selected AT runtime based on the instance's type in the ref. variable at that moment.

    Whereas, the static methods invocation is always decided at compile time. So if an instance variable invokes the static method then the compiler actual replaces the obj with the class (type) of that ref. variable. All this is explained on page 150 of K&B (Ch 2). Which states:

    "
    int frogs = f.frogCount; // Access static variable FrogCount using f

    ...This is merely a syntax trick to let you use an object reference variable (but not the object it refers to) to get to a staticmethod or variable...
    ... In other words, the compiler cares only that reference variable f is declared as type Frog...
    "

    Hi All,

    This is my first post. Currently I am preparing for OCJP 6 exam. Studying the study guide by Kates & Bert. While reading the Introduction under the heading "Tips on Taking the Exam" it states:

    "Check for syntax errors first: count curly braces, semicolons, and parenthesis and then make sure there are as many left ones as right ones. Look for capitalization errors and other such syntax problems before trying to figure out what the code does."

    A very good tip and I just want to optimize the tip by saying that "Do the above ONLY when you see a 'compilation fails' or 'error on line #' or similar choice in the answers. Otherwise start figuring out what the code does."

    I hope this helps.

    Regards,