Pages

Saturday, August 6, 2011

HttpCookieMode enumerations

Tuesday, July 5, 2011

Design Principles

SOLID Principles:
SRP:(single responsibility principle)
OCP:(Open Close Principle)
LSP: (Liskov substitution principle - Design By Contract)
ISP:(Interface-segregation principle)
DIP:(Dependency inversion principle)

Inheritance --> is - a
Composition --> part - of
Aggregation --> has - a

Saturday, July 2, 2011

LINQ


Aggregate
Conversion
Ordering
Partitioning
Sets
Aggregate
Cast
OrderBy
Skip
Concat
Average
OfType
ThenBy
SkipWhile
Distinct
Count
ToArray
Descending
Take
Except
Max
ToDictionary
Reverse
TakeWhile
Intersect
Min
ToList


Union
Sum
ToLookup




ToSequence



Sunday, June 5, 2011

Ajax Frameworks Types

Ajax Frameworks Types
Client Side vs. Server Side Frameworks
 
Two types of Ajax based frameworks used in the web programming nowadays: 
1. Server-side Framework 
2. Client-side Framework. 

Server-side framework is where the code executed on the Web server is considered as Server-side code  and it is installed inside the server.

Client-side framework is where code is executed on the user’s browse.

Internet is an extremely wide area and because of this both the server-side and client –side programmers may not be in the contact and performs their work separately. Both the server-side and client-side functions differently and the code used in the frameworks also varies. The code of both the frameworks has its own pros and cons that suite to different sorts of developers.

Now the question arises, what is the Server-side framework and what is Client-side? In this article, you will get the answer of both these queries. You will also learn about what are the advantages and disadvantages of both these frameworks.

Server Side Framework
The framework that is installed inside the server is known as Server-side framework. The coding of server-side framework is actually not created in JavaScript but it is the same language that API provided for server-side framework. So, it is not mandatory for the developers to be skilled in JavaScript for server-side framework programming. Nearby all the frameworks in server-side accepts the coding of developers and automatically translates it into Ajax when user accesses the website.
Server-side framework can also be used for installing the specific functions from the library to translate and accessed effectively. The server-side framework exactly provides the desired functions and the library needed for developer to render the specific buttons and information in Ajax based website. The developers have to only customize the code during creating the program. Moreover, the server-side framework responds better because it handles a large number of user communications without intervention of server.
Google Web Toolkit (GWT) might be an excellent example of server-side framework that is used as a normal Java Swing kind of programming on the server side in web pages using the GWT API. The other server side frameworks are: Yahoo, Toolkit and DWR.
Server-side framework is basically used for server server-side programming that covers password protection, browser customization, form processing and building and displaying pages created from database.

Pros and Cons of Server Side Frameworks
There is no need for the developers to learn the extra language as server-side coding can be written in the existing language in which the server-side programmer is efficient.


Client Side Framework
As opposing the server-side, Client-side framework is accessed and executes within the user’s browsers. For creating Ajax based client-side framework, developers must be efficient enough in JavaScript as well as XML. Because Ajax-based client side website is fully depended upon Ajax and it also needs to a wide range of coding for different browsers.

The different uses of framework for different browsers make the Ajax client-side programming very complex. The frameworks written for Mozilla cannot be executed in Internet Explorer if XMLHttpRequest has not been defined and implemented for the Internet explorer too.

The Request XMLHttpRequest performs like a bridge between the server and the client. The developers have to generate different coding for different platforms to perform it successfully. That’s why the developers must have the knowledge about which browser has been used by his client; otherwise the developer has to develop several customize client-side framework for running their own platforms.

Through Client-side framework, users can execute any technology that supports user’s browser. In Client-side framework, users can modify several features besides codes without sending information to web server.

In the Client-side framework, user can handle multiple asynchronous request, can detect easily error handling and exceptions and can mix and match widget facilities to get extra flexibility in the programming. (Widgets are small interfaces or components that can be integrated with an application easily through client side framework)

Client-side framework is used in online games, customizing the display without reloading the page and getting data about the user’s screen or browser. The examples of client-side framework are Prototype, DOJO Toolkit, Rico, Script.aculo.us and many more.

Pros and Cons of Client Side Frameworks

Client-side framework is more flexible than server-side due to multi-handing frameworks, easily error handling and exceptions while the adding of widgets makes it extra-flexible.

Saturday, March 12, 2011

Static Class


  1. Static Class cannot be instantiated unlike the unstatic class. You should directly access its Method via the ClassName.MethodName

  2. A Program can't tell when it is going to load static class but its definitely loaded before the call.

  3. A Static class will always have the static constructor and its called only once since after that its in the memory for its lifetime.

  4. A Static class can contain only static members. So all the members and functions have to be static.

  5. A Static class is always sealed since it cannot be inherited further. Further they cannot inherit form any other class (except Object)

Static Constructor

This is a special constructor and gets called before the first object is created of the class. The time of execution cannot be determined, but it is definitely before the first object creation - could be at the time of loading the assembly. Notes for Static Constructors:
  1. It is used to initialize static data members.
  2. Can't access anything but static members.
  3. The static constructor should be without parameters.
  4. Can't have access modifiers like Public, Private or Protected.
  5. There can be only one static constructor in the class.
  6. A class can have static as well as non static constructor without arg at same time.

The syntax of writing the static constructors is also damn simple. Here it is:

public class Sample{
    static Sample()
    {
        // Only static members are accessible.
        // Initialization code can be here.
    }
    // Other class methods goes here
}

Let us understand features step by step here.

Firstly, the call to the static method is made by the CLR and not by the object, so we do not need to have the access modifier to it.

Secondly, it is going to be called by CLR, who can pass the parameters to it, if required. So we cannot have parameterized static constructor.

Thirdly, non-static members in the class are specific to the object instance. So static constructor, if allowed to work on non-static members, will reflect the changes in all the object instances, which is impractical. So static constructor can access only static members of the class.

Fourthly, overloading needs the two methods to be different in terms of methods definition, which you cannot do with Static Constructors, so you can have at the most one static constructor in the class.

Now, one question raises here, can we have two constructors as:

public class Sample
{
    static Sample()
    {
        // Only static members are accessible.
        // Initialization code can be here.
    }
    public Sample()
    {
        // Code for the First Constructor.
    }

    // Other class methods goes here
}
This is perfectly valid, though doesn't seem to be in accordance with overloading concepts. But why? Because the time of execution of the two methods are different. One is at the time of loading the assembly and one is at the time of object creation.

Wednesday, February 16, 2011

SQL Server Q & A -1

1. How to optimize stored procedures in SQL Server?
Ans: I. Use where clause
II. Select only required fields
III. Do join on indexed key fields

2. What is the difference between Stored procedure and User defined functions?

3. Why should we go for Stored Procedures? Why not direct queries?
Ans: SP are precompiled and contain an execution plan with it. Hence, they are faster.

4. How many NULL values we can have in a Unique key field in SQL Server?
Ans: Only one. In case of Oracle, we can have multiple NULL values in a Unique key field.

5. What is correlated subquery?
6. What is an index. What are the types?
Indexes in databases are very much similar to Indexes in Books. Indexes help in searching data faster.

Types: Clustered Index
Non-Clustered Index

7. What is the difference between a clustered index and a non-clustered index?
Clustered Index:
1 Only one clustered index allowed per table
2 Physically rearranges the data
3 For use on columns that are frequently searched for range of data

Non-clustered Index:
1 Upto 249 non-clustered index allowed per table
2 Doesn’t rearrange the data. Keeps a pointer to the data.
3 For use on columns that are searched for single value.

8. What is a join? What are the types of joins?
Joins are used to retrieve data from multiple tables.
Following are the types of joins:
Inner join
Left outer join
Right outer join
Full outer join
Cross join



9. What is a transaction?
A SQL transaction is a sequence of operations performed as a single unit of work. If all the tasks are completed successfully, then the transaction is committed (saved). If a single task fails, the transaction is rolled back (discarded).

10. What is ACID property of transaction?
A SQL transaction must exhibit ACID property, i.e Atomicity, Consistency, Isolation, and Durability.

Atomicity: A transaction is always treated as a single unit of work, i.e. either all the tasks are performed or none of them, no intermediate stage.
Consistency: When a transaction is completed, it must leave all data in a consistent state.
Isolation: Modifications made by a transaction must be isolated from the modifications made by other transactions.
Durability: After a transaction is completed, it’s effects are permanently in place in the system.

11. What is SET NOCOUNT ON?
When we perform a SELECT, INSERT, UPDATE or DELETE query, it returns a COUNT (number of rows affected) when SET NOCOUNT OFF. If SET NOCOUNT ON, it doesn’t return the COUNT.

12. How to delete exactly duplicate records from a table?
There are many ways. Simplest answer is:
i. Let the table tab1 contains duplicate records.
ii. Insert distinct records from tab1 in a temporary table #temp
INSERT INTO #temp
SELECT DISTINCT * FROM tab1
iii. Delete all rows from original table tab1
DELETE FROM tab1
iv. Insert from temporary table
INSERT INTO tab1
SELECT * FROM #temp
Try other solutions yourself.

13. How to get nth highest salary from employee table.
The query below demonstrates how to find the 5th highest salary. Replace 5 with any integer to get nth salary.

SELECT TOP 1 SALARY
FROM (SELECT DISTINCT TOP 5 SALARY
FROM EMPLOYEE ORDER BY SALARY DESC) a
ORDER BY SALARY ASC