This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in threads(sun accesibility test)

 
manny singh
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
manny singh
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry


BYE FORUM
 
Vishal Matere
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[BPS: Be nice]

[ April 29, 2008: Message edited by: Ben Souther ]
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
manny singh
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am extremely sorry for the question i asked and my behavior

Welcome back
 
Vierda Mila
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Manny,

click this

Hope it helps.
 
Hussam Odeh
Ranch Hand
Posts: 55
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic