Win a copy of Terraform in Action this week in the Cloud forum!

Jimmy Thomas

Greenhorn
+ Follow
since Aug 17, 2005
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jimmy Thomas

Hi,

What's an international voucher mean??

Is it Ok if I buy an International voucher from India and later give my exam in a different country???

I did enquire in one of the centers back in India and they are saying that, if you buy an voucher you are allowed to take the certification in that country only... is this true!!

Thanks
Hi,

I would like to know whether any of you are aware of any voucher promotions/discounts going on currently in Bangalore. I plan to take the exam in the coming month.

Thanks
The Thread implements Runnable so it use the constructor

Thread(Runnable target)

Option B is correct
Is Anyone Having a explanation to this??



The reason is to avoid the possible problem of deadlocks. What option B ensures is that the order of locking remains the same.
Anish,
I do get an Exception...

Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at threads.JoinTest.main(JoinTest.java:20)
Sandy,

Try this


Output:
----------------------------------
-1
2147483647
-1
1111111111111111111111111111111
11111111111111111111111111111111
2147483647

I guess this should explain... narrow conversion.
[ September 16, 2005: Message edited by: Jimmy Thomas ]
There change in implementation between the JDKs (1.5 & 1.4), in JDK 5 the insert method call gets delegated to the insert() of AbstractStringBuilder class. This is not a public class & I couldn't find the docs for the same.

Prior to JDK 5 the insert method functionality was handled by the StringBuffer class itself.

I guess this is the cause for the different outputs that we're getting...
[ September 16, 2005: Message edited by: Jimmy Thomas ]
Sangeeta,

I tried the same program on Linux (JDK 1.4.2) $ I got the same that you've pointed out ababcdcd . I suspect there's some change in Implementation between the two version of JDK or due to the platform difference.

Could you tell me on what platform/JDK did you test ???

Can you explain the element 3 and element 4. i have a doubt as why it agian inserts the char a in element 3 and char b in element 4.



The key is the array we're reading from & inserting to are the same. So the 3rd element will the element that's inserted in the first loop & similarly for the 4th element.
This is the output that I got: abababcd
Tested on Win2k - Java 5 version.

First of all we must remember that the StringBuffer ultimately uses a Char array to store the contents of the string. Since we're using the same buffer object to do the insert, we're modifying the contents of the underlying array inturn. This is what is actually happening...

StringBuffer sb = new StringBuffer("abcd");

The above line creates a Char array containing {'a','b','c','d'}

sb.insert(2,sb);

Now are trying to insert at index two of the above created array, the point to note is that both the source & destination is the same char array. Initially the array len=4, during copy this what happens..

element 1 --> {'a','b','a','c','d'}
element 2 --> {'a','b','a','b','c','d'}
element 3 --> {'a','b','a','b','a','c','d'}
element 4 --> {'a','b','a','b','a','b','c','d'}
[ September 16, 2005: Message edited by: Jimmy Thomas ]
Harish,

Static methods are invoked always on the reference type on which the call is made. Having said that, in your example 2, the call
new Q().printS1S2();, results in invoking the method declared in the base class.

Since the method definition of printS1S2 is,
Is it a good practice to call super.run() when we override the run() method of a Thread sub-class. The behaviour that I've noticed is that if we create a new subclassed Thread object using a Runnable object, then the run method will also get invoked for the Runnable object along with the Thread's run method sequentially.

This is how the code in java.lang.Thread class works, it calls the target's, i.e. the Runnable's run method.



The below code exhibits this scenario..


Output:
----------------------------------------------
Creating & starting new Thread
Creating & starting new Thread, with MyRun
MyRun.run()... Sleeping
Woke up
Creating & starting new MyThread
MyThread.run()
123
Creating & starting new MyThread, with MyRun
MyRun.run()... Sleeping
Woke up
MyThread.run()
123
----------------------------------------------
Hi Ritu,

In Java arrays are Objects, so when you call the method m1(int[] i4, int[] i5), the copy of the reference to these array objects are passed. Though you're manipulating the references inside the method it's valid only within the scope of the method m1(), once this method returns the array references are the same as before the call to method m1 is made.
Hi Marcus,

It's always a pleasure to help you guys out.

Do the questions on your free mock exams get randomly selected out of 320 questions or are they a fixed set of 60 questions??

Regards,
Jimmy
Hi Ranchers,

First of all I have to thank all the members of this site for its incredible support to Java developers world wide.

Now that Java 5 has got a major language makeover using Generics, I feel that this site should start a new forum specifically for Generics only. This would help people like me, in understanding/querying about this feature more in depth. As of now I haven�t come across too many places where one can look for learning Generics, though I found a particular site that is pretty good & has some real meat Angelika Langer - Generics FAQs.

Thanks,
Jimmy
16 years ago
Thanks Nathaniel & Barry, I had chosen option two & got it wrong...

This question is from Marcus Green's examulator, Question Bank Id:713.

-- Jimmy