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.

SQL Server 2000

Databases

A database is a storage place for data. For most types of data files, a database does not present information directly to a user; rather, the user runs an application that accesses data from the database and presents it to the user in an understandable format.

Relational Databases

Although there are different ways to organize data in a database, a relational database is one of the most effective systems. A relational database system uses mathematical set theory to effectively organize data. In a relational database, data is collected into tables (called relations in relational database theory).

Table: A two-dimensional object consisting of rows and columns that is used to store data in a relational database. Each table stores information about one of the types of objects modeled by the database. For example, an education database might have one table for teachers, a second for students, and a third for classes.

Functions

A function encapsulates frequently performed logic in a subroutine made up of one or more Transact-SQL statements. Any code that must perform the logic incorporated in a function can call the function rather than having to repeat all of the function logic.

SQL Server2000 supports two types of functions:

Built-in functions. These functions operate as defined in Transact-SQL and cannot be modified. The functions can be referenced only in Transact-SQL statements.

User-defined functions. These functions enable you to define your own Transact-SQL functions by using the CREATE FUNCTION statement.

Built-In Functions

The Transact-SQL programming language contains three types of built-in functions: rowset, aggregate, and scalar.

Data Types

A data type is an attribute defining the type of data that an object can contain. Columns, parameters, variables, functions that return data values and stored procedures that have a return code all have data types. Transact-SQL includes a number of base data types, such as varchar, text, and int.

Types of User-Defined Functions

The Transact-SQL programming language supports two types of user-defined functions: scalar and table.

Scalar Functions.

Scalar functions return a single data value of the type defined in a RETURNS clause. You can use all scalar data types, including bigint and sql_variant. The timestamp data type, user-defined data type, and non-scalar types (such as table or cursor) are not supported. The body of the function, defined in a BEGIN...END block, contains the series of Transact-SQL statements that return the value. The return type can be any data type except text, ntext, image, cursor, and timestamp.

Table Functions

Table functions return a table. There are two types of table functions: inline and multi-statement. For an inline table function, there is no function body; instead, the table is the result set of a single SELECT statement. For a multi-statement table function, the function body, defined in a BEGIN...END block, contains the Transact-SQL statements that build and insert rows into the table that will be returned.

Inner join: The INNER JOIN returns all rows from both tables where there is a match. If there are rows in Employees that do not have matches in Orders, those rows will not be listed.

Left join: The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows also will be listed.

Right join: The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employees). If there had been any rows in Orders that did not have matches in Employees, those rows also would have been listed.

Outer join: it may be desirable to include rows from one table even if it does not have matching rows in the other table. This is done by the use of an OUTER JOIN. OUTER JOINs are used when we want to keep all the rows from the one table, such as Course, or all the rows from the other, regardless of whether they have matching rows in the other table.

Indexers:

It is the job of the query optimizer to determine which indexes will be the most useful in processing a specific query. Although indexes may speed up queries in large tables, indexes will slow update operations (insert, delete, update), because every update causes a rebuild of the index. We begin by introducing the "simple" CREATE INDEX statement.

Stored procedure: A stored procedure is a group of Transact-SQL statements that is compiled one time and that can then be executed many times. This functionality increases performance when the stored procedure is executed because the Transact-SQL statements do not have to be recompiled.

CREATE PROCEDURE sp_GetInventory
@location varchar (10)
AS
SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = @location

EXECUTE sp_GetInventory 'FL'

Triggers: A trigger is a special type of stored procedure that a user does not call directly. When the trigger is created, it is defined to execute when a specific type of data modification is made against a specific table or column.

Why triggers? – to extend data integrity and to implement complex business logic.

Two classes of triggers:

1) Instead of – this bypass the triggering action and run in their place.

2) After

– default trigger class

– After trigger fire as a supplement to the triggering actions.

– Move then one allowed on a table.

Syntax:

Create Trigger trigger_name

ON table_name or view_name

FOR trigger_class and trigger_types

AS T-SQL statement

Constraints

Constraints enable us to define the way that SQL Server automatically enforces the integrity of a database. Constraints define rules regarding the values allowed in columns and are the standard mechanism for enforcing integrity. Using constraints is preferred to using triggers, rules, or defaults.

A constraint is a property assigned to a column or the set of columns in a table that prevents certain types of inconsistent data values from being placed in the column(s). Constraints are used to enforce the data integrity. This ensures the accuracy and reliability of the data in the database. The following categories of the data integrity exist:

· Entity Integrity

· Domain Integrity

· Referential integrity

· User-Defined Integrity

· Entity Integrity ensures that there are no duplicate rows in a table.

Domain Integrity enforces valid entries for a given column by restricting the type, the format, or the range of possible values.
Referential integrity ensures that rows cannot be deleted, which are used by other records (for example, corresponding data values between tables will be vital).
User-Defined Integrity enforces some specific business rules that do not fall into entity, domain, or referential integrity categories.

Each of these categories of the data integrity can be enforced by the appropriate constraints. Microsoft SQL Server supports the following constraints:

· PRIMARY KEY

· UNIQUE

· FOREIGN KEY

· CHECK

· NOT NULL

Rules

Rules are a backward-compatibility feature that performs some of the same functions as CHECK constraints. CHECK constraints are the preferred, standard way to restrict the values in a column. CHECK constraints are also more concise than rules; there can be only one rule applied to a column, but multiple CHECK constraints can be applied. CHECK constraints are specified as part of the CREATE TABLE statement, while rules are created as separate objects and are then bound to the column.

User Defined functions:

A Scalar user-defined function returns one of the scalar data types. Text, ntext, image and timestamp data types are not supported. These are the type of user-defined functions that most developers are used to in other programming languages. You pass in 0 to many parameters and you get a return value. Below is an example that is based in the data found in the NorthWind Customers Table.

CREATE FUNCTION whichContinent
(@Country nvarchar(15))
RETURNS varchar(30)
AS
BEGIN
declare @Return varchar(30)
select @return = case @Country
when 'Argentina' then 'South America'
when 'Belgium' then 'Europe'
when 'Brazil' then 'South America'
when 'Canada' then 'North America'
when 'Denmark' then 'Europe'
when 'Finland' then 'Europe'
when 'France' then 'Europe'
else 'Unknown'
end

return @return
end

Index: INDEX is used to create a new index on some column in an existing table. The following is the general syntax for the CREATE INDEX statement:

CREATE INDEX index_name
ON Table_name (column [ASC | DESC])
 
There are clustered and nonclustered indexes.
A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.

A nonclustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a nonclustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.


Views:

A database object that can be referenced the same way as a table in SQL statements. Views are defined by using a SELECT statement and are analogous to an object that contains the result set of this statement.

Data type:

An attribute that specifies what type of information can be stored in a column, parameter, or variable. SQL Server provides system-supplied data types; you can also create user-defined data types.

Union:

The UNION command is used to select related information from two tables, much like the JOIN command.

Drop Index

You can delete an existing index in a table with the DROP INDEX statement.

Connection Pooling:

Connection pooling is the ability of re-use your connection to the Database. This means if you enable Connection pooling in the connection object, actually you enable the re-use of the connection to more than one user.

The connection pooling is enabled by default in the connection object. If you disable the connection pooling, this means the connection object which you create will not be re-used to any other user than who create that object.

SqlConnection testConnection = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=DEMO;Integrated Security=SSPI;");

long startTicks = DateTime.Now.Ticks;

for (int i = 1; i <= 100; i++)

{

testConnection.Open();

testConnection.Close();

}

long endTicks = DateTime.Now.Ticks;

Console.WriteLine("Time taken : " + (endTicks - startTicks) + " ticks.");

testConnection.Dispose();

Object Pooling:

Object pools (otherwise known as resource pools) are used to manage the object caching. A client with access to a Object pool can avoid creating a new Objects by simply asking the pool for one that has already been instantiated instead. Generally the pool will be a growing pool, i.e. the pool itself will create new objects if the pool is empty, or we can have a pool, which restricts the number of objects created.

It is desirable to keep all Reusable objects that are not currently in use in the same object pool so that they can be managed by one coherent policy. To achieve this, the Reusable Pool class is designed to be a singleton class.

Object Pooling is a service that is defined as "A performance optimization based on using collections of pre-allocated resources, such as objects or database connections." It is also mentioned that pooling results in more efficient resource allocation.

SQL: Standard computer language for accessing and manipulating database systems.

DML (Data Manipulation Language): select, update, delete & insert into.

DDL (Data Definition Language): Create table, alter table, drop table, create index, drop index/
IN: used when exact value we want to return for at least are of the column.

The SqlCommand class provides three main methods:

·ExecuteNonQuery Executes the command and returns the number of rows affected by the statement.

· ExecuteScalar Executes the command and returns a single value.

· ExecuteReader Builds a SqlDataReader that can be used to read a set of records.