csharp-interview-3(entry, mid level)

Card Set Information

Author:
sabond
ID:
159333
Filename:
csharp-interview-3(entry, mid level)
Updated:
2012-06-19 14:22:27
Tags:
interview csharp programming net
Folders:

Description:
csharp interview questions and answers - part 3 - entry and mid level
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user sabond on FreezingBlue Flashcards. What would you like to do?


  1. Difference between a Thread and a Process?
    • A process is a collection of virtual memory space, code, data, and system resources.
    • A thread is code that is to be serially executed within a process. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread. Prior to the introduction of
    • multiple threads of execution, applications were all designed to run on a single thread of execution.

    When a thread begins to execute, it continues until it is killed or until it is interrupted by a thread with higher priority (by a user action or the kernel’s thread scheduler).

    Each thread can run separate sections of code, or multiple threads can execute the same section of code. Threads executing the same block of code maintain separate stacks. Each thread in a process shares that process’s global variables and resources.
  2. What is a Windows Service and how does its
    lifecycle differ from a "standard" EXE?
    A service opens before you even get to the login screen, whereas a standard exe cannot open until after you have logged on.

    • Windows Service applications are long-running applications that are ideal for use in server environments. The applications do not have a user interface or produce any visual output. Any user messages are typically written to the
    • Windows Event Log. Services can be automatically started when the computer is booted. They do not require a logged in user in order to execute and can run under the context of any user including the system. Windows Services are
    • controlled through the Service Control Manager where they can be stopped, paused, and started as needed.

    • Windows service is an application that runs in the
    • background. It is equivalent to a NT service. The executable created is not a Windows application, and hence you can't just click and run it. It needs to be installed as a service, .Net has a facility where we can add an installer to our program and then use a utility to install the service. Where as this is not the case with standard exe.
  3. 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?
    Processes access virtual memory space, not physical memory. Applications never access RAM directly but only through the memory management interface of the processor.

    Depending on which version of Windows you are using, and how the program was compiled there is a different maximum amount of addressable memory.

    All 32 bit processes on 32bit Windows have a 4GB virtual address space. The upper 2GB is common to all processes and is used by the system. The lower 2GB is private to each process and is inaccessable to all others. Unless the program was compiled as large address aware, in which case it will have 3GB of private address space.

    For 32bit processes on 64bit Windows, each process has 2GB private address space, unless compiled large address aware in which case it has 4GB private adress space.

    For 64bit processes on 64bit windows each process has 8TB of private address space whilst compiled as large address aware. The 2GB address space limit remains for programs not compiled as large address aware.

    This is completely independent of the size of RAM or the pagefile. The system maps physical memory into this virtual address space according to both need and availability.

    At any given time the data in virtual memory space might be stored in RAM, on disk, or both. All of this is totally transparent to all applications. Frequently accessed data will be kept in RAM with the remainder left on disk.
  4. What is the difference between an EXE and a DLL?
    An exe runs in it's own address space, Dll gets loaded into the 'hosting' process address space or a shared address space.

    The only difference between an EXE and a DLL is that the latter does not have an entry point. – wrong, dll might have Main.

    Although an EXE file and a DLL file are both executables, a DLL file cannot execute on its own. A DLL file is a dynamic link library which is referenced by an EXE during program runtime and dynamically loaded into memory. As its name implies a DLL is a library, a library of functions. The advantage of using DLL’s is that commonly used functions such as graphics and printing functions can be packaged into a common DLL which is then referenced by different executables without having to re-write the functions. In addition, these libraries are dynamic in that are only loaded in memory when they are called. For instance if an application references a printing DLL but during the lifetime of that application the user never prints, the DLL will not be loaded in memory.

    DLL does not initialize it's own memory space/stack when loaded. It uses the controlling EXE's stack to store data.
  5. What is a PID? How is it useful when troubleshooting a system?
    PID stands for Process Identifier.

    This is a unique system wide number that identifies a process on the system. This ID is used by debuggers and low-level administrative tools to indicate which process is causing the problem. It can also be used to trace system calls of a particular process.
  6. How many processes can listen on a single TCP/IP port? 
    One. Only one can capture the incoming packet. 

    "one application listening on a single port" that's the reason why ports exist -- to allow multiple applications to share the network without conflicts
  7. What is the GAC? What problem does it solve?
    • GAC = Global Assembly Cache,
    • solves dll versioning (hell) problem. It's interesting to know how it solves the problem, each assembly is uniquely identified by 4 'things' major version number,minor version, build and revision numbers.For each differing version, the GAC silently creates a subfolder based on a hash of these and places the assembly in it.From a user perspective it seems as if, we are moving the same file in one directory and it doesn't ask if it should overwrite the file !
  8. What is the difference between Managed and
    Unmanaged Code in .NET?
    Unmanaged executable files are basically a binary image, x86 code, loaded into memory. The program counter gets put there and that’s the last the OS knows. There are protections in place around memory management and port I/O and so forth, but the system doesn’t actually know what the application is doing. Therefore, it can’t make any guarantees about what happens when the application runs.

    Definitions for managed code:

    • Code that is executed by the CLR. Managed code
    • provides information (i.e., metadata) to allow the CLR to locate methods encoded in assembly modules, store and retrieve security information, handle exceptions, and walk the program stack. Managed code can access both managed data and unmanaged data. Managed data—Memory that is allocated and released by the CLR using Garbage Collection. Managed data can only be accessed by managed code.

    • Code that targets the common language runtime, the
    • foundation of the .NET Framework, is known as managed code; code that does not target the common language runtime is known as unmanaged code. You can
    • think of the runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety in the code. The concept
    • of code management is a fundamental principle of the runtime.

    • Managed code supplies the metadata necessary for the
    • CLR to provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on IL executes as managed code.

    • Code that executes under the CLI execution environment. 
    • Managed code uses the execution environment for memory management, object lifetime, and the basic type-system, among other fundamental services.
  9. Describe what an Interface is and how it’s different from a Class.
    An interface only defines a contract - 'what' should be implemented - Class takes care of the 'how'.
  10. When to use interface and when abstract class?
    • 1.     If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are
    • automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface.

    2.      If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.

    3.      If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.

    4.      If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.  
  11. What is Reflection?
    • It's the way runtime gathers type/assembly/module
    • information at runtime.

    Reflection is the ability to read metadata at runtime. Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically. Reflection also allows us to create new types at runtime.
  12. Conceptually, what is the difference between
    early-binding and late-binding?
    • Early binding - I know at compilation time what I am calling (The call is resolved at compile time).
    • Late binding - Resolve the call at runtime.

    Early binding determines execution path at compilation, late binding allows for dynamic execution at runtime.
  13. What is an Asssembly Qualified Name? Is it a filename? How is it different?
    • Fully qualified name of an assembly includes major,minor
    • ,build,revision numbers + culture + key info.

    • Assembly asm = Assembly.LoadFrom(“…\\Debug\\ApxIndexDAL.dll”);   
    • Console.WriteLine(Asm.FullName);

    • "ApxIndexDAL, Version=1.1.0.0, Culture=neutral,
    • PublicKeyToken=null"

    Type asm in immediate window to see its properties:

    asm

    • {ApxIndexDAL, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null} 
    •     CodeBase: "file:///C:/a_work/net2005/IDR_7-2008/JK/ApxIndexData/bin/Debug/ApxIndexDAL.DLL" 
    •     EntryPoint: null 
    •     EscapedCodeBase: "file:///C:/a_work/net2005/IDR_7-2008/JK/ApxIndexData/bin/Debug/ApxIndexDAL.DLL"
    •     Evidence: {System.Security.Policy.Evidence}
    •     FullName: "ApxIndexDAL, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null"
    •     GlobalAssemblyCache: false
    •     HostContext: 0
    •     ImageRuntimeVersion: "v2.0.50727"
    •     Location: "C:\\a_work\\net2005\\IDR_7-2008\\JK\\ApxIndexData\\bin\\Debug\\ApxIndexDAL.dll"
    •     ManifestModule: {ApxIndexDAL.dll}
    •     ReflectionOnly: false
  14. Is this valid? Assembly.Load("foo.dll");
    NO

    • using System.Reflection;
    • Assembly asm = Assembly.LoadFrom(“…\\Debug\\ApxIndexDAL.dll”);    // uses … foo.dll

    You should never use Assembly.LoadFile(). Use LoadFrom() if you know where the assembly is located, use Load() to let .NET figure out where the assembly is located.  

    • OR
    • Assembly al = Assembly.Load("ApxIndexDAL ");   // no.dll
    • Type t = al.GetType("ClassLibrary1.Class1");

    • OR
    • Assembly asm = Assembly.LoadFile(dllPath)
  15. How does the generational garbage collector in the .NET CLR manage object lifetime? 
    What is non-deterministic finalization?
    An object is GC collected only when the GC is forced to do a garbage collection, otherwise it lets the junk pile up - so you never know when GC will wake up from it's slumber and clean your stuff up - that's non-deterministic finalization.
  16. What is the difference between Finalize() and Dispose()?
    Finalize called by GC and Dispose called by programmer to free up resources. 

    Finalize is non-deterministic - it is called by the GC, so you can never be sure when it's gonna get called. Dispose() is deterministic - you explicitly call it.

    Recommended cleanup pattern for any class using unmanaged resources:

    • 1)     Implement IDisposable as well as override Finalize.
    • 2)     In Finalize call GC.SuppressFinalize(this);

    • public class SqlConnection : IDisposable, IDbConnection
    • {
    •     private void Cleanup()
    •     {
    •         // Release unmanaged resource
    •     }

    •     public void Dispose()
    •     {
    •         Cleanup();
    •         GC.SuppressFinalize(this);
    •     }

    •     protected override void Finalize()
    •     {
    •         Cleanup();
    •     }
    • }
  17. What is boxing?
    All types within the CLR fall into one of two categories: reference types (objects) or value types (values).  

    Boxing converts a value-type to a reference-type, thus storing the object on the heapUnboxing converts a reference-type to a value-type, thus storing the value on the stack.

    • int i = 9;
    • object o = i; // boxing
    • int k = (int) o; // unboxing 
  18. Is string a value type or a reference type?
    • It is a reference type 
    • It's immutable You can never actually change the contents of a string, at least with safe code which doesn't use reflection. Because of this, you often end up changing the value of a string variable. For instance, the code s = s.Replace ("foo", "bar"); doesn't change the contents of the string that s originally referred to - it just sets the value of s to a new string, which is a copy of the old string but with "foo" replaced by "bar".  
    • It can contain nulls 
    • It overloads the == operator  When the == operator is used to compare two strings, the Equals method is called, which checks for the equality of the contents of the strings rather than the references themselves. For instance, "hello".Substring(0, 4)=="hell" is true, even though the references on the two sides of the operator are different (they refer to two different string objects, which both contain the same character sequence).

What would you like to do?

Home > Flashcards > Print Preview