Pages

Showing posts with label FAQ or Q&A. Show all posts
Showing posts with label FAQ or Q&A. Show all posts

Thursday, August 25, 2011

FAQ or Q&A

Q: Difference between strategy pattern and factory pattern

A factory pattern is a creational pattern. A strategy pattern is an operational pattern. Put another way, a factory pattern is used to create objects of a specific type. A strategy pattern is use to perform an operation (or set of operations) in a particular manner. In the classic example, a factory might create different types of Animals: Dog, Cat, Tiger, while a strategy pattern would perform particular actions, for example, Move; using Run, Walk, or Lope strategies.
In fact the two can be used together. For example, you may have a factory that creates your business objects. It may use different strategies based on the persistence medium. If your data is stored locally in XML it would use one strategy. If the data were remote in a different database, it would use another.

Q:Difference between dependency injection and factory pattern
When using a factory your code is still actually responsible for creating objects. By DI you outsource that responsibility to another class or a framework, which is separate from your code.

Q: Returning IEnumerable vs IQueryable
The difference is that IQueryable is the interface that allows LINQ-to-SQL (LINQ.-to-anything really) to work. So if you further refine your query on an IQueryable, that query will be executed in the database, if possible.
For the IEnumerable case, it will be LINQ-to-object, meaning that all objects matching the original query will have to be loaded into memory from the database.
In code:
IQueryable custs = ...;
// Later on...
var goldCustomers = custs.Where(c => c.IsGold);
That code will execute SQL to only select gold customers. The following code, on the other hand, will execute the original query in the database, then filtering out the non-gold customers in the memory:

IEnumerable custs = ...;
// Later on...
var goldCustomers = custs.Where(c => c.IsGold);

This is quite an important difference, and working on IQueryable can in many cases save you from returning too many rows from the database. Another prime example is doing paging: If you use Take and Skip on IQueryable, you will only get the number of rows requested; doing that on an IEnumerable will cause all of your rows to be loaded in memory.
Click Here

Q: Understanding Garbage Collection in .NET
Wonderful link
http://msdn.microsoft.com/en-us/magazine/bb985010.aspx

Q protected internal
'protected internal' does not mean protected *and* internal - it means protected *or* internal. So a protected internal member is visible to any class inheriting the base class, whether it's in the same assembly or not. The member is also visible via an object declared of that type anywhere in the original assembly.

Q:What is internal set property in c#?
If you have a property with an internal set accessor (and public get accessor) it means that code within the assembly can read (get) and write (set) the property, but other code can only read it.
You can derive the above information by reading about the internal access modifier, the public access modifier and properties.
Also, you can read about Restricting Accessor Accessibility.


Q:Difference between flush() and commit()
Flushing the Session simply gets the data that is currently in the session synchronized with what is in the database. However, just because you have flushed, doesn't mean the data can't be rolled back.
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.Commit does flush the session, but it also ends the unit of work.

Difference between .Net 4.0 and .Net 3.5, 2.0


As we all know, ASP.NET 3.5 has introduced with the following main new features
1) AJAX integration
2) LINQ
3) Automatic Properties
4) Lambda expressions
I hope it would be useful for everyone to know about the differences about asp.net 3.5 and its next version asp.net 4.0
Because of space consumption I’ll list only some of them here.

1) Client Data access:

ASP.NET 3.5: There is no direct method to access data from client side. We can go for any of these methods
  1. Pagemethods of script manager
    http://randomactsofcoding.blogspot.com/2007/10/introduction-to-pagemethods.html

    2) ICallbackEventHandler interface
    http://www.codeproject.com/KB/aspnet/ICallbackEventHandler.aspx

    3) XMLHttphanlder component
ASP.NET 4.0: In this framework there is an inbuilt feature for this. Following are the methods to implement them.
1) Client data controls
2) Client templates
3) Client data context
i.e we can access the data through client data view & data context objects from client side.

2) Setting Meta keyword and Meta description:

Meta keywords and description are really useful for getting listed in search engine.
ASP.NET 3.5: It has a feature to add meta as following tag
  &ltmeta name="keywords" content="These, are, my, keywords" />
&ltmeta name="description" content="This is the description of my page" />
ASP.NET 4.0: Here we can add the keywords and description in Page directives itself as shown below.
  < %@ Page Language="C#"  CodeFile="Default.aspx.cs"   Inherits="_Default"
Keywords="Keyword1,Key2,Key3,etc"   Description="description" %>

3) Enableviewstage property for each control

ASP.NET 3.5: this property has two values “True” or “false”
ASP.NET 4.0: ViewStateMode property takes an enumeration that has three values: Enabled, Disabled, and Inherit.
Here inherit is the default value for child controls of a control.

4) Setting Client IDs

Some times ClientID property creates head ach for the programmers.
ASP.NET 3.5: We have to use ClientID property to find out the id which is dynamically generated
ASP.NET 4.0: The new ClientIDMode property is introduced to minimize the issues of earlier versions of ASP.NET.
It has following values.
AutoID – Same as ASP.NET 3.5
Static – There won’t be any separate clientid generated at run time
Predictable-These are used particularly in datacontrols. Format is like clientIDrowsuffix with the clientid vlaue
Inherit- This value specifies that a control’s ID generation is the same as its parent.

New features in ASP.net 4
http://www.simple-talk.com/dotnet/asp.net/asp.net-4.0-features/

Friday, July 15, 2011

Questions Answers

Q:Difference between Clustered and Non-Clustered Index Data Structures?

When you first create a new table, there is no index created by default. In technical terms, a table without an index is called a “heap”. As you would expect, the data we will insert into the table will be returned in the same order. A non-clustered 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 non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.
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.
Clustered index is good when you know in which order you will be returning the records in most cases. You can create clustered index and after that you don’t need to use ORDER BY statement. This will be much more faster. If the order is not important for you and will not create clustered index by yourself, then primary key will be clustered index by default. There is nothing bad not to have the clustered index, it can speed up inserting rows.
Source:- http://www.allinterview.com/showanswers/8164.html

Q:Difference between Trace and Debug ?

According to Microsoft Documentation there is not much
difference between Trace and Debug Class.

Debug only works in debug mode and trace works in debug and
release both mode.


Q:Difference between Array and ArrayList?

Array is the collection of values of the same data type
>the variables in an array is called array elements
>Array is a reference type data type
>The array structure in System's Memory

Array list is a class .
>when you want to access the elements of an array through its index value location in an array,use an ArrayList.
>The use of the arraylist is an alternative to the use of th array.
>The Methods Of ArrayList class are
1)Add
2)Remove
3)Clear
4)Insert
5)TrimToSize
6)Sort
7)Reverse

Example: http://stackoverflow.com/questions/459677/c-a-strings-split-method

Question: difference between ref and out

The main difference between the two types is in the rule for definite assignment of them.
When we use the out parameter, The program calling the function need not assign a value to the out parameter before making the call to the function. The value of the out parameter has to be set by the function before returning the value.
The same is not true for the reference (ref) type parameter. For a ref type parameter, the value to the parameter has to be assigned before calling the function. If we do not assign the value before calling the function we will get a compiler error.

Another important thing to note here is that in case of ref parameter, the value passed by the caller function can be very well used by the called function. The called function does not have the compulsion to assign the value to a ref type parameter. But in case of the out parameter, the called function has to assign a value.

Thursday, July 14, 2011

Object Oriented Programming - Concepts

Object Oriented Programming

OOP is Nothing but Object Oriented Programming.
In OOPs concept is implimented in our real life systems.
OOPs have following features
1. Object - Instance of class
2. Class - Blue print of Object
3. encapsulation - Protecting our data
4. polymorphism - Different behaviors at diff. instances
5. abstraction - Hidding our irrelavance data
6. inheritence - one property of object is aquring to
another property of object

Simple Ex.
Please assume u standing near a car.
How to impliments our OOPs concept for this scenario ?
Simple,
car is a object b'coz it having more functions.
car is a class b'coz it contain more parts and features inside.
car is a Encapsulation B'coz it protected some unwanted parts or
functions to user car is a Polymorphism b'coz it have different
speed as display in same speedometer car is a Abstraction b'coz
it hidding more parts by coverig such as engine,disel tank car
is a Inheritance b'coz one car is a property of more people.
i mean your car is driving bu you, your friend and your relatives.

Wonderful source link for OOPS concepts:-
http://www.desy.de/gna/html/cc/Tutorial/tutorial.html


Q:what is difference between instance and object.?
instance means just creating a reference(copy) .
object :means when memory location is associated with the object( is a runtime entity of the class) by using the new operator

Q:what are the all difference between interface and abstract class?
interface is a set of abstract methods, all of which have to be overriden by the class whichever implements the interface
abstract class is a collection of data and methods which are abstact (not all of them)

Interfaces are essentially having all method prototypes no definition but Abstract class can contain method definations also.

In short Interface is a abstract class having all methods abstract.
Both abstract classes and interfaces are used when there is a difference in behaviour among the sub-types extending the abstract class or implementing the interface.

When the sub-types behaviour is totally different then you use an interface, when the sub-types behaviour is partially common and different with respect to the supertype an abstract class is used. In an abstract class the partially common behaviour is given a concrete implementation. Since there is no common behaviour between an interface and a sub-type an interface does not have an implementation for any of its behaviour.
If you create a abstract class writing the abstract keyword in the declaration part then You only can inherit the class. You can not create an instance of this abstract class but can inherit the class and with creating the instance of the derived class you can access the method of the abstract class.

If you use a virtual keyword in a method then you can override this method in the subclass if you wish..
If you create a abstract method then you must override this method in the subclass other wise it shows error in the program.


1) What is meant by Object Oriented Programming?
OOP is a method of programming in which programs are organised as cooperative collections of objects. Each object is an instance of a class and each class belong to a hierarchy.

2) What is a Class?
Class is a template for a set of objects that share a common structure and a common behavior.

3) What is an Object?
Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

4) What is an Instance?
An instance has state, behaviour and identity. The structure and behaviour of similar classes are defined in their common class. An instance is also called as an object.

5) What are the core OOP’s concepts?
Abstraction, Encapsulation,Inheritance and Polymorphism are the core OOP’s concepts.

6) What is meant by abstraction?
Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

7) What is meant by Encapsulation?
Encapsulation is the process of compartmentalizing the elements of an abstraction that defines the structure and behavior. Encapsulation helps to separate the contractual interface of an abstraction and implementation.

What is meant by Inheritance?
Inheritance is a relationship among classes, wherein one class shares the structure or behavior defined in another class. This is called Single Inheritance. If a class shares the structure or behavior from multiple classes, then it is called Multiple Inheritance. Inheritance defines “is-a” hierarchy among classes in which one subclass inherits from one or more generalized superclasses.
9) What is meant by Polymorphism?
Polymorphism literally means taking more than one form. Polymorphism is a characteristic of being able to assign a different behavior or value in a subclass, to something that was declared in a parent class.
10) What is an Abstract Class?
Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behavior, typically by implementing its abstract operations.

11) What is an Interface?
Interface is an outside view of a class or object which emphasizes its abstraction while hiding its structure and secrets of its behavior.

12) What is a base class?
Base class is the most generalized class in a class structure. Most applications have such root classes. In Java, Object is the base class for all classes.

13) What is a subclass?
Subclass is a class that inherits from one or more classes
14) What is a superclass?
superclass is a class from which another class inherits.

15) What is a constructor?
Constructor is an operation that creates an object and/or initializes its state.

16) What is a destructor?
Destructor is an operation that frees the state of an object and/or destroys the object itself. In Java, there is no concept of destructors. Its taken care by the JVM.
17) What is meant by Binding?
Binding denotes association of a name with a class.

18) What is meant by static binding?
Static binding is a binding in which the class association is made during compile time. This is also called as Early binding.

19) What is meant by Dynamic binding?
Dynamic binding is a binding in which the class association is not made until the object is created at execution time. It is also called as Late binding.

20) Define Modularity?
Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules.

21) What is meant by Persistence?
Persistence is the property of an object by which its existence transcends space and time.

22) What is collaboration?
Collaboration is a process whereby several objects cooperate to provide some higher level behavior.

23) In Java, How to make an object completely encapsulated?
All the instance variables should be declared as private and public getter and setter methods should be provided for accessing the instance variables.

24) How is polymorphism achieved in java?
Inheritance, Overloading and Overriding are used to achieve Polymorphism in java.

25) What is sealed and abstract class?

Source link:- http://msdn.microsoft.com/en-us/library/ms173150%28v=vs.80%29.aspx

Compile time polymorphism is functions and operators overloading.
Runtime time polymorphism is done using inheritance and virtual functions.
eg compile time polymorphism -- method overloding

run time time polymorphism -- method overriding

Static classes and static methods

  1. Static Class occupy memory during compile time.
  1. Static class cannot be instantiated. It calls its data members and member functions itself.
  1. Static class can have static members only as its cannot declare instance members in a static class
  1. Static class constructor get called whenever any static member is called.
  1. General Class can contains static methods but they too called its-self by class name.