Paul Stat

Ranch Hand
+ Follow
since Jan 20, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Paul Stat

Basically if you have <? extends Whatever> as a generic declaration. The extends is saying you can use any list of type Whatever or its subtypes, but you are not allowed to add to the list ever. Kind of a contract.

If you changed it to <? super Whatever> then you could add to the list so long as it's Whatever or one of its super types
hint this is the same as saying

Took my SCJP 5 test this morning and i PASSED......just. Oh well a pass is a pass, plus I know the areas I need to improve upon

Namely: Concurrency 37% and API Contents 40%

All other areas were mainly either Hi 60%'s or low 70%'s
15 years ago
himanshu it's quite simple really, interfaces methods are always implicitly public and abstract, so these two declaration of the animal interface are exactly the same



So in the first example even though we haven't declared it to be public + abstract IT IS!

Now when we have a class that implements this interface as



It may appear we've fulifilled the contract, BUT we're giving the saySomething method default privileges, which is MORE restrictive. The same is true when we extend a class and override it's methods, we can't make the overriding methods MORE restrictive

HTH
lookup greedy quantifiers

also, try splitting the output over two lines



that should give you some clues

Kavita Tipnis wrote:You can make the overriding method (public void graze())
less restrictive than the overridden method(void graze()) , so C should be correct.



Yeah but it's not though is it because Pasture is extending Animal, therefore inheriting saySomething, which is implicitly public, therefore we can't override it and make the access MORE restrictive. So C must be wrong

And besides the public void graze(){} in interfaces IS the same as the one in Pasture as it's implicitly public (and abstract ofcourse)
Hello folks,

Am I right in saying that because of the following:

Quote from Sun

for (initialization; termination; increment) {
statement(s)
}

When using this version of the for statement, keep in mind that:

* The initialization expression initializes the loop; it's executed once, as the loop begins.
* When the termination expression evaluates to false, the loop terminates.
* The increment expression is invoked after each iteration through the loop; it is perfectly acceptable for this expression to increment or decrement a value.



These two lines are equivalent?


This is from Practice Exam Q7: SCJP Exam for J2SE 5 Platform Paul Sanghera

Consider the following source file:


Which of the following code lines insered independently at line 7 will make this source file compile?
A: interface Pasture {void graze();}
B: interface Pasture {void graze(){}}
C: interface Pasture extends Animal{void graze();}
D: interface Pasture extends Animal{void saySomething(){}}
E: interface Pasture implements Animal{void graze();}

Answer: A+C

I put A, I don't see how C can be correct when the saySomething() method in Animal is implicitly public and here we'd be setting default access levels???
Hello folks,

Just practicing away and I came across this exercise where you have to Synchronize on a StringBuffer object that initialised with a value of "A". You then have to print that out 100 times on a line, then increment the value. We're supposed to create 3 instances of this thread and start them one after the other so when main is run it should print out 3 lines, one with A's, one with B's and one with C's.

It asks us to use the StringBuffer object so that we don't have to create a new object as StringBuffers are mutable. It also says to increment the value of the StringBuffer to check the methods available to us in Chapter 6.

Now I've managed to do the exercise, but not in exactly the way they are describing, see below



Ok so I got the desired result, but I'm not satisfied that I haven't been able to acheive it in the way K&B describes! Any hints?

Ankit Garg wrote:You are confused here. You are mixing releasing lock and getting CPU time. Lets take an example. Suppose I'm playing a video game. And you are sleeping in your bed. When I shout that I'm about to finish my game and you can play, it is like notifying. When I shout (i.e. notify you) you wake up and are willing to play a game (it is like a thread being eligible for CPU time). But I have not left the game console yet (i.e. when I notified you, I didn't release the lock on the object i.e. game console). I think this will make it a bit clear ...



Nice analogy thanks for that
Ok so here's the steps



Hope this helps

Ankitt Gupta wrote:Believe me I found Thread very easy.I guess following K&B very nicely will build the concept.And thread is all about concept.



Hmmm I guess I need to read that chapter a few more times then, I found understood the examples in the chapter but when it came to the questions at the end I found them very hard.

Deepak Bala wrote:What is it about the thread questions that make it difficult for you ?



when it's questions about what methods are in Thread, Runnable, Object that's fine. When it's a bit more involved and you're asked to predict the output say I find that tricky. Or perhaps saying what can and can't access synchronized code, that sort of thing
I hate involved Thread questions, I just find them soooo hard. I tried some exercises from one book got 70%, then I tried the questions in the K&B book and got 20%!

Any tips for getting my head around Thread questions?

Henry Wong wrote:

Paul Stat wrote:

Senthil Kumaran wrote: i suggest you to re look the toarray() and aslist() methods again,.,



enlighten me



No offense, but it takes less than a minute to look it up yourself. Why do we need enlighten you?

http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html

Henry



Ok fine so it


Returns an array containing all of the elements in this list in proper sequence



But what happens to the original String[] array, is it just subject to the garbage collector?