Tuesday, July 03, 2007

.net interview questions and answers - Mid level

(Source of Question: http://www.hanselman.com/)

  • Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.


  • This question really ends up being: Give definition of each. And this has not much too do with .Net.

    Interface-oriented: Interfaces are used in distributed applications. In such applications the client (caller) and server (callee)
    are two separate class implementations and client wants to call functions defined within server class. For that both have to
    agree on a particular contract - defining class - that lists what functions are available and what is the signature of each.
    The class that declares this contract is Interface. The advantage is that the implementation class (server class) can reside in
    separate assembly or separate machine. And the definition of server class can change - the implementation of each method can change.
    But as long as the contract/interface remains same the client is not affected.


    Object-Oriented: Anyone who comes to .Net world must know this. And next generation will be borned with this knowledge. So no point
    in repeating. The point to note is that Interface-oriented programming needs object-oriented programming. OOP is a global umbrella
    under which other programming like Interface-oriented resides.


    Aspect-Oriented: Well I heard this term recently but haven't dealt with it much. MSDN forum I read (Christian Liensberger)
    says this: Aspect-oriented
    programming is a way to trace information and do certain things when triggers fire. For example you can do very easy logging in an
    aspect-oriented environment. You can specify in a trigger that each time when a method is called another method gets called first.
    That one gets the arguments that are passed in the method. You can now log these arguments. Same could also happen when a method is
    left... There are many other scenarios where aspect-oriented programming could help.


    Good Article on Wikipedia: http://en.wikipedia.org/wiki/Aspect-oriented_programming

  • Describe what an Interface is and how it’s different from a Class.


  • Interface is kind of a prototype of the class definition. It contains declaration for methods and
    properties available within a class. The class containing actual implementation of these methods and properties is
    called Implementation.

    A class contains definition of methods, properties and declares member varaibles while Interface only declares the
    methods and properties.


  • What is Reflection?

  • Reflection is a mechanism to access class information (meta data) at run time.
    Using Reflection one can create objects, understand the definition of classes, its member varaibles,
    its properties and its methods. It can dynamically invoke methods.


  • What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?

  • .Net Remoting works purely using Common Type System. Its not an open standard.

    Refer to Link http://www.csharphelp.com/archives2/archive460.html


  • Are the type system represented by XmlSchema and the CLS isomorphic?

  • Good answer here: http://voltinsider.com/?p=64.

    In short, XmlSchema has types like xs:Boolean, xs:int, xs:decimal, xs:Date etc.

    CLS (Common Language System) has data types like: int, Int32, double, char, boolean etc.

    Isomorphism means having similar appearance or one-to-one relation.

    XmlSchema and CLS has similar data types. They have almost one-to-one mapping of data types.


  • Conceptually, what is the difference between early-binding and late-binding?

  • Microsoft has a article regarding this: http://support.microsoft.com/default.aspx?scid=kb;en-us;245115

    In Short, Binding is a process through which the method calls are matched to the actual code that
    implements those methods. In early binding, the calls are bound at the compile time. i.e. programmer
    has to know which code is being executed while calling a particular function.

    In Late Binding, programmer does not know which code will execute at run time. The run-time will
    bind an object that is created at runtime to the function call and executes the relevant code
    within that object. Generally the classes that implement IDispatch can be late bound.
    The client creates an object of a generic type (Object a = Server.CreateObject("")).
    And then a method call on this object for a specific type will be late bound through IDispatch Invoke.


  • Is using Assembly.Load a static reference or dynamic reference?


  • While running your .net application, .Net Runtime loads the assemblies referenced by your application. The reference
    to assemblies can be either static or dynamic. Static refenrence means the reference is found in the assembly manifest.
    When compiler builds the application, it puts static references in the assembly manifest's meta data.


    But if application calls System.Reflection.Assembly.Load("assemblyName") - such references are considered dynamic references.
    System.AppDomain.Load() also makes a dynamic (partial) reference to assembly.

    Read MSDN Article: http://msdn2.microsoft.com/en-us/library/yx7xezcf(VS.80).aspx

  • When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?


  • LoadFrom:

    • If an assembly with the same identity is already loaded, LoadFrom will not load it again even the path is different.

    • It resolves the dependies using the load path.


    LoadFile:

    • It can be used to load two different assemblies from different path having the same identity.

    • It does not resolve dependies using the load path.



  • What is an Asssembly Qualified Name? Is it a filename? How is it different?


  • Assembly Qualified name contains: Assembly Name, Version, Culture, Public Key

    The fully qualified name is used to locate the assembly and differentiate it from other assembly with the same name.
    It's not a file name because it has version, culture and public key.

    Example: myAssembly, Version=1.0.1234.0, Culture=en-US, PublicKeyToken=b77a5c561934e089c, ProcessorArchitecture=msil

    Read MSDN article here: http://msdn2.microsoft.com/en-us/library/k8xx4k69.aspx

  • Is this valid? Assembly.Load("foo.dll");


  • No. Assembly.Load() takes Assembly Name as the parameter and not the file name.

    Use Assembly.LoadFrom() or Assembly.LoadFile() to load it from file.

  • How is a strongly-named assembly different from one that isn’t strongly-named?

  • An assembly identity is: Name, Version, Culture, Public Key

    Strongly-named assembly identity is: Name, Version, Culture, Public Key and Digital Signature.

    Only Strongly-named assemblies can reside in GAC. A strongly-named assembly can only reference
    other strongly-named assemblies.


  • Can DateTimes be null?

  • No! Stupid - this is not mid-level question. Its entry level question.


  • What is the JIT? What is NGEN? What are limitations and benefits of each?

  • JIT - Just in Time compiler. This is part of .Net runtime. It compiles the
    IL code into machine executable code at runtime. This is also called "Jitter".
    Limitation of JIT is that the code it generates is not stored/cached anywhere
    hence when the same code needs to be executed again, it is regenerated by JIT.
    Hence, JIT is slow.

    NGEN - is a native image generator for .Net code. NGEN needs the IL code as
    input and it generate the native image at specific place. Benefit of
    NGEN is that it stores the native code so that it does not have to
    be regenerated by JIT everytime its needed. Hence, NGEN code is
    faster.

    Read this article for more details on NGEN: http://visualbasic.about.com/od/usingvbnet/a/FWTools2.htm

    Here is MSDN article on NGEN 2.0: http://msdn.microsoft.com/msdnmag/issues/05/04/NGen/default.aspx#S1

    According to MSDN article, the limitation of NGEN 1.0 was that it was
    fragile. If any of the dependencies of current assembly changes, for example,
    system.dll changes, then the NGEN generated code become invalid and JIT again
    uses the IL code.


  • How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?

  • .Net allocates objects on a memory (managed) heap. For each running application, .Net maintains a set of Application Roots. The Roots
    point to storage locations on the managed heap.


    Garbage collector traverses all the objects in managed heap through Application Root. If one object points to another, then that object
    is considered reachable. At the end it prepares list of unreachable objects. Then it compacts memory by combining all reachable objects
    and freeing up memory used by unreachable objects.


    Garbage collector divides the objects in three generations: 0, 1 and 2. You could say these are iterations. In the first iteration
    (Generation 0) it finds all the reachable and unreachable objects. All reachable objects are promoted to Generation 1. Now, if the
    freed-up memory in first iteration (generation 0 unreachable objects) is not enough to allocate then only the next iteration takes place.

  • What is the difference between Finalize() and Dispose()?

  • Dispose method is called by the user while Finalize() method is called by the Garbage Collector
    automatically when the object is to be destroyed.


  • How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?

  • using() pattern calls the Dispose() method for the object used with it. The class used in using() must implement
    IDisposable interface and must have Dispose() method.

    E.g. using(MyClass objClass = new MyClass()) { }

    Here the MyClass must implement IDisposable. When the execution reaches '}' it calls Dispose() method of the objClass object.


  • What does this useful command line do? tasklist /m "mscor*"


  • This lists the processes running on the local machine that uses mscor*.dll.

  • What is the difference between in-proc and out-of-proc?

  • COM servers implemented in DLL are in-proc COM servers and those implementd in EXE are out-of-proc.

    Refer this great article on COM Interop: http://www.codeproject.com/useritems/BuildCOMServersInDotNet.asp
  • What technology enables out-of-proc communication in .NET?


  • When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

.net interview questions and answers - everyone who writes code

Here I am trying to compile some questions from many bloggers and provide answers to what I can. Even though this questions are asked in interview or not, I felt they are important for someone to know to do their job better.

(Source of Questions: Scott Hanselman and other blogs listed in my previous post).

Everyone who writes code

  1. What is the difference between an EXE and a DLL?
    An EXE is an executable program by itself. The Operating system can load the instructions from EXE file and run it as a stand alone application. While a DLL is a Dynamic Link Library file that contains binary routines that other executable programs can load while they are run.

    P.S. this has nothing to do with .net.
  2. What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
    Windows Service is type of a cron job in Unix. Windows Service runs in the background and stays in the machine memory until it is unloaded. Windows Service can generate events for itself (e.g. time based events, or file operation based events, network port based events etc.) and then kick off when the event occurs - process the event and then go back to wait for next event. IIS (W3Svc) is such a windows service.
    EXE is generally user invoked program and runs in foreground.

    P.S. This has nothing to do with .Net.

  3. What is the GAC? What problem does it solve?
    Global Assembly Cache. When a .Net program (or class files) run they use many functions available in other DLLs. GAC stores all these common (system) DLLs so that they don't have to be loaded everytime a program runs. One can add or remove DLLs in the GAC.
  4. Describe the difference between a Thread and a Process?
    Process is a module or a program that operating system allocates memory and cpu for its execution. Process has its own space. Now, a process may want to do parallel processing within itself to perform a specific task. E.g. check spelling while user is typing. Different parallel execution units within a process are called threads. A process contain one or more threads. And each thread belongs to one process. In Windows Task manager one can see all the processes that are currently running.

    P.S. This has nothing to do with .Net.
  5. What is a PID? How is it useful when troubleshooting a system?

  6. PID is Process Id. It helps in debugging. Generally each system should log the errors with the PID so looking at log file one can find out what events caused a particular error. Many of the tracing tools display PID.

    P.S. This has nothing to do with .Net.


  7. What is strong-typing versus weak-typing? Which is preferred? Why?


  8. Strong Typing means each of the object in the program has its type and type-casting is not used to cast object of one type to another. This way compiler will generate errors if an object of one type is being assinged to object of another type. This reduces run time errors.

    Weak typing is where objects are dynamically created of a specific type and then assigned to objects of their base class types. Objects may change their type at the Run time. Compiler does not catch if there are any errors in assignments or comparison or any such operations on weakly typed objects.

    What is preferable - depends entirely on the need. Though its common to avoid weak-typing unless you know what you are doing.

    P.S. Again, this is not too much related to .net as such. This is common programming concept.

  9. 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?

  10. Rather than reproducing this answer here is a link: Dotnet Doc Link
    In short, maximum 4 GB memory but 2 GB for OS and 2 GB for process.

  11. Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.


  12. I did not knew about this one earlier. So, here is a link to someone's answer:
    Dotnet Doc Link

    What that says in nutshell is- Component is the class that implements IComponent. Container is a class that implments IContainer and Container will contain the components.

  13. How many processes can listen on a single TCP/IP port?
  14. As far as I know, ONE.

  15. Can DateTimes be null?
    No. You can use DateTime.MinValue if needed.
  16. Is string a value type or a reference type?
  17. reference type.
  18. What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
  19. Debug build will contain all the debug information that helps in debugging a program e.g. PDB files. Release mode does not contain any extra information. Some solutions may use compiler directives to execute different codes in DEBUG mode and in RELEASE mode.

    There could be speed difference depending upon the size of the project. Its never a good idea to use DEBUG version in production environment.

Monday, July 02, 2007

.Net Questions

This site has a great set of questions for .Net Interview for all beginner, mid or senior level .net developers.


Scott Hanselman's .Net Questions


Here are some fun + technical questions asked during MS interview:

http://www.sellsbrothers.com/fun/msiview/

Here are some questions and answers:
http://blogs.crsw.com/mark/articles/254.aspx

Some C# interview questions with answers:

http://www.kyapoocha.com/category/c-sharp-interview-questions/

Some questions that has not really much to do with .Net but check them out:
http://www.niallkennedy.com/about/questions.html

And how can I forget this link:
Coding Architect's thoughts on questions

Here is first such attempt to list down questions but there is big discussion here that is more important than those questions:
http://getahead.org/blog/joe/2006/03/01/1141219345542.html