Thursday, 3 January 2008

.NET Interview Questions (1)

Scott Hanselman has a popular list of "What Great .NET Developers Ought To Know" questions that have many answers on the Internet. I collected these answers and organized them with some of my own words. This post is the first part.


Everyone who writes code


  • Describe the difference between a Thread and a Process?
    A Process is a block of executable program bounded by its virtual address space. A Thread is a part of a process, it can only execute within the address space of a process. A process must have at lease one thread, or have multiple threads running simultaneously to improve efficiency. In .Net classes under System.Threading namespace are mainly used for multi-threading and asynchronous programming.

  • What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
    A Windows Service is an application running in the background without a visual user interface. Typically a Windows Service is started by Windows automatically when the system is started, or started manually through Control Panel->Services shortcut. A standard exe application is started and closed by a login user, and has a user interface to respond user interaction events. A Windows Service must be installed in order to run. A Windows Service runs in its own security context with a specific user account. A standard application runs under the security context of current login user.

  • What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?
    In a 32-bit system, the maximum memory available is 232 = 4GB. Because the operating system takes up 50% of available memory, a single process can only take maximum 2GB.
    This memory limitation affect those applications take large amount of memory like database management servers. To have more memory available for applications, we can set /3GB switch to the system start up line in c:\boot.ini file.

  • What is the difference between an EXE and a DLL?
    An EXE file has an entry point (in C# is main() function) and can run independently by itself, a DLL contains functions and can only be loaded within an EXE.

  • What is strong-typing versus weak-typing? Which is preferred? Why?
    A strong type checks object type at compile time. A weak type checks object type at run time. For example, Person p = new Person(); p is a strong type. Object o = new Person(); o is a weak type.
    Strong types can reduce bugs at run time. Weak types are more flexible to program. The preference is dependent on the type of application. For quick and small jobs like VBScript, weak-typing is preferred because it’s quicker to write code. For large projects strong-typing is preferred because most errors can be trapped at compile time.

  • Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.
    A container is a class implement System.ComponentModel.IContainer interface, and can hold controls. Three containers are: System.Web.UI.Page, System.Windows.Forms.Form and System.ComponentModel.Container.

  • What is a PID? How is it useful when troubleshooting a system?
    PID is process ID. It’s an integer to identity a process running in the operating system. It can be used to identify a process, start and kill a process in a multi-tasking system for troubleshooting. Also in Visual Studio .NET, a process running in the operating system can be attached to the debugger to debug into the process.

  • How many processes can listen on a single TCP/IP port?
    Only one.

  • What is the GAC? What problem does it solve?
    A GAC stands for global assembly cache. It’s a machine-wide code cache. An assembly deployed in GAC has a strong name, which contains a digital signature, publisher information, version number and culture information.
    It solves “DLL Hell” problem.


  • What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

    The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.


  • Explain ACID rule of thumb for transactions.

    A transaction must be:
    1. Atomic - it is one unit of work and does not dependent on previous and following transactions.
    2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
    3. Isolated - no transaction sees the intermediate results of the current transaction).
    4. Durable - the values persist if the data had been committed even if the system crashes right after.

No comments: