Monday, November 10, 2014
Why a table can have only one clustered index?
A clustered index sorts and stores the data rows in the table based on the index key values. Therefore only one clustered index can be created on each table because the data rows themselves can only be sorted in one order.
Saturday, September 27, 2014
Find the duplicate records with the help of CTE
with cte
as
(
select *,ROW_NUMBER() over (partition by EmpName order by EmpId desc) Rn
from Employee
)
select * from cte where Rn=1
as
(
select *,ROW_NUMBER() over (partition by EmpName order by EmpId desc) Rn
from Employee
)
select * from cte where Rn=1
Wednesday, August 20, 2014
Difference between Abstract Class and Interface
1. An abstract class can have abstract members as well non abstract members. Whereas in an interface all the members are implicitly abstract.
2. A class can inherit one or more interfaces, but only one abstract class. So, with the help of Interface C# support multiple inheritance.
3. Abstract class is refererence type because it's a class. In an Interface we can't say anything until then, who is going to be implement. If a class is implement it behaves like a reference type and if a structure implement, then it behaves like value type.
e.g.
interface MyName
{
void Name();
}
struct StructInterface:MyName public class clsInterface : MyName
{ {
public void Name() public void Name()
{ {
Console.Write("My Name"); Console.WriteLine("My Name");
} }
} }
4. Abstract class provide partial abstraction while Interface provide full abstraction.
5. Generally, abstract class used where, we have partially idea about the thing, that somewhere we confirm over the logic and somewhere not. But in the case of Interface we don't have any idea related the thing.
2. A class can inherit one or more interfaces, but only one abstract class. So, with the help of Interface C# support multiple inheritance.
3. Abstract class is refererence type because it's a class. In an Interface we can't say anything until then, who is going to be implement. If a class is implement it behaves like a reference type and if a structure implement, then it behaves like value type.
e.g.
interface MyName
{
void Name();
}
struct StructInterface:MyName public class clsInterface : MyName
{ {
public void Name() public void Name()
{ {
Console.Write("My Name"); Console.WriteLine("My Name");
} }
} }
4. Abstract class provide partial abstraction while Interface provide full abstraction.
5. Generally, abstract class used where, we have partially idea about the thing, that somewhere we confirm over the logic and somewhere not. But in the case of Interface we don't have any idea related the thing.
Monday, August 18, 2014
Difference between bug, error and exception
"One of the most confusing question I would say".
I have a story to simplify these three concepts:
Suppose I planned to go from India to London. Took my flight from New Delhi Airport for London. I kept in my mind the time when the flight will land in London. But when I woke-up, I was in Dubai. This is called Bug. Irrelevant result. Everything looks fine but the output is not as expected.
Second one is ERROR: When I reached the airport to take my flight, there was some problem in the Air-Bus due to which the flight got delayed. This problem is called error and without fixing it, we are not able to execute the code. We have to fix it first.
And the last one is EXCEPTION. Let's suppose when I'm in the flight, and mid-way, all the engine of the plane stopped working due to unexpected reasons but I landed safely. Common belief would be that the plane is going to be crashed but this did not happen and all the passengers are safe. This is called EXCEPTION. I'm still alive and running.
Same thing happens in a Program also. You don't come to know that some circumstances are generated in your program and by these circumstances, you believed that the program will surely crash/Stop but it did not happen. Because these exceptions are handled in our code.
For e.g. suppose a SQL Connection Exception Occurred and you don't know when your database is going to crash. By these exceptions,your program will definitely crash and a Big Yellow page will come at user's end. To manage this, we need to handle these exception in our program to run the program hassle free.
So we can say that: exception handling features provide a way to deal with any unexpected or exceptional situations that arise while a program is running.
I have a story to simplify these three concepts:
Suppose I planned to go from India to London. Took my flight from New Delhi Airport for London. I kept in my mind the time when the flight will land in London. But when I woke-up, I was in Dubai. This is called Bug. Irrelevant result. Everything looks fine but the output is not as expected.
Second one is ERROR: When I reached the airport to take my flight, there was some problem in the Air-Bus due to which the flight got delayed. This problem is called error and without fixing it, we are not able to execute the code. We have to fix it first.
And the last one is EXCEPTION. Let's suppose when I'm in the flight, and mid-way, all the engine of the plane stopped working due to unexpected reasons but I landed safely. Common belief would be that the plane is going to be crashed but this did not happen and all the passengers are safe. This is called EXCEPTION. I'm still alive and running.
Same thing happens in a Program also. You don't come to know that some circumstances are generated in your program and by these circumstances, you believed that the program will surely crash/Stop but it did not happen. Because these exceptions are handled in our code.
For e.g. suppose a SQL Connection Exception Occurred and you don't know when your database is going to crash. By these exceptions,your program will definitely crash and a Big Yellow page will come at user's end. To manage this, we need to handle these exception in our program to run the program hassle free.
So we can say that: exception handling features provide a way to deal with any unexpected or exceptional situations that arise while a program is running.
Saturday, July 26, 2014
Connect Oracle Database with Entity Framework
With lot of efforts I have found the actual ODAC and ODT driver that provide visual studio development enviroment with oracle 10g (11g latter) and database connection.
The ODAC you can downlaod from the url: http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html
Install this ODAC driver. Now when you add EDMX (Entity Framework) file then you get the
Oracle Data Provider For .Net.
Select this driver fill the datasource name, user name and password.
Now you connect with your oracle database.
The ODAC you can downlaod from the url: http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html
Install this ODAC driver. Now when you add EDMX (Entity Framework) file then you get the
Oracle Data Provider For .Net.
Select this driver fill the datasource name, user name and password.
Now you connect with your oracle database.
Thursday, July 24, 2014
Difference between == and === (equals and triple equals)
The == and === equality operator are used in JavaScript
The === sign defines that value must be equal in type as well however == not.
Example :
0==false // true
0===false // false, because they are of a different type
1=="1" // true, auto type coercion
1==="1" // false, because they are of a different type
Code Snippet:
<script type="text/javascript">
function a() {
if (1 ==='1') {
alert('true');
}
else {
alert('False');
}
}
</script>
The === sign defines that value must be equal in type as well however == not.
Example :
0==false // true
0===false // false, because they are of a different type
1=="1" // true, auto type coercion
1==="1" // false, because they are of a different type
Code Snippet:
<script type="text/javascript">
function a() {
if (1 ==='1') {
alert('true');
}
else {
alert('False');
}
}
</script>
ListBox Multi Select Option to Move Item in asp.net
Move Item from Left to Right List Box and Vice-Versa.
Code Snippet :
protected void btnRight_Click(object s, EventArgs e)
{
int[] indexes = this.lstLeftList.GetSelectedIndices();
ListItem[] items = new ListItem[indexes.Length];
for (int i = 0; i < indexes.Length; i++)
{
items[i] = this.lstLeftList.Items[indexes[i]];
}
for (int i = 0; i < items.Length; i++)
{
this.lstRightList.Items.Add(items[i]);
this.lstLeftList.Items.Remove(items[i]);
}
}
protected void btnLeft_Click(object s, EventArgs e)
{
int[] indexes = this.lstRightList.GetSelectedIndices();
ListItem[] items = new ListItem[indexes.Length];
for (int i = 0; i < indexes.Length; i++)
{
items[i] = this.lstRightList.Items[indexes[i]];
}
for (int i = 0; i < items.Length; i++)
{
this.lstLeftList.Items.Add(items[i]);
this.lstRightList.Items.Remove(items[i]);
}
}
Code Snippet :
protected void btnRight_Click(object s, EventArgs e)
{
int[] indexes = this.lstLeftList.GetSelectedIndices();
ListItem[] items = new ListItem[indexes.Length];
for (int i = 0; i < indexes.Length; i++)
{
items[i] = this.lstLeftList.Items[indexes[i]];
}
for (int i = 0; i < items.Length; i++)
{
this.lstRightList.Items.Add(items[i]);
this.lstLeftList.Items.Remove(items[i]);
}
}
protected void btnLeft_Click(object s, EventArgs e)
{
int[] indexes = this.lstRightList.GetSelectedIndices();
ListItem[] items = new ListItem[indexes.Length];
for (int i = 0; i < indexes.Length; i++)
{
items[i] = this.lstRightList.Items[indexes[i]];
}
for (int i = 0; i < items.Length; i++)
{
this.lstLeftList.Items.Add(items[i]);
this.lstRightList.Items.Remove(items[i]);
}
}
What is the difference between Server.Transfer and Response.Redirect?
Response.Redirect involves a round-trip to
the server whereas Server.Transfer conserves server resources by
avoiding the round-trip. It just changes the focus of the web-server to a
different page and transfers the page processing to a different page.
Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
Response.Redirect changes the url in the browser. Whereas Server.Transfer retains the original url in the browser. It just replaces the contents of the previous page with the new one.
Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
Response.Redirect changes the url in the browser. Whereas Server.Transfer retains the original url in the browser. It just replaces the contents of the previous page with the new one.
What are functional and non-functional requirements?
Functional
requirements defines the behaviour of a system whereas non-functional
requirements specify how the system should behave; in other words they
specify the quality requirements and judge the behaviour of a system.
Example :
Functional - Display a chart which shows the maximum number of products sold in a region.
Non-functional – The data presented in the chart must be updated every 5 minutes.
Thursday, July 3, 2014
Abstraction, Encapsulation, and Information Hiding
I was in some interview and interviewer ask me the question to differentiate these terms of OOPs Abstraction, Encapsulation, and Information Hiding.
But at that time I'm not able to give the accurate information and differentiation with these terms.
Then, I was curious. I decided to gather a number of different definitions for abstraction, information hiding, and encapsulation, and to compare them. This article details what I found.
But at that time I'm not able to give the accurate information and differentiation with these terms.
Then, I was curious. I decided to gather a number of different definitions for abstraction, information hiding, and encapsulation, and to compare them. This article details what I found.
ABSTRACTION
"A view of a problem that extracts the essential information
relevant to a particular purpose and ignores the remainder of
the information." -- [IEEE, 1983]
"The essence of abstraction is to extract essential properties while omitting inessential details."
-- [Ross et al, 1975]
"An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer."
-- [Booch, 1991]
One point of confusion regarding abstraction is its use as both a process and an entity. Abstraction, as a process, denotes the extracting of the essential details about an item, or a group of items, while ignoring the inessential details. Abstraction, as an entity, denotes a model, a view, or some other focused representation for an actual item. Abstraction is most often used as a complexity mastering technique. For example, we often hear people say such things as: "just give me the highlights" or "just the facts, please." What these people are asking for are abstractions.
We can have varying degrees of abstraction, although these "degrees" are more commonly referred to as "levels." As we move to higher levels of abstraction, we focus on the larger and more important pieces of information (using our chosen selection criteria). Another common observation is that as we move to higher levels of abstraction, we tend to concern ourselves with progressively smaller volumes of information, and fewer overall items. As we move to lower levels of abstraction, we reveal more detail, typically encounter more individual items, and increase the volume of information with which we must deal.
We also note that there are many different types of abstraction, e.g., functional abstraction, data abstraction, process abstraction, and even object abstraction.
"The essence of abstraction is to extract essential properties while omitting inessential details."
-- [Ross et al, 1975]
"An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer."
-- [Booch, 1991]
One point of confusion regarding abstraction is its use as both a process and an entity. Abstraction, as a process, denotes the extracting of the essential details about an item, or a group of items, while ignoring the inessential details. Abstraction, as an entity, denotes a model, a view, or some other focused representation for an actual item. Abstraction is most often used as a complexity mastering technique. For example, we often hear people say such things as: "just give me the highlights" or "just the facts, please." What these people are asking for are abstractions.
We can have varying degrees of abstraction, although these "degrees" are more commonly referred to as "levels." As we move to higher levels of abstraction, we focus on the larger and more important pieces of information (using our chosen selection criteria). Another common observation is that as we move to higher levels of abstraction, we tend to concern ourselves with progressively smaller volumes of information, and fewer overall items. As we move to lower levels of abstraction, we reveal more detail, typically encounter more individual items, and increase the volume of information with which we must deal.
We also note that there are many different types of abstraction, e.g., functional abstraction, data abstraction, process abstraction, and even object abstraction.
INFORMATION HIDING
"The technique of encapsulating software design decisions in
modules in such a way that the module's interfaces reveal little
as possible about the module's inner workings; thus each module is
a 'black box' to the other modules in the system." -- [IEEE, 1983]
"... the purpose of hiding is to make inaccessible certain details that should not affect other parts of a system."
-- [Ross et al, 1975]
"... the purpose of hiding is to make inaccessible certain details that should not affect other parts of a system."
-- [Ross et al, 1975]
ENCAPSULATION
"It is a simple, yet reasonable effective, system-building
tool. It allows suppliers to present cleanly specified
interfaces around the services they provide. A consumer has full
visibility to the procedures offered by an object, and no visibility
to its data. From a consumer's point of view, and object is a
seamless capsule that offers a number of services, with no
visibility as to how these services are implemented ... The
technical term for this is encapsulation." -- [Cox, 1986]
"The concept of encapsulation as used in an object-oriented context is not essentially different from its dictionary definition. It still refers to building a capsule, in the case a conceptual barrier, around some collection of things." -- [Wirfs-Brock et al, 1990]
Like abstraction, the word "encapsulation" can be used to describe either a process or an entity. As a process, encapsulation means the act of enclosing one or more items within a (physical or logical) container.
Programming languages have long supported encapsulation. For example, subprograms (e.g., procedures, functions, and subroutines), arrays, and record structures are common examples of encapsulation mechanisms supported by most programming languages.
If encapsulation was "the same thing as information hiding," then one might make the argument that "everything that was encapsulated was also hidden." This is obviously not true. For example, even though information may be encapsulated within record structures and arrays, this information is usually not hidden (unless hidden via some other mechanism).
- Brad Cox's definition ([Cox, 1986]) allows for encapsulation to hide some information ("full visibility to the procedures offered by an object"), while hiding other information ("no visibility to its data").
At the end we can say that encapsulation is the process to wrap-up the related data. It also provide security over this wrap-up by applying access modifiers like public, protected, private etc.
"The concept of encapsulation as used in an object-oriented context is not essentially different from its dictionary definition. It still refers to building a capsule, in the case a conceptual barrier, around some collection of things." -- [Wirfs-Brock et al, 1990]
Like abstraction, the word "encapsulation" can be used to describe either a process or an entity. As a process, encapsulation means the act of enclosing one or more items within a (physical or logical) container.
Programming languages have long supported encapsulation. For example, subprograms (e.g., procedures, functions, and subroutines), arrays, and record structures are common examples of encapsulation mechanisms supported by most programming languages.
If encapsulation was "the same thing as information hiding," then one might make the argument that "everything that was encapsulated was also hidden." This is obviously not true. For example, even though information may be encapsulated within record structures and arrays, this information is usually not hidden (unless hidden via some other mechanism).
- Brad Cox's definition ([Cox, 1986]) allows for encapsulation to hide some information ("full visibility to the procedures offered by an object"), while hiding other information ("no visibility to its data").
At the end we can say that encapsulation is the process to wrap-up the related data. It also provide security over this wrap-up by applying access modifiers like public, protected, private etc.
CONCLUSIONS
Abstraction, information hiding, and encapsulation are very different,
but highly-related, concepts. One could argue that abstraction is a
technique that helps us identify which specific information should be
visible, and which information should be hidden. Encapsulation is then
the technique for packaging the information in such a way as to hide
what should be hidden, and make visible what is intended to be visible.
Tuesday, June 17, 2014
What is Interface?
Ans: Interface is the contract between programmer and technology. It Means that whatever the abstract method that a interface contain, you must override all (this is the contract).
Example:
Interface Contract
{
void ContractHere();
}
class MakeContract : Contract
{
void ContractHere()
{
Console.WriteLine("Contract Override Successfully");
}
}
Example:
Interface Contract
{
void ContractHere();
}
class MakeContract : Contract
{
void ContractHere()
{
Console.WriteLine("Contract Override Successfully");
}
}
Why constructor is not inherit?
Inheritance said - only property and behaviour are inherited, and constructor is not a behaviour and not a property so that it is not inherited.
Difference between entity and object
Million Dollar Question. Differentiate entity and object.
Entities define the schema of an object but not the behaviour of the object.
An entity has intrinsic identity while value objects is solely defined by the values of its properties.
We can also say that the abstract concept and the different representation are all entity(with their intrinsic identity). Here the representation refer to abstract concept.
But when we are come to object we are in consciousness.
Lets take an Example of Entity Framework in .Net,
where the database table is mapped through the entity and we can access the particular table by using the Object of these entity.
We also say that, an entity can be object but object can not be entity. Object usually refers to in memory data structures while entity is an abstract concept.
An Object has:
1. Identity - a name
2. State - determined by the values of its attributes
3. Behavior - determined by how the object acts or reacts to requests (messages) from other objects
An Entity Example:
1. Entity: Course
2. Properties: Name, Location, Days Offered, Credit Hours, Professor
Entities define the schema of an object but not the behaviour of the object.
An entity has intrinsic identity while value objects is solely defined by the values of its properties.
We can also say that the abstract concept and the different representation are all entity(with their intrinsic identity). Here the representation refer to abstract concept.
But when we are come to object we are in consciousness.
Lets take an Example of Entity Framework in .Net,
where the database table is mapped through the entity and we can access the particular table by using the Object of these entity.
We also say that, an entity can be object but object can not be entity. Object usually refers to in memory data structures while entity is an abstract concept.
An Object has:
1. Identity - a name
2. State - determined by the values of its attributes
3. Behavior - determined by how the object acts or reacts to requests (messages) from other objects
An Entity Example:
1. Entity: Course
2. Properties: Name, Location, Days Offered, Credit Hours, Professor
Subscribe to:
Comments (Atom)
