Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!

AmanZeeK Verma

Greenhorn
+ Follow
since Dec 06, 2010
AmanZeeK likes ...
Android Eclipse IDE Firefox Browser
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
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by AmanZeeK Verma

Snatched some good points from net, this might help you.

•Any implementations can change value of fields if they are not defined as final. Then they would become a part of the implementation.An interface is a pure specification without any implementation.

•If they are static, then they belong to the interface, and not the object, nor the run-time type of the object.

•An interface provide a way for the client to interact with the object. If variables were not public, the clients would not have access to them.

So, they are public static and final variables!!!.. It belongs at implementing class level and not class's generated-object level and defines spec. of implementing class.

Hope it helps.
9 years ago
How did you create your test.jar file ?

The META-INF folder inside jar has a file MANIFEST.MF which seems to be missing entry for main class

something like Main-Class: com.zeek.test.SomeClassName
9 years ago

your system may not be the same as on the fellow sitting next to you and that is what K&B book meant in making the statement quoted



This is not only meaning of the statement ...the same code when executed on same machine can also produce different results, if thread priority is the criteria to determine the output.
You have three things to see actually, Thread C is started at last, (A and B is in progress); random sleep is *again* random; You cant rely on priorities. Basically these multiplication of probabilities are making things worse to analyze.

I tried same code with 1) no sleep 2) Constant sleep 1000
In first Case: Thread-C finished well in advance (even though it was started last)
In second Case: Thread-C finished before B but could not beat A


I further tried to find reason for second case, the problem was small loop, I increased max(i) to 1000 (and modified constant sleep 1000 to 10) and now C finished before A and B (not well before but yes it finished before)

I tried to re-check the effect by varying sleep constant and range of i; The more I allow threads to work, the chance of getting C first finished gets increased. Eg. I tried Sleep constant 1 and max(i) 10000 (removing unnecessary sysouts for faster processing) and C finished well in advance.


Similar maths can actually help, but in practice result can really vary!

Please consider Type Erasure and dry run on JVM


To understand this, suppose, you have a following extra class


now printSize(list3) can return List<? extends Chewable>

If I am collecting the returned value as
But, this case is collecting it as List<Meat> (why not List<ChewingGum> ?? ..)

so, compiler canot ensure this.. unless you catch it properly (? extends Chewable)

Hope this can help to some extent!!..

EDIT/UPDATE: Oops, you already knew this (as mentioned in question)...
The previous line (printSize(line2)) is List<Chewable> ... Its again creating ambiguity for compiler. Remember in Runtime there will be Type Erasure... so JVM does not know about type of List!!..
The statement merely means... the retrieval of the object in Collection (HashMap say) must be from the same bucket, it was stored to....

Address would/will still be different!
I really liked the question, tried googling it...

Here is one link that has this discussed, I still would like someone to explains this detail...

http://stackoverflow.com/questions/4401743/why-final-static-int-can-be-used-as-a-switchs-case-constant-but-not-final-sta


The code above says,
1. Create an object Child and assign it to a ref to Parent p1 -- Thats ok, all Child can be ref by Parent like All Dogs can be ref by Animal... Dog IS A Animal
2. Create an object Parent and assign it to a ref of Parent p2 -- No doubt!.. that's prefect.
3. Cast a Parent to Child and store it on Child, please note we are not creating any object here. Now compiler wont complain since you explicitly want an Animal to be a Dog, legal but not appropriate to cast without checking -- Runtime error in this case!!
4. Cast a Parent ref (which holds a Child) to Parent and refer it using Child.... gotcha!.. Animal IS-A Dog?? that may not be true, and hence compiler complains.

Hope this helps!

//updated: poor english!
I am guessing the source would be a blog with hundreds of question dumped with answers and no explanation!!

@svm muni: If above statement is the case, Please don't trust those blogs/sites, rather trust your book theory and compiler.

By the way for assertions,
1) Do not 'assert' the argument of a "Public" class
2) Do not tend to 'modify' while 'asserting'

Rest is self explainatory, I hope I am not missing any point.
Thats simple.. got confused when explicitly passing null as a param.
Thanks
Please justify the output of the following code:



Source: http://www.angelfire.com/or/abhilash/
Output: String

I was told that IS-A means, we should use either extends or implements Runnable.

--> Please cross check

This is seriously going off the track!..

Consider following points:
1) Since its an objective question, which has various options and Dog IS-A Animal is fine. Only other option that can be selected is Dog IS-A Dog, all other options are 100% wrong.

2) However please note a code like

will not compile, saying Cyclic Dependency.

3) benefit of doubt to Dog IS-A Dog since you can cast a Dog instance to Dog Type.