Tuesday, May 31, 2005

What's the advantage of satellite assemblies over raw resource files?

Coming from a Java background, I always use to wonder why .NET converts ordinary resource files into satellite assemblies for internationalization.
Why not use the raw resource text files themselves..( as Java uses properties files)

I guess the most imp. advantage U get by converting resources to assemblies is that U can "version and digitally sign" them...i.e. U can give them a version number and also sign them with a private key. So there is a extra security that no one has tampered with the resource files.

What are modules (.netmodule files) in .NET? What is their use?

I have often wondered on the "real use" of modules and AL.exe in .NET.

The only use of AL.exe seems to be during i18N process, when we can create satellite assemblies. AL.exe is also useful if U need to link different .netmodules files into a single DLL. But we still need to ship the .netmodule files too along with the DLL !!!

An excellent article discussing this topic can be found at:
http://www.codenotes.com/cnp/baseAction.aspx?cnp=NET030009

Monday, May 30, 2005

The wonder of JavaCC !!!

I have been using JavaCC in a project for parsing Resource files. Anyone who has worked with Parsers before would just love the simplicity and power of JavaCC.

I would strongly recommend using JavaCC to generate any Java parser anyone would ever need. The following links would get U started :)

https://javacc.dev.java.net/

http://www.engr.mun.ca/~theo/JavaCC-FAQ/javacc-faq.htm

http://www.engr.mun.ca/~theo/JavaCC-Tutorial/ (An excellent tutorial for beginners)

Thursday, May 26, 2005

What's the differene between "setenv" and "export" commands in Unix/Linux?

Actually it depends on what shell U are using...i.e. C shell or Bourne Shell.

There are 2 types of variables:
  1. Shell variables -- That are local to the shell
  2. Environment variables -- That are available to all other processes

In C-shell to set a shell variable U type: % set name=value

In bourne shell you can just type: $NAME=value

In C-shell to set an environment variable: % setenv [NAME value]

In bourne shell, U need to export the shell variable, so U type: $ export NAME

A good article explaning the differences is present at:

http://sc.tamu.edu/help/general/unix/vars.html

What is double buffering technique in Graphics?

Double Buffering is a technique that is used to prevent flicker when drawing onto the screen. The problem stems from the fact that when a new animation frame is rendered, it is desirable to first clear the old frame. This causes a flicker to occur. The basic idea of double buffering is to create a virtual screen out of the user's view. A graphics device could be a screen, printer, file, or memory area. The virtual screen used as the buffer is the primary example of using a memory space as a graphics device. When paint() is called, the clearing and painting of the animation frame can occur on the virtual screen and the resulting rendered image can then be transferred to the real screen immediately upon completion. The cost of double buffering is in memory and CPU consumption. However, this cost is probably unavoidable for complex animations and usually isn't too expensive.

A very good tutorial on how to reduce flicker in Java GUI applications is given at:
http://javaboutique.internet.com/tutorials/
Java_Game_Programming/BildschirmflackernEng.html

Excerpt from the article:

Double buffering means to paint all the things in the paint() method to an offscreen image. If all things that have to be painted, are painted, this image is copied to the applet screen. The method does the following in detail:

  • Generates a new offscreen-image by using createImage and stores this image in a instance variable( = generate an empty image)
  • Call getGraphics to get graphic context for this image
  • Draw everything (including to clear the screen completely) on the offscreen image ( = draw image in the background)
  • When finished, copy this image over the existing image on the screen. ( = draw image in the foreground)

This technique means that the picture is already painted before it is copied to the screen. When copying the image to the foreground the old pixels are overlayed by the new ones. There won't be any flickering picture anymore because there is not a millisecond where you see an empty screen!

The only disadvantage of the double buffering is, that it produces a large amount of data and every image is drawn two times (offscreen and when copying to the screen). But in most cases and on a fast computer this is much better than wasting time on finding an other solution!

Wednesday, May 25, 2005

Dealing with Compound messages during i18n

A compound message contains variable data. In the following list of compound messages, the variable data is in bold:

The disk named MyDisk contains 300 files.
The current balance of account #34-98-222 is $2,745.72.
405,390 people have visited your website since January 1, 1998.
Delete all files older than 120 days.

Such messages are always difficult to localize. Just picking up sub-strings from the properties files won't work and would be very cumbersome. In Java, there is a cool class named "MessageFormat" that can be used in such cases. The following link contains the tutorial:
http://java.sun.com/

What is HTTP tunneling?

In most cases, network administrators will configure a firewall to only allow HTTP traffic on the default Web server port, 80. Traffic sent across an HTTP connection is considered relatively safe and, thus, HTTP has become the standard entry protocol to an internal network. Technologies such as SOAP have been designed to provide safe access through a firewall by using HTTP as the transport protocol.

HTTP tunneling is designed mainly for firewall aversion. HTTP tunneling performs protocol encapsulation, by enclosing data packets of one protocol (SOAP, JRMP, etc.) within HTTP Packets. The HTTP packets are then sent across the firewall as normal internet traffic.

SOAP is an excellent example of HTTP-Tunneling in the modern era of distributed computing.

The HTTP tunneling can be thought as a way to use an existing road of communication (HTTP) and create a subprotocol within it to perform specific tasks.
The subprotocol will contain all the information necessary to create an object on the Web Server, invoke the method on that object and return results back to the client.

Thursday, May 12, 2005

Number formatting...Really crazy !!!

During "i18n" tasks in my development career, I was amused to see how some locales have the formatting exactly opposite to that of US or UK.

For e.g.
In en_US locale, a number(currency) would look like $9,876,543.21 (separated by comma and a decimal)

But in German, the same number would be written as 9.876.543,21 DM (comma and decimal have opposite meaning !!!)

To furthur add to the confusion, in French, the amount would be written as 9 876 543,21 F (space and comma)

God save us poor mortal developers in understanding these nuances !!!

How to get localized objects in Java?

A lot of "i18N" programs only have to deal with "strings" that need to be localized. For e.g. labels, other text etc.
But what if U need a localized object ?..i.e a double object, a JPEG object etc.

There is a special class in Java "ListResourceBundle" that allows a ResourseBundle to be loaded from a ".class" file.
Read the tutorial below for more info :
http://java.sun.com/docs/books/tutorial/i18n/resbundle/list.html

Soft references, Weak References, Phantom references in Java !!!

The Reference API in Java can leave any sane person fully confused !!!..I tried to make sense of what the different types of references are and what purpose do they solve.
I am still not crystal clear about the usability of all these references, but I hope I will understand someday.

Referent
An object that is softly, weakly, or phantomly referenced from inside a SoftReference, WeakReference, or PhantomReference object, respectively.

Soft references:
The garbage collector might or might not reclaim a softly reachable object depending on how recently the object was created or accessed, but is required to clear all soft references before throwing an OutOfMemoryError.

Weakly reachable objects are finalized some time after their weak references have been cleared. The only real difference between a soft reference and a weak reference is that the garbage collector uses algorithms to decide whether or not to reclaim a softly reachable object, but always reclaims a weakly reachable object.

Phantomly reachable objects are objects that have been finalized, but not reclaimed.
The garbage collector will never clear a phantom reference. All phantom references must be explicitly cleared by the program.

An excellent article explaining GC in Java is given at
http://www.artima.com/insidejvm/ed2/gc17.html

Excerpts from the article:
--------------------------
Note that whereas the garbage collector enqueues soft and weak reference objects when their referents are leaving the relevant reachability state, it enqueues phantom references when the referents are entering the relevant state. You can also see this difference in that the garbage collector clears soft and weak reference objects before enqueueing them, but not phantom reference objects. Thus, the garbage collector enqueues soft reference objects to indicate their referents have just left the softly reachable state. Likewise, the garbage collector enqueues weak reference objects to indicate their referents have just left the weakly reachable state. But the garbage collector enqueues phantom reference objects to indicate their referents have entered the phantom reachable state. Phantom reachable objects will remain phantom reachable until their reference objects are explicitly cleared by the program.

The garbage collector treats soft, weak, and phantom objects differently because each is intended to provide a different kind of service to the program. Soft references enable you to create in-memory caches that are sensitive to the overall memory needs of the program. Weak references enable you to create canonicalizing mappings, such as a hash table whose keys and values will be removed from the map if they become otherwise unreferenced by the program. Phantom references enable you to establish more flexible pre-mortem cleanup policies than are possible with finalizers

To use the referent of a soft or weak reference, you invoke get() on the reference object. If the reference hasn't been cleared, you'll get a strong reference to the referent, which you can then use in the usual way. If the reference has been cleared, you'll get null back. If you invoke get() on a phantom reference object, however, you'll always get null back, even if the reference object hasn't yet been cleared. Because the phantom reachable state is only attained after an object passes through the resurrectable state, a phantom reference object provides no way to access to its referent. Invoking get() on a phantom reference object always returns null, even if the phantom reference hasn't yet been cleared, because if it returned a strong reference to the phantom reachable object, it would in effect resurrect the object. Thus, once an object reaches phantom reachability, it cannot be resurrected.

Virtual machine implementations are required to clear soft references before throwing OutOfMemoryError, but are otherwise free to decide when or whether to clear them. Implementations are encouraged, however, to clear soft references only when the programs demand for memory exceeds the supply, to clear older soft references before newer ones, and to clear soft references that haven't been used recently before soft references that have been used recently.

Soft references enable you to cache in memory data that you can more slowly retrieve from an external source, such as a file, database, or network. So long as the virtual machine has enough memory to fit the softly referenced data on the heap together with all the strongly referenced data, the soft reference will in general be strong enough to keep the softly referenced data on the heap. If memory becomes scarce, however, the garbage collector may decide to clear the soft references and reclaim the space occupied by the softly referenced data. The next time the program needs to use that data, it will have to be reloaded from the external source. In the mean time, the virtual machine has more room to accommodate the strongly (and other softly) referenced memory needs of the program.

Weak references are similar to soft references, except that whereas the garbage collector is free to decide whether or not to clear soft references to softly reachable objects, it must clear weak references to weakly reachable objects as soon as it determines the objects are weakly reachable. Weak references enable you to create canonicalizing mappings from keys to values. The java.util.WeakHashMap class uses weak references to provide just such a canonicalizing mapping. You can add key-value pairs to a WeakHashMap instance via the put() method, just like you can to an instance of any class that implements java.util.Map. But inside the WeakHashMap, the key objects are held via weak reference objects that are associated with a reference queue. If the garbage collector determines that a key object is weakly reachable, it will clear and enqueue any weak reference objects that refer to the key object. The next time the WeakHashMap is accessed, it will poll the reference queue and extract all weak reference objects that the garbage collector put there. The WeakHashMap will then remove from its mapping any key-value pairs for keys whose weak reference object showed up in the queue. Thus, if you add a key-value pair to a WeakHashMap, it will remain there so long as the program doesn't explicitly remove it with the remove() method and the garbage collector doesn't determine that the key object is weakly reachable.

Phantom reachability indicates that an object is ready for reclamation. When the garbage collector determines that the referent of a phantom reference object is phantom reachable, it appends the phantom reference object to its associated reference queue. (Unlike soft and weak reference objects, which can optionally be created without associating them with a reference queue, phantom reference objects cannot be instantiated without associating the reference object with a reference queue.) You can use the arrival of a phantom reference in a reference queue to trigger some action that you wish to take at the end of an object's lifetime. Because you can't get a strong reference to a phantom reachable object (the get() method always returns null), you won't be able to take any action that requires you to have access to the instance variables of the target. Once you have finished the pre-mortem cleanup actions for a phantom reachable object, you must invoke clear() on the phantom reference objects that refer to it. Invoking clear() on a phantom reference object is the coup de gras for its referent, sending the referent from the phantom reachable state to its final resting place: unreachability.

How GC works in Java?

The GC mechanisms in Java and .NET are the same with some minor differences. Read the following articles for more details:

http://www.javaworld.com/javaworld/jw-12-2001/jw-1207-java101.html

http://www.javaworld.com/javaworld/jw-01-2002/jw-0104-java101.html

http://www.javaworld.com/javaworld/jw-01-2002/jw-0104-java101guide.html

What are weak references in .NET?

Weak references reduce the memory pressure placed on the managed heap by large objects.
When a root points to an object, the object cannot be collected because the application's code can reach the object. When a root points to an object, it's called a strong reference to the object. However, the garbage collector also supports weak references. Weak references allow the garbage collector to collect the object, but they also allow the application to access the object.

------------------------------------------------------
Void Method() {
Object o = new Object(); // Creates a strong reference to the
// object.

// Create a strong reference to a short WeakReference object.
// The WeakReference object tracks the Object.
WeakReference wr = new WeakReference(o);

o = null; // Remove the strong reference to the object

o = wr.Target;
if (o == null) {
// A GC occurred and Object was reclaimed.
} else {
// a GC did not occur and we can successfully access the Object
// using o
}
}

---------------------------------------------
Once you've created a weak reference to an object, you usually set the strong reference to the object to null. If any strong reference remains, the garbage collector will be unable to collect the object.
To use the object again, you must turn the weak reference into a strong reference. You accomplish this simply by calling the WeakReference object's Target property and assigning the result to one of your application's roots. If the Target property returns null, then the object was collected. If the property does not return null, then the root is a strong reference to the object and the code may manipulate the object. As long as the strong reference exists, the object cannot be collected.

Note: It seems that "weak" references in .NET are equivalent to "soft" references in Java.

How GC works on .NET?

Two excellent articles on how Garbage Collection works in .NET.
A "MUST READ" for all .NET developers..

http://msdn.microsoft.com/msdnmag/
issues/1100/GCI/default.aspx

http://msdn.microsoft.com/msdnmag/
issues/1200/GCI2/default.aspx

Excerpt from the article:

How does the garbage collector know if the application is using an object or not?

As you might imagine, this isn't a simple question to answer.Every application has a set of roots. Roots identify storage locations, which refer to objects on the managed heap or to objects that are set to null. For example, all the global and static object pointers in an application are considered part of the application's roots. In addition, any local variable/parameter object pointers on a thread's stack are considered part of the application's roots. Finally, any CPU registers containing pointers to objects in the managed heap are also considered part of the application's roots. The list of active roots is maintained by the just-in-time (JIT) compiler and common language runtime, and is made accessible to the garbage collector's algorithm.

Now, the garbage collector starts walking the roots and building a graph of all objects reachable from the roots. For example, the garbage collector may locate a global variable that points to an object in the heap.

Once this part of the graph is complete, the garbage collector checks the next root and walks the objects again. As the garbage collector walks from object to object, if it attempts to add an object to the graph that it previously added, then the garbage collector can stop walking down that path. This serves two purposes. First, it helps performance significantly since it doesn't walk through a set of objects more than once. Second, it prevents infinite loops should you have any circular linked lists of objects.Once all the roots have been checked, the garbage collector's graph contains the set of all objects that are somehow reachable from the application's roots; any objects that are not in the graph are not accessible by the application, and are therefore considered garbage. The garbage collector now walks through the heap linearly, looking for contiguous blocks of garbage objects (now considered free space). The garbage collector then shifts the non-garbage objects down in memory (using the standard memcpy function that you've known for years), removing all of the gaps in the heap. Of course, moving the objects in memory invalidates all pointers to the objects. So the garbage collector must modify the application's roots so that the pointers point to the objects' new locations. In addition, if any object contains a pointer to another object, the garbage collector is responsible for correcting these pointers as well.

Wednesday, May 11, 2005

In .NET should we implement Finalize() or Dispose() method?

A type must implement Finalize() when it uses unmanaged resources such as file handles or database connections that must be released when the managed object that uses them is reclaimed.

But executing Finalize() has its performance bottlenecks. Read the below articles for more info.

http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx

http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx

Hence it is better if a Dispose() method is implemented and developers are encouraged to call Dispose() or Close(). We can always have Finalize() as a back-up in case the developer forgets to call Dispose(). For this we need to use the SuppressFinalize() method to prevent double execution of clean-up code.

GC class has a SuppressFinalize() method that can be called from the IDisposable.Dispose method to prevent the garbage collector from calling Object.Finalize on an object that does not require it.

Alternate .NET IDE's

While Microsoft Visual Studio .NET is the standard-bearer for .NET development, its hefty price tag and overwhelming features can often push developers away from it. Thankfully, a variety of alternative IDEs (Integrated Development Environment) are available. Here's a high-level view of these alternatives.

ASP.NET Web Matrix
Microsoft provides the freely available ASP.NET Web Matrix tool for developing ASP.NET-based applications. Microsoft describes it as a community-supported, easy-to-use WYSIWYG application development tool for ASP.NET. It includes database connectivity, Web services, mobile platform support, and support for multiple languages. It is supported on Windows 2000 and XP and Internet Explorer 5.5 or greater with the .NET Framework installed. Finally, it includes a development Web server so IIS is not required.

SharpDevelop
SharpDevelop is a freely available open source IDE built with the C# language. It provides a great example of what you can achieve with the .NET platform, but it doesn't restrict you to C#. It is similar to Visual Studio .NET in both appearance and features. It allows you to develop all types of applications including ASP.NET, Windows Forms, and console. At this time, it is only supported on the Windows platform.

PrimalCode
PrimalCode is a commercially available .NET IDE available from Sapien. The company describes it as an innovative .NET development environment, incorporating complete scripting and .NET development capability in a compact size that works with your existing hardware. PrimalCode includes two other Sapien tools: PrimalScript and PrimalDiff. In addition to .NET support, PrimalCode supports more than 30 languages including Perl, classic ASP, PHP, ColdFusion, VBScript, JSP, and WMI. Also, it includes a source code control system. It is available for the Windows platform with a trial download available. The download version is available for $249 USD.

Antechinus C# Editor
Antechinus C# Editor allows you to develop C# code including both Windows Forms and ASP.NET applications. It resembles Microsoft FrontPage, allowing you to publish an application to the appropriate Web location. It is integrated with the various tools installed with the .NET Framework, and it includes many features to make your life easier like bookmarking, documentation, color-coding, templates, and so forth. It is available for $49.95 USD for the Windows platform.

Eclipse
Eclipse is an open, extensible IDE framework developed by IBM. It was originally developed for the Java language. It is built on a mechanism for discovering, integrating, and running modules called plug-ins. That is, a tool provider writes a tool as a separate plug-in that operates on files in the workspace and surfaces its tool-specific user interface in the IDE. One such plug-in is the C# Plugin from Improve Technologies. It allows you to work with C# code, but the creation of C# projects or integrated development of ASP.NET or Windows Forms' applications is not supported. Both Eclipse and the Improve C# Plugin are freely available for Windows and Linux.

MonoDevelop
MonoDevelop is a freely available IDE for the Linux platform. It is connected with the Mono project. It is a simple IDE allowing development of C# code. It includes various Visual Studio .NET features like code completion, extensive help, class management, and an integrated debugger. It is still in the early stages of development so it will continue to add features, including support for building GUI interfaces. You should monitor its site to keep up with associated developments.

CodeWright
Borland has been an active member of the development tool community for many years, and they are an active participant in the continuing evolution of Eclipse as well. Its CodeWright tool is a powerful file editing system. It includes peer-to-peer connectivity for remote communication and file editing. Basically, I think of it as a text editor on steroids. It is available as a standalone tool as well as an add-in for Visual Studio .NET. The downside is that the CodeWright product is being discontinued so future support is still to be determined.

Architect or Developer

This eternal debate keeps coming up from time to time.
This time the debate was sparked by a article in Javaworld at http://www.javaworld.com/javaworld/jw-05-2005/jw-0509-architect.html

All the comments that were posted in response were very very interesting:
http://www.theserverside.com/news/thread.tss?thread_id=33809&News05_10_05-click
http://indicthreads.com/blogs/209/java_architect_developer.html

Also I was amused to hear what Martin Fowler of "ThoughtWorks" had to say about this topic.
http://www.martinfowler.com/ieeeSoftware/whoNeedsArchitect.pdf

In Agile methodologies, there is more focus on keeping components flexible and ready for change, hence the role of a architect also changes...Interesting read :)

Some really amusing comments are listed below : (who says developers do not have a good sense of humor)
  1. Of course there are organization where you have PowerPoint-architects who hide their ignorance and lack of actual knowledge behind stack loads of nice-looking high-level block-diagrams that do absolutely nothing and will never be looked upon a second time after they have been presented to the project board or whoever.
  2. Any of the following is much better definition of a (Java) architect :1. One who does not know how to start a java JVM. 2. One talks about UML all the times and present you a class diagram by copying from Gang of Four pattern book as his design.3. One who has never managed to write more than 100 lines of codes successfully.4. One who is the buddy of the VP of Engineering or CTO.

Some good Java interview questions

The following links have some good Java questions that one can expect in interviews:

http://java.sys-con.com/read/48839_2.htm

http://java.sys-con.com/read/46228.htm

Also interesting is some points given in the second link regarding the trouble is finding good Java developers today.

Tuesday, May 10, 2005

Microsoft has a Linux Lab !!!

I should have not been totally suprised by this news, as it is natural for a company to have some "competitive systems" where they can benchmark their products with the other products.

But it looks like MS is trying to play a different ball game. It "says" (believe it or not) that it wants to bridge the gap between the opensource community and MS. It's hard to say what MS strategy really is, but the truth is, today open-source software has become a force to reckon with !!!

http://www.microsoft-watch.com/article2/0,1995,1813672,00.asp

How does VMWare work?

Recently a few guys in my team were using a tool known as VMWare for simulating different operating systems on a single machine. Here's some info on how this is done:

VMWare hosts each guest operating system in a separate, secure virtual machine. Each virtual machine (VM) has its own virtual CPU, memory, disk, etc. and all of the virtual hardware is mapped to your computer's real hardware. Each virtual machine also comes complete with its own BIOS that can be edited the same way you'd edit the real BIOS on the computer that VMWare is running on. This lets you customize your virtual machines and control all of the usual stuff that you can control via your PC's actual BIOS.

http://www.extremetech.com/article2/0,1558,1628461,00.asp
www.vmware.com

Friday, May 06, 2005

What does 'foo' and 'bar' mean? Does anyone know the history.

Since college days, we have been seeing the words 'foo' and 'bar' in a hell lot of programs...So what do these variable names mean ?...

The following links provide some really amusing information:
http://www.catb.org/~esr/jargon/html/F/foo.html

http://kb.indiana.edu/data/aetq.html?cust=379462.50587.30

http://www.catb.org/~esr/jargon/html/F/foobar.html

Cool Cool Java Collections

With JDK 1.2, Sun introducted the Java Collection Framework, a cool API for data-structures in Java. At the base of the heirarchy were collection interfaces like:
List: A collection that is ordered and whose members can be accessed by index. A list can also contain duplicates and null values.
Set: A collection that is not ordered and hence there are no methods that allow to access members thru a index. Also a Set does not allow duplicates and atmost one null value.

Though I personally feel that the JDK Collection framework is quite comprehensive and should suffice most development needs, it is good to know about some other alternatives:
1) Jakarta Commons Collections - An open source initiative that contains some extra cool collections like MultiMap etc.
2) JGL (Java Generic Library) - A port of the C++ STL (Standard tag library) to the Java language. Thought I was first impressed by this package, I think this API would appleal more to those from the C++ background. Also the latest version is no longer free, I believe.

Thursday, May 05, 2005

Awt, Swing and SWT

AWT: The idea was to wrap the native GUI widgets of the various operating systems with a platform-independent Java API called Abstract Window Toolkit (AWT). Only common widgets such as text field, text area, check box, radio button, list, and push button were supported by AWT. The graphics and imaging features were also very limited. That was, at best, enough for building simple applets.

SWING: is one of the most complex GUI frameworks ever developed. It has a complete set of GUI components ranging from buttons and text fields to tables, trees, and styled text editors. These components do not rely on the native widgets of the operating system; instead, Swing components are painted using graphic primitives such as lines, rectangles, and text. The painting is delegated to a look and feel (L&F) plug-in that can imitate the native L&F. Swing also has a platform-independent L&F called "Metal." JBuilder, uses Swing, and its speed is quite good.

Standard Widget Toolkit (SWT) is the GUI toolkit developed by IBM for its Eclipse IDE. SWT can be used outside of the Eclipse environment and offers direct access to the native GUI features of the operating system. Therefore, SWT-based Java applications have native GUIs and can be integrated with other native applications and components. SWT delegates to native widgets for common components (such as labels, lists, tables, and so on) as AWT does, while emulating in Java more sophisticated components (for example, toolbars are emulated when running on Motif) similarly to Swing's strategy.SWT has been designed to be as inexpensive as possible. This means (among the other things) that it is native-oriented. Anyway, it differs from AWT in a number of details. SWT provides different Java implementations for each platform, and each of these implementations calls natively (through the Java Native Interface, JNI) the underlying native implementation. The old AWT is different in that all platform-dependent details are hidden in C (native) code and the Java implementation is the same for all the platforms.

Visual Studio locking dlls above 64kb

Visual Studio .NET has a very stupid problem...If Ur dotnet assembly size is above 64kb then Intellisense locks the dll and so the build fails.

Solutions for the problem are given at:
http://support.microsoft.com/kb/313512/EN-US/

How to join one row in a table with many related rows in the other table

Suppose I have a table as below:
Table Project
{
ProjectID int
Manager int (secondary key)
Architect int (secondary key)
Client int (secondary key)
}

Table Contact
{
ContactID int (primary key)
Name string
}

Now I want to show the Project table with names of Manager and Architect and the client.
A "join" or a "union" will not work...The solution is very simple:

select Project.ProjectID, a.FirstName as Manager, b.firstname as Architect, c.FirstName as Client from Project,
Contact a,
Contact b,
Contact c
where a.contact_id = project.manager and
b.contact_id = project.architect and
c.contact_id = project.client

A simple recursive function to get all files in all sub-dirs of a folder

The below code is in .NET C#

public ArrayList GetAllFiles(string directory)
{
 ArrayList totalFilesList = new ArrayList(10);
 string[] files = Directory.GetFiles(directory);//add all files in that current  folder.totalFilesList.AddRange(files);//Check if the current directory has sub-directories
 string[] subDirs = Directory.GetDirectories(directory);//if yes, then call recursive functions..
 if(subDirs.Length > 0)
  {//now look for all files in current folder's sub-dir's.
  foreach(string subDir in subDirs)
   {
   ArrayList tempArrayList = GetAllFiles(subDir);
   totalFilesList.AddRange(tempArrayList);
  }
 }
return totalFilesList;
}

Indexers in .NET

How can we write a customCollection object which behaves the same way as a ASP.NET session object or Application object, i.e. retrieve the values using indexes.

For e.g. we can retrieve a object from Session as :
object obj = Session["key"]; //to retrieve
Session["key"] = obj; //add or set a value in Session.

Writing our own Collection object which behaves in a similar manner is very simple, using Indexes in C #See code below:

class MyCollection
{
private Hashtable hashTable = new Hashtable();
public object this [object index]
{
get{return hashTable[index];} set{hashTable[index] = value;}
}
}

Now we can use MyCollection object as shown below:

MyCollection myCollection = new MyCollection();
myCollection["Naren"] = "Swetha";
Console.WriteLine("value >> " + myCollection["Naren"]);

That's it....

Difference between java 'null' and C sharp 'null'

In java, when you try to print a null reference, what do U get?

For e.g. Object obj = null;System.out.println(obj);

What gets printed is "null".

So basically a null reference when converted to a string results in "null".
But in Csharp, the same code will print a empty string

Object obj = null;
Console.WriteLine(obj);

Very imp difference for java developers learning C#

Another important difference is while Type-Casting or Boxing/UnBoxing as it is known in C#.Java does not allow us to cast a reference type to a primitive type.So the following code in Java would throw an compilation error:

boolean b = (boolean)getSomeObject();

Assume getSomeObject() method has the signature:
public object getSomeObject()

But in C#, it is possible to type-cast an reference type to an primitive. So the following code would not give a compilation error.

bool b = (bool)getSomeObject();

But at runtime, if getSomeObject() returns a 'null' , then we would get a 'NullReferenceException'
A 'null' can be type-casted to any object reference type, but not to a primitive type So in C#, we need to be very careful about this fact

DateTime class in .NET (localization)

In ASP.NET, web.config contains a tag.

<globalization culture="en-GB" requestencoding="utf-8" responseencoding="utf-8">

When the culture is "en-US" and we print a DateTime object, we get it in the format "mm/dd/yyyy" whereas if U change the culture to "en-GB" then the date.toString() would return a string in the format "dd/mm/yyyy".So our code cannot assume the date, month to be in a specific format for parsing. Very very imp tip for localisation !!!!

Transfer of technical blog

I used to maintain my technical blog at http://naren.tblog.com
But I found the "Blogger" site by google so user-friendly and cool that I am transferring my technical blogs to here.