Monday, October 6, 2008

OOPS Questions And Answers


1.) Why JAVA is known as securable language? 

There are two reasons behind this. The first one is, as JAVA runs in JVM, which is a virtual machine, and it converts source code to byte code, which is not understandable for humans, so its safe. The second reason is JAVA does not support the Pointer concept, hence we can say that JAVA is a securable language.


2.) What is the necessity of Interface? 

As java is a Partially Object Oriented language, and it does not support the multiple inheritance concepts, it creates problem for the developers. To over come this situation JAVA provides Interface concept for multiple inheritance.


3.) What is Abstraction? 

An essential element of object-oriented programming is abstraction. Abstraction is the process to hide the complexity. A powerful way to manage abstraction is through the use of hierarchical classifications. This allows programmer to understand the semantics of complex system.


4.) What is Polymorphism? 

The meaning of Polymorphism is something like one name many forms. Polymorphism enables one entity to be used as general category for different types of actions. The specific action is determined by the exact nature of the situation. The concept of polymorphism can be explained as “one interface, multiple methods”.


5.) What is Inheritance? 

Inheritance is the process of basing one class on another. In this process, a base class provides methods, properties, and other members to a derived class. The advantage of inheritance is that you can write and maintain code once it is in the base class and reuse it over and over in the derived classes. But the main draw back of Java is it doesn’t support multiple Inheritances; hence to over come this draw back Java provides us the Interface concept.


6.) What is Object Oriented Programming Language ? 

The language, which obeys all the basic principles of Object Oriented Programming, which are Encapsulation, Inheritance and Polymorphism, is generally known as Object Oriented Programming Language. Languages like c++ and java are some well-known Object Oriented Programming Languages.


7.) What is Encapsulation?

Encapsulation is a process of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse.


8.) What is Class and Object? 

A class defines the abstract characteristics of a thing (object), including the thing’s characteristics, like its attributes or properties and the things it can do .The code for a class should be relatively self-contained. Collectively, the properties and methods defined by a class are called members. Object a particular instance of a class. Object holds the characteristics of the Class. The set of values of the attributes of a particular object is called its state.


9.) Is JAVA a completely Object Oriented Programming Language?

The answer to this question is certainly no. The reason behind this is JAVA does not obey the OOPs concept purely. Certain concepts like Operator over loading and Multiple Inheritance are not supported by JAVA. Hence JAVA is known as Partially Object Oriented Programming Language.


10) Does a class inherit the constructors of its superclass?

A class does not inherit constructors from any of its super classes.

11) If a class is declared without any access modifiers, where may the class be accessed?

A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.


12) What is the difference between shadow and override?

Overriding is used to redefines only the methods, but shadowing redefines the entire element.

13) What is multithreading?

Multithreading is the mechanism in which more than one thread run independent of each other within the process.

14) What are inner class and anonymous class?

Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

15) What is the difference between superclass and subclass?

A super class is a class that is inherited whereas sub class is a class that does the inheriting.

16) What is difference between overloading and overriding?

a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method.

b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass.

c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass.

d) Overloading must have different method signatures whereas overriding must have same signature.

17) How many ways can an argument be passed to a subroutine?

An argument can be passed in two ways. They are Pass by Value and Passing by Reference.

Passing by value: This method copies the value of an argument into the formal parameter of the subroutine.

Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.

18) What is the difference between procedural and object-oriented programs?

1. In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code.
2. In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.

19) What are the advantages of OOPL?

Object oriented programming languages directly represent the real life objects. The features of OOPL as inheritance, polymorphism, encapsulation makes it powerful.

20) Can a method be overloaded based on different return type but same argument type ?

No, because the methods can be called without using their return type in which case there is ambiguity for the compiler.

21) What is Downcasting ?

Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.

22) Who were the three famous amigos and what was their contribution to the object community?

The Three amigos namely,
James Rumbaugh (OMT): A veteran in analysis who came up with an idea about the objects and their Relationships (in particular Associations).
Grady Booch: A veteran in design who came up with an idea about partitioning of systems into subsystems.
Ivar Jacobson (Objectory): The father of USECASES, who described about the user and system interaction.

23)What is meant by ?method-wars??

Before 1994 there were different methodologies like Rumbaugh, Booch, Jacobson, Meyer etc who followed their own notations to model the systems. The developers were in a dilemma to choose the method which best accomplishes their needs. This particular span was called as ?method-wars?

24) Differentiate Aggregation and containment?

Aggregation is the relationship between the whole and a part. We can add/subtract some properties in the part (slave) side. It won?t affect the whole part.
Best example is Car, which contains the wheels and some extra parts. Even though the parts are not there we can call it as car.
But, in the case of containment the whole part is affected when the part within that got affected. The human body is an apt example for this relationship. When the whole body dies the parts (heart etc) are died.

25) Differentiate persistent & non-persistent objects?

Persistent refers to an object?s ability to transcend time or space. A persistent object stores/saves its state in a permanent storage system with out losing the information represented by the object.
A non-persistent object is said to be transient or ephemeral. By default objects are considered as non-persistent.

26) List out some of the object-oriented methodologies.

Object Oriented Development (OOD) (Booch 1991,1994).
Object Oriented Analysis and Design (OOA/D) (Coad and Yourdon 1991).
Object Modeling Techniques (OMT) (Rumbaugh 1991).
Object Oriented Software Engineering (Objectory) (Jacobson 1992).
Object Oriented Analysis (OOA) (Shlaer and Mellor 1992).
The Fusion Method (Coleman 1991).







Monday, August 11, 2008

.Net Interview Questions

1. When was .NET announced?
Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and delegates were given CDs containing a pre-release version of the .NET framework/SDK and Visual Studio.NET.
2. When was the first version of .NET released?
The final version of the 1.0 SDK and runtime was made publicly available around 6pm PST on 15-Jan-2002. At the same time, the final version of Visual Studio.NET was made available to MSDN subscribers.
3. What platforms does the .NET Framework run on?
The runtime supports Windows XP, Windows 2000, NT4 SP6a and Windows ME/98. Windows 95 is not supported. Some parts of the framework do not work on all platforms - for example, ASP.NET is only supported on Windows XP and Windows 2000. Windows 98/ME cannot be used for development.IIS is not supported on Windows XP Home Edition, and so cannot be used to host ASP.NET. However, the ASP.NET Web Matrix web server does run on XP Home.The Mono project is attempting to implement the .NET framework on Linux.
4. What is the CLR?
CLR = Common Language Runtime. The CLR is a set of standard resources that (in theory) any .NET program can take advantage of, regardless of programming language. Robert Schmidt (Microsoft) lists the following CLR resources in his MSDN PDC# article:Object-oriented programming model (inheritance, polymorphism, exception handling, garbage collection) Security model Type system All .NET base classes Many .NET framework classes Development, debugging, and profiling tools Execution and code management IL-to-native translators and optimizers What this means is that in the .NET world, different programming languages will be more equal in capability than they have ever been before, although clearly not all languages will support all CLR services.
5. What is the CTS?
CTS = Common Type System. This is the range of types that the .NET runtime understands, and therefore that .NET applications can use. However note that not all .NET languages will support all the types in the CTS. The CTS is a superset of the CLS.
6. What is the CLS?
CLS = Common Language Specification. This is a subset of the CTS which all .NET languages are expected to support. The idea is that any program which uses CLS-compliant types can interoperate with any .NET program written in any language.In theory this allows very tight interop between different .NET languages - for example allowing a C# class to inherit from a VB class.
7. What is IL?
IL = Intermediate Language. Also known as MSIL (Microsoft Intermediate Language) or CIL (Common Intermediate Language). All .NET source code (of any language) is compiled to IL. The IL is then converted to machine code at the point where the software is installed, or at run-time by a Just-In-Time (JIT) compiler.
8. What does 'managed' mean in the .NET context?
The term 'managed' is the cause of much confusion. It is used in various places within .NET, meaning slightly different things.Managed code: The .NET framework provides several core run-time services to the programs that run within it - for example exception handling and security. For these services to work, the code must provide a minimum level of information to the runtime. Such code is called managed code. All C# and Visual Basic.NET code is managed by default. VS7 C++ code is not managed by default, but the compiler can produce managed code by specifying a command-line switch (/com+).Managed data: This is data that is allocated and de-allocated by the .NET runtime's garbage collector. C# and VB.NET data is always managed. VS7 C++ data is unmanaged by default, even when using the /com+ switch, but it can be marked as managed using the __gc keyword.Managed classes: This is usually referred to in the context of Managed Extensions (ME) for C++. When using ME C++, a class can be marked with the __gc keyword. As the name suggests, this means that the memory for instances of the class is managed by the garbage collector, but it also means more than that. The class becomes a fully paid-up member of the .NET community with the benefits and restrictions that brings. An example of a benefit is proper interop with classes written in other languages - for example, a managed C++ class can inherit from a VB class. An example of a restriction is that a managed class can only inherit from one base class.
9. What is reflection?
All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly. Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes - e.g. determining data type sizes for marshaling data across context/process/machine boundaries.Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember ) , or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).
10. What is the difference between Finalize and Dispose (Garbage collection) ?
Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles (HWND), database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. Provide implicit control by implementing the protected Finalize Method on an object (destructor syntax in C# and the Managed Extensions for C++). The garbage collector calls this method at some point after there are no longer any valid references to the object. In some cases, you might want to provide programmers using an object with the ability to explicitly release these external resources before the garbage collector frees the object. If an external resource is scarce or expensive, better performance can be achieved if the programmer explicitly releases resources when they are no longer being used. To provide explicit control, implement the Dispose method provided by the IDisposable Interface. The consumer of the object should call this method when it is done using the object. Dispose can be called even if other references to the object are alive. Note that even when you provide explicit control by way of Dispose, you should provide implicit cleanup using the Finalize method. Finalize provides a backup to prevent resources from permanently leaking if the programmer fails to call Dispose.
11. What is Partial Assembly References?
Full Assembly reference: A full assembly reference includes the assembly's text name, version, culture, and public key token (if the assembly has a strong name). A full assembly reference is required if you reference any assembly that is part of the common language runtime or any assembly located in the global assembly cache.
Partial Assembly reference: We can dynamically reference an assembly by providing only partial information, such as specifying only the assembly name. When you specify a partial assembly reference, the runtime looks for the assembly only in the application directory.We can make partial references to an assembly in your code one of the following ways:-> Use a method such as System.Reflection.Assembly.Load and specify only a partial reference. The runtime checks for the assembly in the application directory.-> Use the System.Reflection.Assembly.LoadWithPartialName method and specify only a partial reference. The runtime checks for the assembly in the application directory and in the global assembly cache
12. Changes to which portion of version number indicates an incompatible change?
Major or minor. Changes to the major or minor portion of the version number indicate an incompatible change. Under this convention then, version 2.0.0.0 would be considered incompatible with version 1.0.0.0. Examples of an incompatible change would be a change to the types of some method parameters or the removal of a type or method altogether. Build. The Build number is typically used to distinguish between daily builds or smaller compatible releases. Revision. Changes to the revision number are typically reserved for an incremental build needed to fix a particular bug. You'll sometimes hear this referred to as the "emergency bug fix" number in that the revision is what is often changed when a fix to a specific bug is shipped to a customer.
13. What is side-by-side execution? Can two application one using private assembly and other using Shared assembly be stated as a side-by-side executables?
Side-by-side execution is the ability to run multiple versions of an application or component on the same computer. You can have multiple versions of the common language runtime, and multiple versions of applications and components that use a version of the runtime, on the same computer at the same time. Since versioning is only applied to shared assemblies, and not to private assemblies, two application one using private assembly and one using shared assembly cannot be stated as side-by-side executables.
14. Why string are called Immutable data Type ?
The memory representation of string is an Array of Characters, So on re-assigning the new array of Char is formed & the start address is changed . Thus keeping the Old string in Memory for Garbage Collector to be disposed.
15. What does assert() method do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
16. What's the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
17. Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose. For applications that are constantly running you run the risk of overloading the machine and the hard drive. Five levels range from None to Verbose, allowing you to fine-tune the tracing activities.
18. Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.
19. How do assemblies find each other?
By searching directory paths. There are several factors which can affect the path (such as the AppDomain host, and application configuration files), but for private assemblies the search path is normally the application's directory and its sub-directories. For shared assemblies, the search path is normally same as the private assembly path plus the shared assembly cache.
20. How does assembly versioning work?
Each assembly has a version number called the compatibility version. Also each reference to an assembly (from another assembly) includes both the name and version of the referenced assembly.The version number has four numeric parts (e.g. 5.5.2.33). Assemblies with either of the first two parts different are normally viewed as incompatible. If the first two parts are the same, but the third is different, the assemblies are deemed as 'maybe compatible'. If only the fourth part is different, the assemblies are deemed compatible. However, this is just the default guideline - it is the version policy that decides to what extent these rules are enforced. The version policy can be specified via the application configuration file.
21. What is garbage collection?
Garbage collection is a system whereby a run-time component takes responsibility for managing the lifetime of objects and the heap memory that they occupy. This concept is not new to .NET - Java and many other languages/runtimes have used garbage collection for some time.
22. Why doesn't the .NET runtime offer deterministic destruction?
Because of the garbage collection algorithm. The .NET garbage collector works by periodically running through a list of all the objects that are currently being referenced by an application. All the objects that it doesn't find during this search are ready to be destroyed and the memory reclaimed. The implication of this algorithm is that the runtime doesn't get notified immediately when the final reference on an object goes away - it only finds out during the next sweep of the heap.Futhermore, this type of algorithm works best by performing the garbage collection sweep as rarely as possible. Normally heap exhaustion is the trigger for a collection sweep.
23. Is the lack of deterministic destruction in .NET a problem?
It's certainly an issue that affects component design. If you have objects that maintain expensive or scarce resources (e.g. database locks), you need to provide some way for the client to tell the object to release the resource when it is done. Microsoft recommend that you provide a method called Dispose() for this purpose. However, this causes problems for distributed objects - in a distributed system who calls the Dispose() method? Some form of reference-counting or ownership-management mechanism is needed to handle distributed objects - unfortunately the runtime offers no help with this.
24. What is serialization?
Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization / Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).
25. Does the .NET Framework have in-built support for serialization?
There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code.
26. Can I customise the serialization process?
Yes. XmlSerializer supports a range of attributes that can be used to configure serialization for a particular class. For example, a field or property can be marked with the [XmlIgnore] attribute to exclude it from serialization. Another example is the [XmlElement] attribute, which can be used to specify the XML element name to be used for a particular property or field.Serialization via SoapFormatter/BinaryFormatter can also be controlled to some extent by attributes. For example, the [NonSerialized] attribute is the equivalent of XmlSerializer's [XmlIgnore] attribute. Ultimate control of the serialization process can be acheived by implementing the the ISerializable interface on the class whose instances are to be serialized.
27. Why is XmlSerializer so slow?
There is a once-per-process-per-type overhead with XmlSerializer. So the first time you serialize or deserialize an object of a given type in an application, there is a significant delay. This normally doesn't matter, but it may mean, for example, that XmlSerializer is a poor choice for loading configuration settings during startup of a GUI application.
28. Why do I get errors when I try to serialize a Hashtable?
XmlSerializer will refuse to serialize instances of any class that implements IDictionary, e.g. Hashtable. SoapFormatter and BinaryFormatter do not have this restriction.
29. What are attributes?
There are at least two types of .NET attribute. The first type I will refer to as a metadata attribute - it allows some data to be attached to a class or method. This data becomes part of the metadata for the class, and (like other class metadata) can be accessed via reflection. The other type of attribute is a context attribute. Context attributes use a similar syntax to metadata attributes but they are fundamentally different. Context attributes provide an interception mechanism whereby instance activation and method calls can be pre- and/or post-processed.
30. How does CAS work?
The CAS security policy revolves around two key concepts - code groups and permissions. Each .NET assembly is a member of a particular code group, and each code group is granted the permissions specified in a named permission set.For example, using the default security policy, a control downloaded from a web site belongs to the 'Zone - Internet' code group, which adheres to the permissions defined by the 'Internet' named permission set. (Naturally the 'Internet' named permission set represents a very restrictive range of permissions.)
31. Who defines the CAS code groups?
Microsoft defines some default ones, but you can modify these and even create your own. To see the code groups defined on your system, run 'caspol -lg' from the command-line. On my system it looks like this:Level = MachineCode Groups:1. All code: Nothing 1.1. Zone - MyComputer: FullTrust 1.1.1. Honor SkipVerification requests: SkipVerification 1.2. Zone - Intranet: LocalIntranet 1.3. Zone - Internet: Internet 1.4. Zone - Untrusted: Nothing 1.5. Zone - Trusted: Internet 1.6. StrongName - 0024000004800000940000000602000000240000525341310004000003000000CFCB3291AA715FE99D40D49040336F9056D7886FED46775BC7BB5430BA4444FEF8348EBD06F962F39776AE4DC3B7B04A7FE6F49F25F740423EBF2C0B89698D8D08AC48D69CED0FC8F83B465E0807AC11EC1DCC7D054E807A43336DDE408A5393A48556123272CEEEE72F1660B71927D38561AABF5CAC1DF1734633C602F8F2D5: Note the hierarchy of code groups - the top of the hierarchy is the most general ('All code'), which is then sub-divided into several groups, each of which in turn can be sub-divided. Also note that (somewhat counter-intuitively) a sub-group can be associated with a more permissive permission set than its parent.
32. How do I define my own code group?
Use caspol. For example, suppose you trust code from www.mydomain.com and you want it have full access to your system, but you want to keep the default restrictions for all other internet sites. To achieve this, you would add a new code group as a sub-group of the 'Zone - Internet' group, like this: caspol -ag 1.3 -site www.mydomain.com FullTrust Now if you run caspol -lg you will see that the new group has been added as group 1.3.1:
1.3. Zone - Internet: Internet 1.3.1. Site - www.mydomain.com: FullTrust
Note that the numeric label (1.3.1) is just a caspol invention to make the code groups easy to manipulate from the command-line. The underlying runtime never sees it.
33. How do I change the permission set for a code group?
Use caspol. If you are the machine administrator, you can operate at the 'machine' level - which means not only that the changes you make become the default for the machine, but also that users cannot change the permissions to be more permissive. If you are a normal (non-admin) user you can still modify the permissions, but only to make them more restrictive. For example, to allow intranet code to do what it likes you might do this: caspol -cg 1.2 FullTrustNote that because this is more permissive than the default policy (on a standard system), you should only do this at the machine level - doing it at the user level will have no effect.
34. I can't be bothered with all this CAS stuff. Can I turn it off?
Yes, as long as you are an administrator. Just run: caspol -s off
35. Can I look at the IL for an assembly?
Yes. MS supply a tool called Ildasm which can be used to view the metadata and IL for an assembly.
36. Can source code be reverse-engineered from IL?
Yes, it is often relatively straightforward to regenerate high-level source (e.g. C#) from IL.
37. How can I stop my code being reverse-engineered from IL?
There is currently no simple way to stop code being reverse-engineered from IL. In future it is likely that IL obfuscation tools will become available, either from MS or from third parties. These tools work by 'optimising' the IL in such a way that reverse-engineering becomes much more difficult.Of course if you are writing web services then reverse-engineering is not a problem as clients do not have access to your IL.
38. Is there built-in support for tracing/logging?
Yes, in the System.Diagnostics namespace. There are two main classes that deal with tracing - Debug and Trace. They both work in a similar way - the difference is that tracing from the Debug class only works in builds that have the DEBUG symbol defined, whereas tracing from the Trace class only works in builds that have the TRACE symbol defined. Typically this means that you should use System.Diagnostics.Trace.WriteLine for tracing that you want to work in debug and release builds, and System.Diagnostics.Debug.WriteLine for tracing that you want to work only in debug builds.
39. Can I redirect tracing to a file?
Yes. The Debug and Trace classes both have a Listeners property, which is a collection of sinks that receive the tracing that you send via Debug.WriteLine and Trace.WriteLine respectively. By default the Listeners collection contains a single sink, which is an instance of the DefaultTraceListener class. This sends output to the Win32 OutputDebugString() function and also the System.Diagnostics.Debugger.Log() method. This is useful when debugging, but if you're trying to trace a problem at a customer site, redirecting the output to a file is more appropriate. Fortunately, the TextWriterTraceListener class is provided for this purpose.
40. What are the contents of assembly?
In general, a static assembly can consist of four elements: The assembly manifest, which contains assembly metadata. Type metadata. Microsoft intermediate language (MSIL) code that implements the types. A set of resources.
41. What is GC (Garbage Collection) and how it works
One of the good features of the CLR is Garbage Collection, which runs in the background collecting unused object references, freeing us from having to ensure we always destroy them. In reality the time difference between you releasing the object instance and it being garbage collected is likely to be very small, since the GC is always running.[The process of transitively tracing through all pointers to actively used objects in order to locate all objects that can be referenced, and then arranging to reuse any heap memory that was not found during this trace. The common language runtime garbage collector also compacts the memory that is in use to reduce the working space needed for the heap.]
Heap:A portion of memory reserved for a program to use for the temporary storage of data structures whose existence or size cannot be determined until the program is running.
42. Differnce between Managed code and unmanaged code ?
Managed Code:Code that runs under a "contract of cooperation" with the common language runtime. Managed code must supply the metadata necessary for the runtime to provide services such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on Microsoft intermediate language (MSIL) executes as managed code.
Un-Managed Code:Code that is created without regard for the conventions and requirements of the common language runtime. Unmanaged code executes in the common language runtime environment with minimal services (for example, no garbage collection, limited debugging, and so on).
43. What is MSIL, IL, CTS and, CLR ?
MSIL: (Microsoft intermediate language)When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Before code can be executed, MSIL must be converted to CPU-specific code, usually by a just-in-time (JIT) compiler. Because the common language runtime supplies one or more JIT compilers for each computer architecture it supports, the same set of MSIL can be JIT-compiled and executed on any supported architecture.When a compiler produces MSIL, it also produces metadata. Metadata describes the types in your code, including the definition of each type, the signatures of each type's members, the members that your code references, and other data that the runtime uses at execution time. The MSIL and metadata are contained in a portable executable (PE) file that is based on and extends the published Microsoft PE and Common Object File Format (COFF) used historically for executable content. This file format, which accommodates
MSIL or native code as well as metadata, enables the operating system to recognize common language runtime images. The presence of metadata in the file along with the MSIL enables your code to describe itself, which means that there is no need for type libraries or Interface Definition Language (IDL). The runtime locates and extracts the metadata from the file as needed during execution.
IL: (Intermediate Language)A language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.
CTS: (Common Type System)The specification that determines how the common language runtime defines, uses, and manages types
CLR: (Common Language Runtime)The engine at the core of managed code execution. The runtime supplies managed code with services such as cross-language integration, code access security, object lifetime management, and debugging and profiling support.
44. What is Reference type and value type ?
Reference Type:Reference types are allocated on the managed CLR heap, just like object types.A data type that is stored as a reference to the value's location. The value of a reference type is the location of the sequence of bits that represent the type's data. Reference types can be self-describing types, pointer types, or interface types
Value Type:Value types are allocated on the stack just like primitive types in VBScript, VB6 and C/C++. Value types are not instantiated using new go out of scope when the function they are defined within returns.Value types in the CLR are defined as types that derive from system.valueType.
A data type that fully describes a value by specifying the sequence of bits that constitutes the value's representation. Type information for a value type instance is not stored with the instance at run time, but it is available in metadata. Value type instances can be treated as objects using boxing.
45. What is Boxing and unboxing ?
Boxing:The conversion of a value type instance to an object, which implies that the instance will carry full type information at run time and will be allocated in the heap. The Microsoft intermediate language (MSIL) instruction set's box instruction converts a value type to an object by making a copy of the value type and embedding it in a newly allocated object.
Un-Boxing:The conversion of an object instance to a value type.
46. What is JIT and how is works ?
An acronym for "just-in-time," a phrase that describes an action that is taken only when it becomes necessary, such as just-in-time compilation or just-in-time object activation
47. What is portable executable (PE) ?
The file format used for executable programs and for files to be linked together to form executable programs
48. What is strong name?
A name that consists of an assembly's identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly. Because the assembly manifest contains file hashes for all the files that constitute the assembly implementation, it is sufficient to generate the digital signature over just the one file in the assembly that contains the assembly manifest. Assemblies with the same strong name are expected to be identical
49. What is global assembly cache?
A machine-wide code cache that stores assemblies specifically installed to be shared by many applications on the computer. Applications deployed in the global assembly cache must have a strong name.
50. What is difference between constants, readonly and, static ?
Constants: The value can’t be changed Read-only: The value will be initialized only once from the constructor of the class.Static: Value can be initialized once.51.What is difference between shared and public?
An assembly that can be referenced by more than one application. An assembly must be explicitly built to be shared by giving it a cryptographically strong name.
52. What is namespace used for loading assemblies at run time and name the methods?
System.Reflection
53. What are the types of authentication in .net?
We have three types of authentication: 1. Form authentication 2. Windows authentication3. PassportThis has to be declared in web.config file.
54. What is the difference between a Struct and a Class ?
The struct type is suitable for representing lightweight objects such as Point, Rectangle, and Color. Although it is possible to represent a point as a class, a struct is more efficient in some scenarios. For example, if you declare an array of 1000 Point objects,you will allocate additional memory for referencing each object. In this case, the struct is less expensive.When you create a struct object using the new operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the new operator. If you do not use new, the fields will remain unassigned and the object cannot be used until all of the fields are initialized. It is an error to declare a default (parameterless) constructor for a struct. A default constructor is always provided to initialize the struct members to their default values.It is an error to initialize an instance field in a struct.There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class Object. A struct can implement interfaces, and it does that exactly as classes do.A struct is a value type, while a class is a reference type.
55. How big is the datatype int in .NET?
32 bits.
56. How big is the char?
16 bits (Unicode).
57. How do you initiate a string without escaping each backslash?
Put an @ sign in front of the double-quoted string.
58. What's the access level of the visibility type internal?
Current application.
59. Explain encapsulation ?
The implementation is hidden, the interface is exposed.
60. What data type should you use if you want an 8-bit value that's signed?
sbyte.
61. Speaking of Boolean data types, what's different between C# and C/C++?
There's no conversion between 0 and false, as well as any other number and true, like in C/C++.
62. Where are the value-type variables allocated in the computer RAM?
Stack.
63. Where do the reference-type variables go in the RAM?
The references go on the stack, while the objects themselves go on the heap.
64. What is the difference between the value-type variables and reference-type variables in terms of garbage collection?
The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, the reference-type objects are picked up by GC when their references go null.
65. How do you convert a string into an integer in .NET?
Int32.Parse(string)
66. How do you box a primitive data type variable?
Assign it to the object, pass an object.
67. Why do you need to box a primitive variable?
To pass it by reference.
68. What's the difference between Java and .NET garbage collectors?
Sun left the implementation of a specific garbage collector up to the JRE developer, so their performance varies widely, depending on whose JRE you're using. Microsoft standardized on their garbage collection.
69. How do you enforce garbage collection in .NET?
System.GC.Collect();
70. What's different about namespace declaration when comparing that to package declaration in Java?
No semicolon.
71. What's the difference between const and readonly?
You can initialize readonly variables to some runtime values. Let's say your program uses current date and time as one of the values that won't change. This way you declare public readonly string DateT = new DateTime().ToString().
72. What happens when you encounter a continue statement inside the for loop?
The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop.
73. What's the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it's being operated on, a new instance is created.
74. Can you store multiple data types in System.Array?
No.
75. What's the difference between the System.Array.CopyTo() and System.Array.Clone()?
The first one performs a deep copy of the array, the second one is shallow. 76. How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
77. What's the .NET datatype that allows the retrieval of data by a unique key?
HashTable.
78. What's class SortedList underneath?
A sorted HashTable.
79. Will finally block get executed if the exception had not occurred?
Yes.
80. Can multiple catch blocks be executed?
No, once the proper catch code fires off, the control is transferred to the finally block (if there are any), and then whatever follows the finally block.
81. Why is it a bad idea to throw your own exceptions?
Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.
82. What's a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.
83. What's a multicast delegate?
It's a delegate that points to and eventually fires off several methods.
84. How's the DLL Hell problem solved in .NET?
Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.
85. What are the ways to deploy an assembly?
An MSI installer, a CAB archive, and XCOPY command.
86. What's a satellite assembly?
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
87. What namespaces are necessary to create a localized application?
System.Globalization, System.Resources.
88. What does assert() do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
89. What's the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
90. Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.
91. Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.
92. What namespaces are necessary to create a localized application?
System.Globalization, System.Resources.
93. What are three test cases you should go through in unit testing?
Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).
94. Can you change the value of a variable while debugging a C# application?
Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.
95. What's the implicit name of the parameter that gets passed into the class' set method?
Value, and it's datatype depends on whatever variable we're changing.
96. How do you inherit from a class in C#?
Place a colon and then the name of the base class. Notice that it's double colon in C++.
97. Does C# support multiple inheritance?
No, use interfaces instead.
98. When you inherit a protected class-level variable, who is it available to?
Derived Classes.
99. What's the top .NET class that everything is derived from?
System.Object.
100. How's method overriding different from overloading?
When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class. 101. What does the keyword virtual mean in the method definition?
The method can be over-ridden.
102. Can you declare the override method static while the original method is non-static?
No, you can't, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.
103. Can you override private virtual methods?
No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.
104. Can you prevent your class from being inherited and becoming a base class for some other classes?
Yes, that's what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It's the same concept as final class in Java.
105. Can you allow class to be inherited, but prevent the method from being over-ridden?
Yes, just leave the class public and make the method sealed.
106. Why can't you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it's public by default.
107. Can you inherit multiple interfaces?
Yes, why not.
108. And if they have conflicting method names?
It's up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you're okay.
109. What's the difference between an interface and abstract class?
In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.
110. How can you overload a method?
Different parameter data types, different number of parameters, different order of parameters.
111. If a base class has a bunch of overloaded constructors, and an inherited class has another bunch of overloaded constructors, can you enforce a call from an inherited constructor to an arbitrary base constructor?
Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.
112. What's the difference between System.String and System.StringBuilder classes?
System.String is immutable, System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
113. Does C# support multiple-inheritance?
No, use interfaces instead.
114. When you inherit a protected class-level variable, who is it available to?
The derived class.
115. Are private class-level variables inherited?
Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.
116. Describe the accessibility modifier "protected internal".
It is available to derived classes and classes within the same Assembly (and naturally from the base class it's declared in).
117. What's the top .NET class that everything is derived from?
System.Object.
118. What's the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time it's being operated on, a new instance is created.
119. Can you store multiple data types in System.Array?
No.
120. What's the .NET class that allows the retrieval of a data element using a unique key?
HashTable.
121. Will the finally block get executed if an exception has not occurred?
Yes.
122. What's an abstract class?
A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
123. When do you absolutely have to declare a class as abstract?
1. When at least one of the methods in the class is abstract.2. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
124. What's an interface?
It's an abstract class with public abstract methods all of which must be implemented in the inherited classes.
125. Why can't you specify the accessibility modifier for methods inside the interface?
They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it's public by default.

Wednesday, August 6, 2008

ARP Question And Answers

Questions

1. What is ARP?


2. To which OSI layer does ARP belong?


3. Which RFC specify the requirements for ARP?


4. What is the use of ARP?


5. Why a IP address needs to be mapped to a MAC address, why can't the MAC address itself is represented using the IP address?


6. Can ARP be used in a network other than Ethernet?


7. How does ARP resolve an IP address to an Ethernet MAC address?


8. What is an ARP cache?


9. When is an ARP request packet generated?


10. What happens when a host receives an ARP request packet?


11. Will a host update its ARP cache upon receiving any ARP request?


12. What is the disadvantage if a host updates its ARP cache upon receiving any ARP request?

13. What happens when a host receives an ARP reply packet?


14. Is there a separate packet format for ARP request and ARP reply?


15. Which MAC address is an ARP request directed to?


16. To which MAC address is an ARP reply packet directed to?


17. If a host is not able to get the MAC address of a host, how it knows about its IP address?

18. What will happen if an ARP reply is not received for an ARP request?

19. When is an entry added to the ARP cache?

20. What will happen if a new ARP request packet is received, but the MAC address to IP address is already present in the ARP cache?

21. When is an entry removed from an ARP cache?

22. What is the format of an ARP packet?

23. What is the size of an ARP request and reply packet?

24. How to differentiate between a ARP request packet and a ARP reply packet, as the Ethernet type field is same on both the packets?

25. Why is the hardware MAC address present in both the Ethernet header and the ARP packet (request and reply)?

26. What is proxy ARP?

27. What is the use of proxy ARP?

28. What is gratuitous ARP?

29. What is the use of gratuitous ARP?



Answers

1. What is ARP? Address Resolution Protocol (ARP) is a network protocol, which maps a network layer protocol address to a data link layer hardware address. For example, ARP is used to resolve IP address to the corresponding Ethernet address.


2. To which OSI layer does ARP belong? ARP belongs to the OSI data link layer (Layer 2). ARP protocol is implemented by the network protocol driver. ARP packets are encapsulated by Ethernet headers and transmitted.


3. Which RFC specify the requirements for ARP? RFC 826 specifies the ARP packet format and other details.


4. What is the use of ARP? A host in an Ethernet network can communicate with another host, only if it knows the Ethernet address (MAC address) of that host. The higher level protocols like IP use a different kind of addressing scheme (like IP address) from the lower level hardware addressing scheme like MAC address. ARP is used to get the Ethernet address of a host from its IP address. ARP is extensively used by all the hosts in an Ethernet network.


5. Why a IP address needs to be mapped to a MAC address, why can't the MAC address itself is represented using the IP address? The length of a MAC address is 6 bytes and the length of an IP address is 4 bytes. Obviously, the MAC address cannot be represented using the IP address. So an IP address must be mapped to the corresponding MAC address.


6. Can ARP be used in a network other than Ethernet? ARP is a general protocol, which can be used in any type of broadcast network. The fields in the ARP packet specifies the type of the MAC address and the type of the protocol address. ARP is used with most IEEE 802.x LAN media. In particular, it is also used with FDDI, Token Ring, and Fast Ethernet, in precisely the same way as it is with Ethernet.


7. How does ARP resolve an IP address to an Ethernet MAC address? When ARP needs to resolve a given IP address to Ethernet address, it broadcasts an ARP request packet. The ARP request packet contains the source MAC address and the source IP address and the destination IP address. Each host in the local network receives this packet. The host with the specified destination IP address, sends an ARP reply packet to the originating host with its IP address.


8. What is an ARP cache? ARP maintains the mapping between IP address and MAC address in a table in memory called ARP cache. The entries in this table are dynamically added and removed.


9. When is an ARP request packet generated? The following steps results in the generation of an ARP request packet: 1. The IP module sends a packet, destined for another host in the network, to the ARP module. 2. The ARP module looks up the ARP table (cache) to resolve the IP address. 3. If the supplied IP address is present in the ARP cache, it is resolved into its Ethernet address. 4. If the ARP module is not able to find an entry for this IP address in the ARP cache, then it sends an ARP request packet to the Ethernet driver, to resolve the IP address to the Ethernet address. 5. After the IP address is resolved by the ARP module, the packet is sent to the Ethernet driver for transmission.


10. What happens when a host receives an ARP request packet? The ARP request is received and processed by all the hosts in the network, since it is a broadcast packet. The following steps are carried out when a ARP request packet is received by a host: 1. If the IP address to be resolved is for this host, then the ARP module sends an ARP reply packet with its Ethernet MAC address. 2. If the IP address to be resolved is for this host, then the ARP module updates its ARP cache with the source Ethernet MAC address to source IP address mapping present in the ARP request packet. If the entry is already present in the cache, it is overwritten. If it is not present, it is added. 3. If the IP address to be resolved is not for this host, then the ARP module discards the ARP request packet.


11. Will a host update its ARP cache upon receiving any ARP request? A host will update its ARP cache, only if the ARP request is for its IP address. Otherwise, it will discard the ARP request.
12. What is the disadvantage if a host updates its ARP cache upon receiving any ARP request? The host will exhaust the ARP cache with a lot of unused ARP entries, if it updates the ARP cache for any ARP request.


13. What happens when a host receives an ARP reply packet? The ARP reply packet is received only by the host, which transmitted the ARP request packet. The ARP module adds the Ethernet hardware address to IP address mapping present in the ARP reply packet to the ARP cache.


14. Is there a separate packet format for ARP request and ARP reply? No. Both the ARP request and ARP reply packets use the same format.


15. Which MAC address is an ARP request directed to? All ARP request packets are transmitted with the Ethernet broadcast address, so that all hosts in the network will receive the request.


16. To which MAC address is an ARP reply packet directed to? ARP reply packet is directed to the host, which transmitted the ARP request packet.


17. If a host is not able to get the MAC address of a host, how it knows about its IP address? A host will either use a static file like /etc/hosts or DNS protocol to get the IP address of another host.


18. What will happen if an ARP reply is not received for an ARP request? If an ARP reply is not received, then that IP address cannot be resolved to an Ethernet address. Without a Ethernet address, the packets cannot be transmitted.


19. When is an entry added to the ARP cache? A new entry is added to the ARP cache when an IP address is successfully mapped to a MAC address. Usually, entries are added dynamically to the ARP cache. Static entries can also be added.


20. What will happen if a new ARP request packet is received, but the MAC address to IP address is already present in the ARP cache? If a ARP request packet is received and the mapping already exists in the ARP cache, it will be overwritten with the values present in the request.


21. When is an entry removed from an ARP cache? An entry in an ARP cache is removed after a pre-determined timeout period (e.g. 20 minutes).


22. What is the format of an ARP packet? The various fields of a ARP request/reply packet and their length are shown below:

+--------+
Hardware 2 bytes
MAC
Address
Type
+--------+
Protocol 2 bytes
Address
Type
+--------+
Hardware 1 byte
MAC
Address
Size
+--------+
Protocol 1 byte
Address
Size
+--------+
Op 2 bytes
+--------+
Sender 6 bytes (depends on the above size field)
MAC
Address
+--------+
Sender 4 bytes (depends on the above size field)
IP
Address
+--------+
Target 6 bytes (depends on the above size field)
MAC
Address
+--------+
Target 4 bytes (depends on the above size field)
IP
Address
+--------+

The fields are further explained below:

+---------+-------------------------------------------------------+
Ethernet For a ARP request, source MAC address is the MAC
Header address of the host sending the ARP request,
destination MAC address is the Ethernet broadcast
address (FF:FF:FF:FF:FF:FF), frame type field is 0x806.
For ARP reply, source MAC address is the MAC address of
the host replying to the ARP request, destination MAC
address is the MAC address of the host that sent the
ARP request, and the frame type field is 0x806.
+---------+-------------------------------------------------------+
Hardware Type of the hardware MAC address which is being mapped.
Address For Ethernet the value of this field is 1.
Type
+---------+-------------------------------------------------------+
Protocol Type of the protocol address to which the MAC address
Address is mapped. For IP address the value of this field is
Type 0x800.
+---------+-------------------------------------------------------+
Hardware Size of the hardware MAC address. For Ethernet, the
Address value of this field is 6.
Size
+---------+-------------------------------------------------------+
Protocol Size of the protocol address. For IP, the value of
Address this field is 4.
Size
+---------+-------------------------------------------------------+
OperationType of operation being performed. The value of this
field can be 1 (ARP request), 2 (ARP reply)
+---------+-------------------------------------------------------+
Source The hardware MAC address of the host sending the ARP
MAC request or reply. This is same as the source MAC
address address present in the Ethernet header.
+---------+-------------------------------------------------------+
Source The IP address of the host sending the ARP request or
IP reply.
address
+---------+-------------------------------------------------------+
Target The hardware MAC address of the host receiving the ARP
MAC request or reply. This is same as the destination MAC
address address present in the Ethernet header.
+---------+-------------------------------------------------------+
Target The IP address of the host receiving the ARP request
IP or reply.
address
+---------+-------------------------------------------------------+





23. What is the size of an ARP request and reply packet? The size of an ARP request or reply packet is 28 bytes.


24. How to differentiate between a ARP request packet and a ARP reply packet, as the Ethernet type field is same on both the packets? An ARP request packet can be differentiated from an ARP reply packet using the 'operation' field in the ARP packet. For a ARP request it is 1 and for an ARP reply it is 2.


25. Why is the hardware MAC address present in both the Ethernet header and the ARP packet (request and reply)? The Ethernet header is processed by the data link driver and removed from the packet. When the ARP layer gets the packet, it needs to know the hardware and protocol addresses in order to update the table. That is why the hardware MAC address is present in both the Ethernet header and the ARP packet.


26. What is proxy ARP? Proxy ARP is the process in which one system responds to the ARP request for another system. For example, host A sends an ARP request to resolve the IP address of host B. Instead of Host B, Host C responds to this ARP request.


27. What is the use of proxy ARP? When routers receive ARP requests from one network for hosts on the network, they will respond with a ARP reply packet with their MAC address. For example, let us say host A is in one network, host B is in another network and router C connects these two networks. When host A sends an ARP request to resolve the IP address of host B, the router C receives this packet. The router C sends an ARP reply with its MAC address. So host A will send all the packets destined for host B to the router C. Router C will then forward those packets to host B. Proxy ARP is also used if a host in a network is not able to understand subnet addressing. For example, if host A and host B are actually in two different subnets, but host A cannot understand subnet addressing. So host A assumes that host B is present in the same network. In this case a router, host C, can use proxy ARP to route packets between host A and host B.


28. What is gratuitous ARP? When a host sends an ARP request to resolve its own IP address, it is called gratuitous ARP. In the ARP request packet, the source IP address and destination IP address are filled with the same source IP address itself. The destination MAC address is the Ethernet broadcast address (FF:FF:FF:FF:FF:FF).


29. What is the use of gratuitous ARP? Gratuitous ARP is used for the following: 1. In a properly configured network, there will not be an ARP reply for a gratuitous ARP request. But if another host in the network is also configured with the same IP address as the source host, then the source host will get an ARP reply. In this way, a host can determine whether another host is also configured with its IP address. 2. When the network interface card in a system is changed, the MAC address to its IP address mapping is changed. In this case, when the host is rebooted, it will send an ARP request packet for its own IP address. As this is a broadcast packet, all the hosts in the network will receive and process this packet. They will update their old mapping in the ARP cache with this new mapping.