aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exercise 9-2(page 738)Sun certified programmer for Java6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exercise 9-2(page 738)Sun certified programmer for Java6"Study Guide"" Watch "Exercise 9-2(page 738)Sun certified programmer for Java6"Study Guide"" New topic
Author

Exercise 9-2(page 738)Sun certified programmer for Java6"Study Guide"

Manos Kolias
Greenhorn

Joined: Dec 08, 2009
Posts: 9
This exerscise is to attempt synchronizing a block of code.
The steps we should take are:
1.Create a class and extend the Thread class. //ok so far.
2.Override the run() method of Thread. ect... //ok again.
3. For our three thread objects to share the same object,we will need to create a constructor that accepts a StringBuffer object in the argument. //HOW CAN WE DO THIS???

Does anyone can help me on this topic?
Thanks anyway.
Manos.
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Manos Kolias wrote:This exerscise is to attempt synchronizing a block of code.
3. For our three thread objects to share the same object,we will need to create a constructor that accepts a StringBuffer object in the argument. //HOW CAN WE DO THIS???


Manos Kolias
Greenhorn

Joined: Dec 08, 2009
Posts: 9
Thank you .
Manos Kolias
Greenhorn

Joined: Dec 08, 2009
Posts: 9
Hello again.
I can not understand this exercise !!
I didn't find a method that can increment a letter in the StringBuffer class.
Can you please help me with some details ? All the methods try to append or insert something .
I m in great confusion and that confusion isn't about synchronizing a block of code rather than messing up with StringBuffer class!!

public class Test extends Thread{
private StringBuffer letter ;
public Test(){
letter = null;
}
public Test(StringBuffer sb){
letter = sb;
}
public StringBuffer getLetter(){
return letter ;
}
public void run()
{
for(int i=0;i<100;i++)
{synchronized(this){System.out.println(letter );}

}

}

}
Here is some of my thoughts.
I m expecting for your help .Thanks in advance.
Manos.
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
i think you are talking about the 9-2 exercise in the book in which we have to print AAA....BBBB...CCCCc

s.charAt(0) gives you the character at idnex position 0...you can incremeent it using ++...after incrementing it you can use s.setCharAt(0,char c)......

i hope this clears your doubt....try it yourself..else i will send you my code


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Manos Kolias
Greenhorn

Joined: Dec 08, 2009
Posts: 9
i'm ok .Thanks a lot.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exercise 9-2(page 738)Sun certified programmer for Java6"Study Guide"
 
Similar Threads
Array Reference Assignments for Multidimensional Arrays
Will a started thread run to completion in this example?
Security in Message Broker Product Level
HttpServletRequest and response
Wrappers & Subclasses