File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem in threads(sun accesibility test) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem in threads(sun accesibility test)" Watch "problem in threads(sun accesibility test)" New topic
Author

problem in threads(sun accesibility test)

manny singh
Greenhorn

Joined: Jan 18, 2008
Posts: 28


Which is true?

The output can never contain the value 10.
The output can never contain the value 30.
The output can never contain the value 297.
The output can never contain the value 820.
The output can never contain the value 1010.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

JavaRanch is not just an answering machine.

What do you think the answer should be yourself, and why? Is there something specific about the question that you don't understand? If so, what?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
manny singh
Greenhorn

Joined: Jan 18, 2008
Posts: 28
dear Jasper,

i am not finding the fact behind the questions that is why i am asking.if it is not answering machine then stop this forum and do rest at home because everyone here is to get answer to his question.if you can not give answer then just stay quite and let others consider.
thank you.



[BPS: Removed code tags]
[ April 29, 2008: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by manny singh:
dear Jasper,

i am not finding the fact behind the questions that is why i am asking.if it is not answering machine then stop this forum and do rest at home because everyone here is to get answer to his question.if you can not give answer then just stay quite and let others consider.
thank you





manny singh,
Our first and most important rule here is to be nice.

Jesper is a staff member at Javaranch and is a moderator of this forum.
He is donating his time to help keep this forum running well.

Part of this task involves letting people know when they not asking well formed questions. There is a difference between asking for help and asking someone to do the work for you. Pasting a mock question into the forum and asking someone to answer it and explain why their answer is correct falls in the later category and is not encouraged here.

-Ben

[ April 29, 2008: Message edited by: Ben Souther ]
[ April 29, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

In addition to the link posted above, please also see UseRealWords.
Wrapping your posts in code tags to overcome Javaranch's checks for non-words causes your text not to wrap and be displayed in a mono spaced font.
These things make your posts much harder to read and thus, less likely to get a meaningful answer.

-Ben
manny singh
Greenhorn

Joined: Jan 18, 2008
Posts: 28
sorry


BYE FORUM
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
Originally posted by manny singh:


Which is true?

The output can never contain the value 10.
The output can never contain the value 30.
The output can never contain the value 297.
The output can never contain the value 820.
The output can never contain the value 1010.


Before you go to some other forum here is answer.

O/P = 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 380 390 400 410 420 430 440 450 460 470 480 490 500 510 520 530 540 550 560 570 580 590 600 610 620 630 640 650 660 670 680 690 700 710 720 730 740 750 760 770 780 790 800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990 1000 1010

Answer 3 is correct. 297 is not valid value.


SCJP <br />SCWCD <br />SCBCD <br />SCEA-1
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Vishal,
Do you really think you did Manny a favor by compiling and running the code in his original post for him?
-Ben
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
I guess NO...
I was going to ask him to atleast compile & run but then I thought I would be offensive.

I will restrain from doing so from next time onwards.
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
[BPS: Be nice]

[ April 29, 2008: Message edited by: Ben Souther ]

<a href="http://faq.javaranch.com/java/UseRealWords" target="_blank" rel="nofollow">Use Real Words</a> <a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">!!!Use Code Tags!!!</a> <a href="http://faq.javaranch.com/java/SayThanks" target="_blank" rel="nofollow">Say Thanks</a><br />scjp6
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8815
    
    5
Wow what a thread!

Manny, if you're still here, I'd like to clarify something. The ranchers and moderators here have a LOT of experience when it comes to preparing for, and passing the SCJP. Our combined experience tells us that the way to pass the exam is to write a lot of code, and experiment with the mock questions that you're studying. It won't work to try to memorize stuff, it works when you actually LEARN the concepts that drive the code.

So, we're not being unfriendly when we ask you to do more work before asking your questions, we're asking you to do what works! We want you to pass this exam!

hth,

Bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
manny singh
Greenhorn

Joined: Jan 18, 2008
Posts: 28
i am extremely sorry for the question i asked and my behavior.
i was asking this because one can't have permission to go to compile in the test so how do come to result.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You're correct in that you can't compile during the test but when studying for the test the best thing you can do is write, compile, and run lots of code.

Try to figure out what the answers are for the last 3 questions that you posted here. Then, compile and run them to see if you were correct.
If not, play with the examples. Add println statements to different parts of them to see what the values of the variables are at various stages in the execution. You'll learn a lot more about Java by doing this than by trying to remember answers given by other people here.

Then, if you're still having a hard time with a concept, you'll most likely have a much more specific question to ask. Maybe even a code example of your own that does a better job communicating your issue than the mock tests from a book or web site.

Glad you stuck around.
-Ben
Ivan Ivanic
Ranch Hand

Joined: Oct 31, 2007
Posts: 100
hey manny i totally understand you. in some other java forums people are really rude. but in my experience here i really saw that here every critic is justified. if you follow what this good men say, it will be much easier for you to get help. and it will be much easier for rest of us to help you.
i wish you to have a clear mind and when you come to your limits, you are always welcome to get some clarifications.
it is kinda tough to get used to this kind criticism, if you have bad experience from other forums, but in the end it will help you be a better java programmer. and of course to pass exam.
best luck.
Irina Goble
Ranch Hand

Joined: May 09, 2004
Posts: 91
Originally posted by Vishal Matere:
Answer 3 is correct. 297 is not valid value.

Could you please explain this? Compiling and running does not guaranteed that you get all the correct answers here. While some threads will increment i only 10 times, others might do that 11 times. So why is 297 not valid? Thank you.

[ April 29, 2008: Message edited by: Irina Goble ]

I missed the whole point. Thread.yield() does not release the lock!
[ April 29, 2008: Message edited by: Irina Goble ]
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
Originally posted by Irina Goble:


I missed the whole point. Thread.yield() does not release the lock!

[ April 29, 2008: Message edited by: Irina Goble ]


There you got it. However rather than simply running code, a good inspection of code itself will tell you that 297 is never possible.
vasu chowdary
Ranch Hand

Joined: Mar 15, 2008
Posts: 89
public synchronized void run()
{
}.....compile time error run method is not override.
you will better to write
public void run()
{
synchronized(this)
{
}
}
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

i am extremely sorry for the question i asked and my behavior

Welcome back


[My Blog]
All roads lead to JavaRanch
Vierda Mila
Ranch Hand

Joined: Feb 25, 2008
Posts: 61
Dear Manny,

click this

Hope it helps.


SCJP 5
Hussam Odeh
Ranch Hand

Joined: Jul 03, 2007
Posts: 55
Originally posted by vaasu balu:
public synchronized void run()
{
}.....compile time error run method is not override.
you will better to write
public void run()
{
synchronized(this)
{
}
}


Dear Vaasu,

The following code:

public synchronized void run()
{
}

will compile successfully and it is equivalent to the following code:

public void run()
{
synchronized(this)
{
}
}

Please check it to make sure.
[ May 01, 2008: Message edited by: Hussam Odeh ]

SCJA 1.0: 98%, SCJP 5.0: 97%, SCWCD 5.0: 100%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in threads(sun accesibility test)