General discussion

Locked

Naren Cool Geek - Tips on .NET and Java development.

By narendrn ·
Tags: Off Topic
blog root

This conversation is currently closed to new comments.

320 total posts (Page 1 of 32)   01 | 02 | 03 | 04 | 05   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

C# delegates Vs Java Listeners

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">When I was first introduced to delegates, I found it quite confusing compared to the Java Listener concept. As we know, Java Listeneres use the classic Command design pattern to implement call-backs (implement a standard interface and the method e.g. OnMouseClick())<br />
<br />But after understanding delegates, I have realised that delegates are a bit more flexible than Java Listeners. By using a delegate, U are free to use any method of any object- just the signature of the method should match.<br />They allow easy binding of event handlers and other callback mechanisms, without the use of a separate class implementing a specific listener interface (which is the Java approach for callbacks).<br />Basically, instead passing a callback function via an object of known interface that both communicating parties agree on, delegates only need the two parties to use the same function signature<br />
<br />An interesting article regarding this can be found at:<br />
<a href="http://blog.monstuff.com/archives/000037.html#more">http://blog.monstuff.com/archives/000037.html#more</a>
</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/c-delegates-vs-java-listeners.html">This post originally appeared on an external website</a></div>

Collapse -

What's the difference between the 'out' and the 'ref' parameters in .NET?

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">A variable passed as an out argument need not be initialized. However, the out parameter must be assigned a value before the method returns.<br />
<br />An argument passed to a ref parameter must first be initialized. Compare this to an 'out ' parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.<br />
<br />Now the big question is why did Microsoft go thru the pain of having both 'ref' and 'out' ?<br />
<br />The answer is in the snippet below:<br />
<br />
<p>The two parameter passing modes addressed by out and ref are subtly different, however they are both very common. The subtle difference between these modes leads to some very common programming errors. </p>
<p>These include:<br />not assigning a value to an out parameter in all control flow paths<br />not assigning a value to variable which is used as a ref parameter </p>
<p>Because the C# language assigns different definite assignment rules to these different parameter passing modes, these common coding errors are caught by the compiler as being incorrect C# code.<br />The crux of the decision to include both ref and out parameter passing modes was that allowing the compiler to detect these common coding errors was worth the additional complexity of having both ref and out parameter passing modes in the language.</p>
</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/whats-difference-between-out-and-ref.html">This post originally appeared on an external website</a></div>

Collapse -

Asynchronous programming in .NET

by narendrn In reply to Naren Cool Geek - Tips on ...

The .NET API makes asynchronous programming a breeze....<br />U can make a async call to any method and what amazed me was the simplicity !!!<br /><br />We just have to make use of the magic of delegates...<br />Define a delegate with the same signature as the method you want to call; the common language runtime automatically defines BeginInvoke and EndInvoke methods for this delegate, with the appropriate signatures.<br />The BeginInvoke method is used to initiate the asynchronous call. It has the same parameters as the method you want to execute asynchronously, plus two additional parameters that will be described later. BeginInvoke returns immediately and does not wait for the asynchronous call to complete. BeginInvoke returns an IasyncResult, which can be used to monitor the progress of the call.<br />The EndInvoke method is used to retrieve the results of the asynchronous call. It can be called any time after BeginInvoke; if the asynchronous call has not completed, EndInvoke will block until it completes. The parameters of EndInvoke include the out and ref parameters (<out> ByRef and ByRef in Visual Basic) of the method you want to execute asynchronously, plus the IAsyncResult returned by BeginInvoke.<br /><br />So after making a Async call, we have the following options:<br /><ol><li>Do something and then block till the call completes.</li><li>Poll continously to see it call is complete</li><li>Assign a call-back delegate (AsyncCallBack) </li></ol><p>I found this feature of .NET really really cool...especially in my threading applications.</p><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/asynchronous-programming-in-net.html">This post originally appeared on an external website</a></div>

Collapse -

What is a race condition? How is it different from a dead-lock?

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">A race condition is a situation in which two or more threads or processes are reading or writing some shared data, and the final result depends on the timing of how the threads are scheduled. Race conditions can lead to unpredictable results and subtle program bugs<br />
<br />In Java, the Object class provides a collection of methods ? wait, notify, and notifyAll ? to help threads wait for a condition and notify other threads when that condition changes.</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/what-is-race-condition-how-is-it.html">This post originally appeared on an external website</a></div>

Collapse -

XSD.exe -- A cool tool in .NET SDK

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">While working on XML-driven applications I often used to dislike writing DTD or Schema files..The syntax was cryptic and difficult to remember.<br />
<br />In the .NET SDK, there is a cool tool called XSD.exe that can take a sample XML file and automatically generate a schema-definition file for it.<br />The following command generates an XML schema from myFile.xml and saves it to the specified<br />directory.<br />
<br />
<strong>xsd myFile.xml /outputdir:myOutputDir</strong>
</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/xsdexe-cool-tool-in-net-sdk.html">This post originally appeared on an external website</a></div>

Collapse -

Why wait() and notify() should be inside a synchronized block?

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">I always wondered why does the Java language mandate that wait() should be kept inside a synchronized block. (Especially bcoz wait() releases the lock of the object immediately)<br />
<br />This is required by the language, and ensures that wait and notify are properly serialized. In practical terms, this eliminates race conditions that could cause the "suspended" thread to miss a notify and remain suspended indefinitely.</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/why-wait-and-notify-should-be-inside.html">This post originally appeared on an external website</a></div>

Collapse -

Simple way to wait in a program or stop a program from exiting.

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">We often require a main thread of a application to keep waiting (and not end).<br />For Console applications, we can just block with a Console.Read() method.<br />For other applications, we tend to write a infinite loop like -- while(true){}<br />But the above statement keeps on wasting a lot of computational cycles.<br />
<br />A much cleaner and cool approach would be :--<br />
<br />java.lang.Object sync = new java.lang.Object();<br />synchronized (sync) { sync.wait(); }</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/simple-way-to-wait-in-program-or-stop.html">This post originally appeared on an external website</a></div>

Collapse -

Tutorials for networking concepts

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">Here are a couple of sites which have the best "audio-visual" tutorials (I have seen) on TCP/IP networking concepts. A must see..<br />
<br />
<a href="http://www.learntosubnet.com/">http://www.learntosubnet.com/</a>
<br />
<br />
<a href="http://www.learntcpip.com/TCPIP/default.htm">http://www.learntcpip.com/TCPIP/default.htm</a>
</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/tutorials-for-networking-concepts.html">This post originally appeared on an external website</a></div>

Collapse -

What is a MAC address?

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">I often was confused as to why a MAC address is required for a network node when we have a IP address. The MAC address is actually a hardware address that is assigned by the manufacturer and is gauranteed to be unique.<br />
<br />Basically the MAC address is used in the Data-link layer and the IP address is used in the Network layer. For e.g. Ethernet uses MAC address to find other hosts.<br />The ARP protocol does the mapping btw the MAC address and the IP address.</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/what-is-mac-address.html">This post originally appeared on an external website</a></div>

Collapse -

Themes in pluggable Look & Feel Swing

by narendrn In reply to Naren Cool Geek - Tips on ...

<div xmlns="http://www.w3.org/1999/xhtml">In addition to the pluggable look and feel UI Managers that Swing provides, each PLAF can also have various themes associated with it. These themes allow U to change some common properties such as 'font size', 'background color of a component' etc.<br />
<br />The abstract javax.swing.plaf.metal.MetalTheme class offers about fifty settings that let you customize the fonts and colors of the Swing components. By creating different subclasses, you can swap many of the properties at once when you change the look and feel.<br />
<br />MetalTheme theme = new MyCustomTheme();<br />MetalLookAndFeel.setCurrentTheme(theme);<br />UIManager.setLookAndFeel(new MetalLookAndFeel());<br />
<br />For an example of theme usage, try out the Metalworks demonstration that comes with the Java 2 SDK distribution. Simply change the current directory to the demo/jfc/Metalworks directory, and run the demonstration with the following command:<br />
<br /> java -jar Metalworks.jar</div><p><div class="blogdisclaim"><a href="http://narencoolgeek.blogspot.com/2005/06/themes-in-pluggable-look-feel-swing.html">This post originally appeared on an external website</a></div>

Back to After Hours Forum
320 total posts (Page 1 of 32)   01 | 02 | 03 | 04 | 05   Next

Related Discussions

Related Forums