Agility eLetter May 2005

In this issue...

In this issue, we have a detailed article on Generics in Java: Part-III.

Abstract: In Part-I and II we discussed the benefits and usage of Java Generics, and how it is implemented under the hood. In this Part-III, we conclude with discussions on issues with mixing generic and non-generic (raw-type) code, and the issues of converting a non-generic legacy code to generics. Please visit http://www.agiledeveloper.com/download.aspx to download the complete article from the Agile Developer web site.

Message from us

We are excited to announce the release of .NET Gotchas. Please click on the picture for more detatils. If you get a chance to read, we will be delighted to hear your comments and constructive criticisms.

 

If you would like any question to be addressed or topic to be discussed, please send us an email at agility@agiledeveloper.com. We love to hear from you.

 

Please send suggestions, corrections and comments to agility@agiledeveloper.com

Quiz corner

This month’s quiz has double dip bonus. The person with first correct response will earn two special prizes! Let's see who the lucky, err, I mean, smart winner is!
I have a web service at http://www.agiledeveloper.com/venkat/wsmay2005/Service1.asmx. The service’s GetInfo() method simply returns a random number after a 2 seconds delay. Here is the C# code I use to talk to that web service (Thanks to Brandt for leading me into this trap on his project earlier this year
J):
using System;

 

namespace CallWS

{

      class Test

      {

            static void CallService()

            {

                  wsmay2005.Service1 service =

                           new CallWS.wsmay2005.Service1();

                  int start = Environment.TickCount;

                  service.GetInfo();

                  int end = Environment.TickCount;

                  Console.WriteLine("Time elapsed {0}",

                                          (end - start)/1000);

            }

 

            static void CallServiceAsynch()

            {

                  wsmay2005.Service1 service =

                          new CallWS.wsmay2005.Service1();

                  int start = Environment.TickCount;

                  service.BeginGetInfo(

                        new AsyncCallback(CallReturned), start);

            }

 

            static void CallReturned(IAsyncResult ar)

            {

                  int end = Environment.TickCount;

                  int start = (int) ar.AsyncState;

                  Console.WriteLine("Time elapsed {0}",

                                           (end - start)/1000);

            }

 

            [STAThread]

            static void Main(string[] args)

            {

                  Console.WriteLine("Making two synchronous calls");

                  CallService();               

                  CallService();

 

                  Console.WriteLine("Making four asynchronous calls");

                  CallServiceAsynch();

                  CallServiceAsynch();

                  CallServiceAsynch();

                  CallServiceAsynch();

 

                  Console.ReadLine();

            }

      }

}


The output I get is:

Making two synchronous calls

Time elapsed 2

Time elapsed 2

Making four asynchronous calls

Time elapsed 2

Time elapsed 2

Time elapsed 4

Time elapsed 4

 

Fix the above code (minimum change) so I get the following output:

Making two synchronous calls

Time elapsed 2

Time elapsed 2

Making four asynchronous calls

Time elapsed 2

Time elapsed 2

Time elapsed 2

Time elapsed 2

There should still be two synchronous calls and four asynchronous calls. Send in your response and if your response is the first correct response, you will be the winner of the double dip bonus!

Send your response to agility@agiledeveloper.com. This year, each person with the first correct response to the quiz in each issue of Agility will win a special prize.

Quiz from the past issue

In Java 5, the technique of ____ replaces parameterized type with a type during compilation.

Answer!

It’s erasure. Puneet earned the April Agility Special Prize by sending the first correct response.

Subscription Information

To subscribe or unsubscribe to the free issues of Agility eLetter, please visit http://www.agiledeveloper.com/eLetter.aspx.

Thus spake...

"A life spent making mistakes is not only more honorable but more useful than a life spent doing nothing," George Bernard Shaw.