SQL questions:

1. What is normalization? Explain normalization types.
o Normalization is the process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating two factors: redundancy and inconsistent dependency.
First Normal Form
• Eliminate repeating groups in individual tables.
• Create a separate table for each set of related data.
• Identify each set of related data with a primary key.
Second Normal Form
• Create separate tables for sets of values that apply to multiple records.
• Relate these tables with a foreign key.
Third Normal Form
• Eliminate fields that do not depend on the key.

2. What is demoralization and when would you go for it?
o Demoralization is the reverse process of normalization. It is the controlled introduction of redundancy into the database design. It helps to improve the query performance as the number of joins could be reduced.

3. What is a database index? What is the difference between a clustered and non-clustered index.
o Indexes in SQL Server are similar to the indexes in books. They help SQL Server to retrieve the data quicker. Indexes are of two types. Clustered indexes and non-clustered indexes. When you create a clustered index on a table, all the rows in the table are stored in the order of the clustered index key. So, there can be only one clustered index per table. Non-clustered indexes have their own storage separate from the table data storage.

4. What is the disadvantage of creating an index in every column of a database table?
o If we create an index on each column of a table, it improves the query performance, as the query optimizer can choose from all the existing indexes to come up with an efficient execution plan. At the same time, data modification operations (such as INSERT, UPDATE, DELETE) will become slow, as every time data changes in the table, all the indexes need to be updated. Another disadvantage is that, indexes need disk space, the more indexes you have, more disk space is used.

5. How do you implement one-to-one, one-to-many and many-to-many relationships while designing tables?
o One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships.
One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships.
Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.(It requires at least three table.The third table serves to join two tables).

6. What's the difference between a primary key and a unique key?
o Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow Nulls, but unique key allows one NULL only.

7. What is bit datatype and what's the information that can be stored inside a bit column?
o Bit datatype is used to store Boolean information like 1 or 0 (true or false). Until SQL Server 6.5 bit datatype could hold either a 1 or 0 and there was no support for NULL. But from SQL Server 7.0 onwards, bit datatype can represent a third state, which is NULL.

8. Define candidate key, alternate key, and composite key.
o A candidate key is one that can identify each row of a table uniquely. Generally a candidate key becomes the primary key of the table. If the table has more than one candidate key, one of them will become the primary key, and the rest are called alternate keys.
A key formed by combining at least two or more columns is called composite key.

9. What are defaults? Is there a column to which a default can't be bound?
o A default is a value that will be used by a column, if no value is supplied to that column while inserting data. IDENTITY columns and timestamp columns can't have defaults bound to them.

10. Explain different isolation levels
o An isolation level determines the degree of isolation of data between concurrent transactions. The default SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read, and Serializable.

11. What's the difference between DELETE TABLE and TRUNCATE TABLE commands?
o DELETE TABLE is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the deallocation of the data pages of the table, which makes it faster.

12. What are constraints? Explain different types of constraints.
o Constraints enable the RDBMS enforce the integrity of the database automatically, without needing you to create triggers, rule or defaults.
Types of constraints: NOT NULL, CHECK, UNIQUE, PRIMARY KEY, FOREIGN KEY

13. What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?
o Cursors allow row-by-row processing of the result sets.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven.
o Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip; where as a normal SELECT query makes only one roundtrip, however large the result set is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Further, there are restrictions on the SELECT statements that can be used with some types of cursors.

14. What is a join and explain different types of joins.
o Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.

15. What are triggers? How many triggers you can have on a table? How to invoke a trigger on demand?
o Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table. From SQL Server 7.0 onwards, you could create multiple triggers per each action. But in 7.0 there's no way to control the order in which the triggers fire. In SQL Server 2000 you could specify which trigger fires first or fires last using sp_settriggerorder. Triggers can't be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.

16. If two tables have a many-many relationship how will you resolve it.
o Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.

17. What is an advantage to using a stored procedure as opposed to passing an SQL query from an application?
o A stored procedure is pre-loaded in memory for faster execution. It allows the DBMS control of permissions for security purposes. It also eliminates the need to recompile components when minor changes occur to the database.

18.
What language is used by a relational model to describe the structure of a database?
o DDL,VDL,SDL

General OOp

1. Differentiate between Overriding and Overloading

o overloaded methods can have the same name but must have different parameter lists

o parameter lists are considered different if the order of the arguments are different

o a subclass method can overload a super class method

o a subclass can override methods in it's super class and change it's implementation

o it must have the same return type, name, and parameter list and can only throw exceptions of the same class/subclass as those declared in the original method

2. Can you have an overloaded function that is different only in its return value

I.e. all parameters are the same but the return value is different (look for answer in the above question)


3. How do you call a method on the parent class from the inherited class (C#, Java)

Public override void DrawWindow ( )

{

base.DrawWindow ( ); // invoke the base method

Console.WriteLine (“Writing string to the listbox: {0}",

ListBoxContents);

}

4. Can you explain Polymorphism

Polymorphism: is a feature of OOP that at run time depending upon the type of object the appropriate method is called. Method overloading is the primary way polymorphism is implemented.


5. Can you explain what inheritance is and an example of when you might use it?

Is a feature of OOP that represents the "is a" relationship between different objects (classes). Say in real life a manager is an employee. So in OOPL manger class is inherited from the employee class.


6. What is an Interface? What are the difference between an Interface and an abstract class?

An Abstract class declaration has at least one instance method that is declared abstract which will be implemented by the subclasses. An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior.


7. What is a virtual method?

When an instance method declaration includes a virtual modifier, that method is said to be a virtual method. In a virtual method invocation, the run-time type of the instance for which that invocation takes place determines the actual method implementation to invoke.

  1. What do you mean by static methods:

By using the static method there is no need creating an object of that class to use that method. We can directly call that method on that class. For example, say class A has static function f (), then we can call f () function as A.f (). There is no need of creating an object of class A.

9. What are design patterns? In what ways do designs patterns help build better software?

o Design patterns help software developers to reuse successful designs and architectures. It helps them to choose design alternatives that make a system reusable and avoid alternatives that compromise reusability through proven techniques as design patterns.

10. What is Encapsulation?

-Hiding data within the class and making it available only through the methods. This technique is used to protect your class against accidental changes to fields, which might leave the class in an inconsistent state.

- a tightly encapsulated object hides all it's variables and provides public accessor methods ie the only way you can use the object is by invoking it's public methods

  1. What are the most common techniques for reusing functionality in object-oriented systems?

o -The two most common techniques for reusing functionality in object-oriented systems are class inheritance and object composition.

    • -Class inheritance lets you define the implementation of one class in terms of another's. Reuse by sub classing is often referred to as white-box reuse.
      Object composition is an alternative to class inheritance. Here, new functionality is obtained by assembling or composing objects to get more complex functionality. This is known as black-box reuse.

Dot Net Framework

1. What is .NET Framework?
Dot Net Framework is an environment for building, running, deploying Web Applications, Desktop Applications & Web services. Dot Net Framework is an API for building applications on windows.

The .NET Framework has two main components: Common Language Runtime (CLR) and Framework Class Library (FCL).
CLR is an agent that manages code at execution time, providing core services such as memory management, thread management, remoting, code verification, compilation, and other system services, also enforcing strict type safety.
FCL is an Object-Oriented collection of reusable types that we can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET such as Web Forms and XML Web services.

2. What are CLR, CTS, and CLS?
The .NET Framework provides a runtime environment called the Common Language Runtime or CLR (similar to the Java Virtual Machine or JVM in Java) which handles the execution of code and provides useful services for the implementation of the program.
The managed code that targets CLR benefits from useful features such as cross-language integration, cross-language exception handling, versioning, enhanced security, deployment support and debugging.

Common Type System (CTS) describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety and high performance code execution.
The CTS Specification defines all possible Datatypes and Programming constructs supported by the CLR and how they may or may not interact with each other. Because of this feature, the .NET Framework supports development in multiple programming languages.

Common Language Specification(CLS) is simply a specification that defines the rules to support language integration in such a way that programs written in any language can interoperate with one another taking full advantage of inheritance, polymorphism, exceptions and other features.

What is common language Specification?What is difference between CTS and CLS?
The Common Language Specification (CLS) describes a set of features that different languages have in common.
The CLS includes a subset of the Common Type System (CTS).
The CTS defines the rules concerning data types.
Any program which uses CLS-compliant types can interoperate with any .NET program written in any language.
C# supports both CLS and CTS.


3. Is .NET a runtime service or a development platform?
Ans: It's both. .NET framework’s SDK consists of two parts: the .NET common language runtime and the .NET class library. SDK also includes command-line compilers for C#, C++, JScript, and VB. We use these compilers to build applications and components. These components require the runtime to execute so .Net is development and runtime platform.

4. What is MSIL?
While compiling 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.
Microsoft intermediate language (MSIL) is 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.
Can I do things in IL that I can't do in C#?
Yes. A couple of simple examples are that we can throw exceptions that are not derived from System.Exception and can have non-zero-based arrays.

5. What is strong name?
A name that consists of an assembly's identity which includes text name, version number, and culture information (if provided).

6. What is portable executable (PE)?
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.

7. Which namespace is the base class for .net Class library?
Ans: system.object

8. 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.

9. What are the contents of assembly?
In general, a static assembly can consist of four elements:
1. The assembly manifest, which contains assembly metadata.
2. Type metadata.
3. Microsoft intermediate language (MSIL) code that implements the types.
4. A set of resources.

10. What are the different types of assemblies?
Private, Public/Shared, Satellite

11. What is serialization in .NET? What are the ways to control 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 during remoting. Serialization can be defined as the process of storing an object’s state to a storage medium. During this process, public and private fields of the object, name of the class, including the assembly containing the class are converted to a stream of bytes which is then written to a data stream. When the object is deserialized, an exact clone of the original object is created.
• Binary serialization preserves type fidelity, which is useful for preserving the state of an object.
• XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when we want to provide or consume data without restricting the application that uses the data.
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.

12. Define Assembly. How many types of assemblies are there?
Assembly is a collection of compiled or executable components which is versioned and deployed as single implementation unit.
Assemblies are the fundamental unit of deployment, version control, reuse and security permissions for a .NET-based application. Assemblies take the form of an executable (.exe) file or dynamic link library (.dll) file, and are the building blocks of the .NET Framework.
All managed types and resources are contained within an assembly and are marked either as accessible only within the assembly or as accessible from code in other assemblies.
Assemblies can be static or dynamic. Static assemblies can include .NET Framework types (interfaces and classes), as well as resources for the assembly (bitmaps, JPEG files, resource files, and so on). Static assemblies are stored on disk in PE files. You can also use the .NET Framework to create dynamic assemblies, which are run directly from memory and are not saved to disk before execution. You can save dynamic assemblies to disk after they have executed.

Assemblies are of three types
1. Private assembly- can be accessed only by single application and is stored in the application's directory
2. Shared assembly-can be accessed by multiple applications in a system and is stored in the global assembly cache.
3. Satellite assemblies- are used to deploy language-specific resources for an application and are stored in a language-specific subdirectory for each language.

13. In .NET Compact Framework, can I free memory explicitly without waiting for garbage collector to free the memory?
Yes, you can clear the memory using gc.collect method but it is recommended that u should not call this coz we don’t know the exact time when the GC will be called automatically.
In Dot net u cannot explicitly call a garbage collector; it can be called through CLR.

14. How can I change private assembly to shared assembly?
Yes, you can change from Private to Shared.
- Get the SN using sn.exe?
- Add the SN to the Assembly
- Put the Assembly in GAC.

16. How many classes can a single .NET DLL contain?
Unlimited

18. What is a Manifest?
Manifest describes the assembly itself, providing the logical attributes shared by all the modules and components in an assembly.
The manifest contains the assembly name, version number, locale and an optional strong name that uniquely identifies the assembly. This manifest information is used by the CLR.

19. What is a Metadata?
Metadata is used to describe other data. Data definitions are sometimes referred to as metadata. Examples of metadata include schema, table, index, view and column definitions.

Metadata is information stored in the assembly that describes the types and methods of the assembly and provides other useful information about the assembly. Assemblies are said to be self-describing because the metadata fully describes the contents of each module.

20. What is a Strong Name?
A strong name is a way to ensure that a shared assembly's name does not conflict with another shared assembly.
A strong name contains assembly name, a public key and a private key.
For installing an assembly into GAC you need to give it a strong name. First generate a key pair using 'sn.exe' command line utility and write the key file name as AssemblyKeyFileAttribute in a code file of the assembly.

21. Creating a Key Pair
To create a key pair uses the dot net command line tool sn.exe
sn.exe -k mykey.snk
This filename is used as the attribute value for AssemblyKeyFileAttribute in one of the code files of assembly. It generates a strong named assembly which could be installed into the GAC.

22. What is GAC?
GAC stands for Global Assembly Cache. It is used for storing shared assemblies. It stores all versions of a particular assembly so that on updating an assembly the existing applications which use the earlier version do not break.
For storing an assembly into the GAC you need to sign the assembly with a strong name. For this purpose follow these steps:
1. Use sn.exe command line utility to generate a key pair
2. Add the key file name to the assembly as value for AssemblyKeyFileAttribute.
3. Build the assembly.
4. Use gacutil.exe -i command on the command prompt to install it in the cache.

23. What is Reflection?
Reflection is a namespace in .net which allows you to access metadata for loaded types and objects.
It also allows you to create new types and their objects at runtime.
Reflection is the process by which a program can read its own metadata or metadata from another program. A program is said to reflect on itself or on another program, extracting metadata from the reflected assembly and using that metadata either to inform the user or to modify the program's behavior.
For the attributes in the metadata to be useful, you need a way to access them, ideally during runtime. The classes in the Reflection namespace, along with the System.Type class, provide support for examining and interacting with the metadata.
Reflection is generally used for any of four tasks.

Viewing metadata
This might be used by tools and utilities that wish to display metadata.

Performing type discovery
This allows you to examine the types in an assembly and interact with or instantiate those types. This can be useful in creating custom scripts. For example, you might want to allow your users to interact with your program using a script language, such as JavaScript, or a scripting language you create yourself.

Late binding to methods and properties
This allows the programmer to invoke properties and methods on objects dynamically instantiated, based on type discovery. This is also known as dynamic invocation.

Creating types at runtime (reflection emit)
The ultimate use of reflection is to create new types at runtime and then to use those types to perform tasks. You might do this when a custom class, created at runtime, will run significantly faster than more generic code created at compile time.

24. What are Attributes?

Attributes are part of metadata for a class.
Attributes are used to specify assembly information like key file name, or for specifying security related information. You can create new attributes for your specific needs or ideas.
Attributes are a mechanism for adding metadata, such as compiler instructions and other data about your data, methods, and classes, to the program itself. Attributes are inserted into the metadata and are visible through ILDasm and other metadata- reading tools.

25. When is Marshalling not necessary?
Marshalling is the process of packaging and sending interface method parameters across thread, process or machine boundaries.
When Ever component runs with in client App Domain process then marshalling is not necessary. Marshalling is nothing but gathering or packaging the information into message for transferring across the network required in distributed environment.

26. What is JIT (just in time)? How it works?
When Assembly is executed for the first time on a new computer,the IL will be compiled into machine language optimized for the machine's language which is called as JIT(Just-In-Time Compilation).

27. What is Application Domain?

The primary purpose of the AppDomain is to isolate an application from other applications. Win32 processes provide isolation by having distinct memory address spaces.
All memory in the AppDomain is managed by the .NET runtime, so the runtime can ensure that AppDomains do not access each other's memory.

Objects in different application domains communicate either by transporting copies of objects across application domain boundaries, by using a proxy to exchange messages.

MarshalByRefValue When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries.


MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy.


28. What is the managed and unmanaged code in .net?

Code that you develop with a language compiler that targets the runtime is called managed code; it benefits from features such as cross-language integration, cross-language exception handling, enhanced security, versioning and deployment support.

29. How do you create threading in .NET? What is the namespace for that?
System.Threading.Thread
30. Describe the Managed Execution Process?
> Choosing a compiler.
> Compiling your code to Microsoft intermediate language (MSIL).
> Compiling MSIL to native code.
> Executing your code.

31. What are Namespaces?
The namespace keyword is used to declare a scope. This namespace scope lets us organize code and gives you a way to create globally-unique types. Even if you do not explicitly declare one, a default namespace is created.