We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, July 10, 2015

Interview questions and answers of .Net framwork

1.How many Languages .NET suppots?
Ans: It supports nearly more than 72 languages.

2. How Many times code is compiled in .NET?
Ans: Two Times

3. What is .NET?
A .net is a framework tool that supports many programing languages.

.NET is essentially a framework for software development. It is similar in nature to any other software development framework (J2EE etc) in that it provides a set of runtime containers/capabilities, and a rich set of pre-built functionality in the form of class libraries and APIs 

4. What is .NET frame work?
The .NET Framework is an environment for building, deploying, and running Web Services and other applications. It consists of three main parts: the Common Language Runtime, the Framework classes, and ASP.NET.

5. What are the components of .NET frame work?

Ans: 1. Common Language Runtime (CLR)
2. .Net Framework Class Library. 

6. What is CLR?
Ans: CLR provides an environment to execute .NET applications on target machines. CLR is also a common runtime environment for all .NET code irrespective of their programming language, as the compilers of respective languages in .NET Framework convert every source code into a common language known as MSIL or IL (Intermediate Language).

CLR also provides various services to execute processes, such as memory management service and security services. CLR performs various tasks to manage the execution process of .NET applications.

The responsibilities of CLR are listed as follows:
Automatic memory management
Garbage Collection
Code Access Security
Code verification
JIT compilation of .NET code

7. What is cls?
Ans: CLS is a set of basic rules, which must be followed by each .NET language to be a .NET- compliant language. It enables interoperability between two .NET-compliant languages. CLS is a subset of CTS; therefore, the languages supported by CLS can use each other's class libraries similar to their own. Application programming interfaces (APIs), which are designed by following the rules defined in CLS can be used by all .NET-compliant languag

8. What is the difference between int and int32?
Ans: There is no difference between int and int32. System.Int32 is a .NET Class and int is an alias name for System.Int32.

9. What is Lannguage Inter-operability?
Language Interoperability is the ability of code to interact with code that is written using a different programming language. Language Interoperability can help maximize code reuse and, therefore, improve the efficiency of the development process.

Microsoft intermediate language (MSIL) is the CPU-independent instruction set into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing, and calling methods on objects.

Combined with metadata and the Common Type System, MSIL allows for true cross-language integration. Prior to execution, MSIL is converted to machine code. It is not interpreted. 

10. What is the Managed code explain?
Ans: Managed code is code that can be executed and managed by .NET Framework Common Language Runtime. All codes based on the intermediate language(EL) executes as managed code.

11. What is CTS?
Ans:.Net uses the Common Type System (CTS) for Language Interoperability. CTS defines the predefined data types that are available in IL so that all languages that target the .NET framework will produce the compiled code that is ultimately based on these types. CTS ensures that a data type defined in a VB.net will be understood by C#. For example, VB.Net uses “Integer” to define the data type Integer. C# uses “int” to define the data type Integer. When VB.Net code is compiled, it will convert the Integer to Int32. Since C# refers Int to Int32, VB.Net code will be understood by C#.

12. What are Value Types explain?
ANS: Value types directly contain their data, and instances of value types are either allocated on the stack or allocated inline in a structure. Value types can be built-in (implemented by the runtime), user-defined, or enumerations.

13. What is the refrence Types?
Ans: Reference types store a reference to the value's memory address and are allocated on the heap. Reference types can be self-describing types, pointer types, or interface types. The type of a reference type can be determined from the values of self-describing types. Self-describing types are further split into arrays and class types. The class types are user-defined classes, boxed value types, and delegates. 

14. What are Boxing and Unboxing?
Ans: Converting a value type to reference type is called Boxing. Converting a reference type to value type is called Unboxing.

15. What is Heap?
Ans: Heap memory is used for reference variables whereas Stack memory is used for value types and the stack memory is deallocated as soon as the control leaves the scope whereas heap memory is allocated till it is either garbage collected or the program is terminated.

16. What is the Role of GC explain?
Ans: Implicit Garbage Collection should be handled by the .Net framework. When an object is created then it will be placed in Generation 0. The garbage collection uses an algorithm that checks the objects in the generation, the objects life time gets over then it will be removed from the memory. The two kinds of objects. One is Live Objects and Dead Objects. The Garbage collection algorithm collects all unused objects that are dead objects in the generation. If the live objects running for a long time then based on that life time it will be moved to the next generation.

The object cleaning in the generation will not take place exactly after life time over of the particular objects. It takes own time to implement the sweeping algorithm to free the spaces to the process.
The garbage collector periodically checks the heap memory to reclaim the objects when the object has no valid references in the memory.

When an object is created then it will allocate the memory in the heap then it checks the available space for the newly created objects, if the available space is not adequate to allot the space then it automatically garbage collect the unused objects. If all are valid referenced objects then it gets additional space from the processor. 

If the object has a reference with managed code objects then it will not free the memory space. However, it cannot control the reference with unmanaged code objects when application forces to collect the unused objects. But it can be achieved to write the explicit coding to avoid managed objects reference with unmanaged objects.

17. How many Generations does GC will maintain?
Ans: There are 3 generations gen 0, gen 1 and gen 2.

18. What is Automatic Memory Management?
Ans: Automatic memory management (AMM) is a technique in which an operating system or application automatically manages the allocation and deallocation of memory. This means that a programmer does not have to write code to perform memory management tasks when developing an application. Automatic memory management can eliminate common problems such as forgetting to free memory allocated to an object and causing a memory leak or attempting to access memory for an object that has already been freed. 

Garbage collection is a form of automatic memory management.

19. What is the role of JIT compiler and How many Types?
Ans: The JIT compiler is an important element of CLR, which loads MSIL on target machines for execution. The MSIL is stored in .NET assemblies after the developer has compiled the code written in any .NET-compliant programming language, such as Visual Basic and C#.

JIT compiler translates the MSIL code of an assembly and uses the CPU architecture of the target machine to execute a .NET application. It also stores the resulting native code so that it is accessible for subsequent calls. If a code executing on a target machine calls a non-native method, the JIT compiler converts the MSIL of that method into native code. JIT compiler also enforces type-safety in the runtime environment of .NET Framework. It checks for the values that are passed to parameters of any method. 

19. Explain the concept of strong names?
Ans: While using shared assemblies, in order to avoid name collisions strong names are used. Strong Names are based on private key cryptography, ie. private assemblies are simply given the same name as their main file name.

20. What is an Assembly?
Ans: Assemblies are the basic building blocks required for any application to function in the .NET realm. They have partially compiled code libraries that form the fundamental unit of deployment, versioning, activation scoping, reuse, and security. Typically, assemblies provide a collection of types and resources that work together to form a logical unit of functionality. They are the smallest deployable units of code in .NET. Compared to the executable files assemblies are far more reliable, more secure, and easy to manage. An assembly contains a lot more than the Microsoft Intermediate Language (MSIL) code that is compiled and run by the Common Language Runtime (CLR). In other words, you can say that an assembly is a set of one or more modules and classes compiled in MSIL and metadata that describes the assembly itself, as well as the functionalities of the assembly classes.

21. What is the physical location of BCL?
Ans: C/windows/Assembly

22. Differentiate between DLL and Exe?
Ans: .exe
1).EXE is Executable File
2).exe is run individually 
3).exe Has Main Function
4)Mainly is for standared alone application
.DLL
1)DLL is Dynamic Link Library
2)dll can't run individually
3)dll doesn't contain the Main Function
4)dll give support to exe

23. What is the Application Domain in .NET?
Ans: .NET Developers often need to run an external assembly. However, running an external assembly can be a risky operation as developers have no guarantee whether that external assembly will execute without any security breaches or not. Inefficient resource usage such as printers or file system from external assemblies can also create problems for applications. In .NET Framework, Microsoft provides an excellent solution to solve this problem in the form of “Application Domain”.

An application domain is a logical location in memory where a process runs. When .NET CLR executes .NET assembly it creates the main application process and then .NET developers create more small application domains to run external .NET assemblies separately then the main application process.

24. What is Manifest?
Ans: Part of the assembly which contains assembly meta data that describes the assembly itself is known as manifest. Assembly manifest contains Assembly Name, Version Number, Culture, Strong name, List of files inside the assembly and Reference information.

25. What is metadata?
Ans: Metadata in .Net is binary information that describes the characteristics of a resource. This information includes Description of the Assembly, Data Types and members with their declarations and implementations, references to other types and members, Security permissions, etc. A module's metadata contains everything that needed to interact with another module.

26. What MSIL Code?
Ans: When a program complies in .Net, the source code will be converted into an intermediate language called Microsoft Intermediate Language (MS-IL). This is done by the Just-In time Compiler (JIT). The dot net framework is built in such a way that the code is Just-In time complied, which means that it gets complied when it is called rather than compiling the entire code at the start up. A portion of the code will get complied only once and it will exist till the application exit. This will have a significant improvement in performance since the entire section of the code won't get executed in most cases.

27. Explain memory-mapped files.
Memory-mapped files (MMFs) allow you to map the content of a file to the logical address of an application. These files enable the multiple processes running on the same machine to share data with each Other. TheMemoryMappedFile.CreateFromFile() method is used to obtain a MemoryMappedFile object that represents a persisted memory-mapped file from a file on disk.

These files are included in the System.IO.MemoryMappedFiles namespace. This namespace contains four classes and three enumerations to help you access and secure your file mappings.

28. What is BCL?
Ans:The .NET framework provides a set of base class libraries that provide functions and features which can be used with any programming language which implements .NET, such as Visual Basic, C# (or course), Visual C++, etc. 

The base class library contains standard programming features such as Collections, XML, DataType definitions, IO ( for reading and writing to files), Reflection and Globalization to name a few. All of which are contained in the System namespace. As well, it contain some non-standard features such as LINQ, ADO.NET (for database interactions), drawing capabilities, forms, and web support. 

29. What is FCL?
Ans: This is also called as Base Class Library and it is common for all types of applications i.e. the way you access the Library Classes and Methods in VB.NET will be the same in C#, and it is common for all other languages in .NET. 
The following are different types of applications that can make use of .net class library. 

1. Windows Application.
2. Console Application
3. Web Application.
4. XML Web Services.
5. Windows Services.

In short, developers just need to import the BCL in their language code and use its predefined methods and properties to implement common and complex functions like reading and writing to file, graphic rendering, database interaction, and XML document manipulation.

Below are the few more concepts that we need to know and understand as part of this .Net framework. 

30. What is Reflection?
Ans: Reflection is used to dynamically load a class, create an object and invoke methods at runtime. It can also be used to read its own meta data to find assemblies, modules and type information at runtime.

31. What is a PE file?
Ans: Portable executable: -The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.

32. What is the Code Contract?
Ans: Code contracts help you to express the code assumptions and statements stating the behavior of your code in a language-neutral way. The contracts are included in the form of pre-conditions, post-conditions, and object-invariants. The contracts help you to improve-testing by enabling run-time checking, static contract verification, and documentation generation.

The System.Diagnostics.Contracts namespace contains static classes that are used to express contracts in your code.

33. What is a managed extensibility framework?
Ans: Managed extensibility framework (MEF) is a new library that is introduced as a part of .NET 4.0 and Silverlight 4. It helps in extending your application by providing greater reuse of applications and components. MEF provides a way for the host applications to consume external extensions without any configuration requirement.

34. Which method do you use to enforce garbage collection in .NET?
Ans:The System.GC.Collect() method.

35. State the differences between the Dispose() and Finalize().
Ans: CLR uses the Dispose and Finalize methods to perform garbage collection of run-time objects of .NET applications.

The Finalize method is called automatically by the runtime. CLR has a garbage collector (GC), which periodically checks for objects in heap that is no longer referenced by any object or program. It calls the Finalize method to free the memory used by such objects. The Dispose method is called by the programmer. Dispose is another method to release the memory used by an object. The Dispose method needs to be explicitly called in code to dereference an object from the heap. The Dispose method can be invoked only by the classes that implement the IDisposable interface.

36. What is code access security (CAS)?
Ans: Code access security (CAS) is part of the .NET security model that prevents unauthorized access of resources and operations, and restricts the code to perform particular tasks.

37. What are tuples?
Ans: Tuple is a fixed-size collection that can have elements of either the same or different data types. Similar to arrays, a user must have to specify the size of a tuple at the time of the declaration. Tuples are allowed to hold up from 1 to 8 elements and if there are more than 8 elements, then the 8th element can be defined as another tuple. Tuples can be specified as a parameter or return type of a method.

38. What is the Difference between NameSpace and Assembly?
Ans: Following are the differences between namespace and assembly: 

Assembly is a physical grouping of logical units, Namespace, logically groups classes.

A namespace can span multiple assemblies.

39. Mention the execution process for managed code.
Ans: A piece of managed code is executed as follows:

Choosing a language compiler
Compiling the code to MSIL
Compiling MSIL to native code
Executing the code.

40. Which is the root namespace for fundamental types in .NET Framework?
Ans: System.Object is the root namespace for fundamental types in .NET Framework.

41. What is lazy initialization?
Ans: Lazy initialization is a process by which an object is not initialized until it is first called in your code. The .NET 4.0 introduces a new wrapper class, System.Lazy<T>, for executing the lazy initialization in your application. Lazy initialization helps you to reduce the wastage of resources and memory requirements to improve performance. It also supports thread-safety.

42. What is the difference between System.String and System.StringBuilder classes?
Ans: String and StringBuilder classes are used to store string values but the difference in them is that String is immutable (read only) by nature because a value once assigned to a String object cannot be changed after its creation. When the value in the String object is modified, a new object is created, in memory, with a new value assigned to the String object. On the other hand, the StringBuilder class is mutable, as it occupies the same space even if you change the value. The StringBuilder class is more efficient where you have to perform a large amount of string manipulation.


43. What is Garbage Collector?
Garbage Collector is used in the dot net Framework for memory management. While running an application, applications make a request for memory for its internal use. Framework allocates memory from the heap. Once the process is completed, the allocated memory needs to be reclaimed for future use. The process of reclaiming unused memory is taken care of by the Garbage Collector.

44. What is the Difference between NameSpace and Assembly?
Ans: Namespace:
· Forms the logical boundary for a Group of classes.
· It is a Collection of names where each name is Unique.
· The namespace must be specified in Project Properties.

Assembly:
· Assemblies are Self-Describing
· It is an Output Unit. It is a unit of deployment and is used for versioning. Assemblies contain the MSIL code.

45. What is the Global Assembly Cache (GAC)?
Ans: While using shared assemblies, to avoid Assembly being overwritten by a different version of the same assembly, shared assemblies are placed in a special directory subtree of the file system known as the global assembly cache (GAC). Placing shared assemblies can only be done by a special .Net Utilities.

46. What is Delay signing?
To create a strongly named assembly and to make sure that this assembly can be used by someone else, we partially build this assembly by providing a Public Key. We write this Public Key in the AssemblyInfo.vb OR .cs file. We also add an attribute by the name <Assembly: AssemblyDelaySignAttribute(true)> to the assembly info file. This makes it sure that when we build the assembly, it would be containing the information only about the public key before we deliver it to our clients. This is a partial strong named assembly that we have created, and hence it is called Delayed Assembly.

47. What is the different types of jits?
Different Types of JIT are
1) Pre-JIT - Complies complete source code into native code at the time of deployment.

2) Econo-JIT - Complies methods that are called at runtime.

3) Normal-JIT - Complies methods that are called at runtime and get stored in the cache. Next time when the same method is called, it will be taken from a cache.

48. How to prevent my .NET DLL to be decompiled?
We can prevent .NET DLL to be decompiled up to an extent by Obfuscate Source code, asymmetric encryption, and encrypted w32 wrapper application.

49. What is the Native Image Generator (Ngen.exe)?
Ngen.exe creates a compiled processor-specific machine code called native images which are files and installs them into the native image cache on the local computer. The runtime will use native images from the cache rather than using the JIT compiler to compile the original assembly.

50. What is the Code Document Object Model (CodeDom)?
Code Document Object Model is code generators which are used to minimize repetitive coding tasks, and to minimize the number of human-generated source code lines.



No comments: