Friday, August 23, 2013

Object Oriented Programming (Oops) Concepts


Hello Friends,

Today I am writing this post because of this is very important question in interview . And Before starting programming you should be about the concepts of Oops.




What is OOP? 
The object oriented programming is commonly known as OOP. Most of the languages are developed using OOP concept. Object-oriented programming (OOP) is a programming concept that uses "objects" to develop a system.
A programming object has an ability to perform actions and has attributes. It performs just like real world entities for e.g. a motor bike. A bike performs actions such as ’Start’, ’Stop’ etc., and it has attributes like red color, 150 cc etc. So does an Object. Actions and attributes are represented by Methods and fields or properties respectively in programming language.
An object hides the implementation details and exposes only the functionalities and parameters it requires to its client. Here also an object shares the same concept as that of a bike. While driving a motor bike, we are unaware of its implementation details such as how it is developed, internal working of gears etc.? We know only the functions or actions it can perform.

What are the various elements of OOP? 
Various elements of OOP are:
• Object
• Class
• Method
• Encapsulation
• Information Hiding
• Inheritance
• Polymorphism

Explain an object. 
An object is an entity that keeps together state and behaviors. For instance, a car encapsulates state such as red color, 900 cc etc and behaviors as ’Start’, ’Stop’ etc., so does an object.
An object is an instance of a class. If you consider Dog as a class, it will contain all possible dog traits, while object German Shepherd contains characteristics of specific type of dog.


Define a class. 
A class represents description of objects that share same attributes and actions. It defines the characteristics of the objects such as attributes and actions or behaviors. It is the blue print that describes objects. 

What is Method?  

Method is an objects behavior. If you consider Dog as an object then its behaviors are bark, walk, run etc.

Explain Encapsulation concept in OOP. 
Encapsulation means keeping actions and attributes together under a single unit.
This can also be understood using a motor bike example. A bike has actions such as ‘switch on light’, ’horn’ etc. and attributes such specific color, size, weight etc. Here

the actions and attributes are bundled together under a single unit, bike.
In a programming language, methods and properties that correspond to actions and attributes respectively are kept under a unit called object. The advantage of encapsulation is that the implementation is not accessible to the client. The user has to know only the functionality of encapsulated unit and information to be supplied to get the result.

What is Information Hiding in OOP? 
Information hiding concept restricts direct exposure of data. Data is accessed indirectly using safe mechanism, methods in case of programming object. Taking bike as an example, we have no access to the piston directly, we can use ’start button’ to run the piston. You can understand the advantage of information hiding concept from this example. If a bike manufacturer allows direct access to piston, it would be very difficult to control actions on the piston.

Define Inheritance. 
Inheritance concept in OOP allows us to create a new class using an existing one. It also allows the new class to add its own functionality. This concept can also be related to real world entity. A bike manufacturer uses same mechanism of existing version of the bike while launching a new version with some added functionalities.

This allows him to save time and efforts.

Explain the term Polymorphism. 
Polymorphism means the ability to take more than one form. An operation may exhibit different behaviors in different instances. The behavior depends on the data types used in the operation.

  
What is Overloading Polymorphism? 
Overloading allows multiple functions to exist with same name but different
parameters. Again if you take bike as an example, it has a function Start with two forms i.e. ’Auto Start’ and ’kick start’.

Explain Overriding Polymorphism. 
Overriding means changing behavior of methods of base class in derive class by overriding the base class methods. If class A is a base class with method ’calculate’ and class B inherits class A, thus derives method ’calculate’ of class A. The behavior of ’calculate’ in class B can be changed by overriding it.

What are the advantages of OOP? 

Following are the advantages of OOP: 

• It presents a simple, clear and easy to maintain structure.
• It enhances program modularity since each object exists independently.
• New features can be easily added without disturbing the existing one.
• Objects can be reused in other program.

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.


  


  


Thursday, August 22, 2013

Debug Editor Shortcut Keys in Visual Studio

Hello Friends,

Today I am writing this post because of debugging is very critical part of developing and using debugging best shortcut we can do debug faster and smoother, So lets use it next time in your project.

Use the following key combinations while you are debugging your project.

Note:  You can change or create keyboard shortcuts in Keyboard of the Environment options in the Options dialog box.

1.             Display documentation for the active window .... F1
2.            Display a system menu for the application window...ALT+SPACEBAR
3.            Add and remove breakpoints on the current lines... F9
4.           Clear all breakpoints................... CTRL+SHIFT+F9
5.            Disable breakpoint....................... CTRL+F9
6.           Display Auto window and move cursor into it..... CTRL+ALT+A
7.            Display Breakpoints dialog box............ CTRL+B
8.             Display Call Stack window and move cursor into it... CTRL+ALT+C
9.            Display Immediate window and move cursor into it.
10.       Not available if you are in the Text Editor window....... CTRL+ALT+I
11.       Display Locals window and move cursor into it............ CTRL+ALT+L
12.      Display Running Document window and move cursor into it.. CTRL+ALT+R
13.       Adds a watch on the currently selected word.............. SHIFT+F9
14.       Display the next statement.............. ALT+* on the NUM pad
15.       Display the shortcut menu................ SHIFT+F10
16.      Display Threads window and move cursor into it........... CTRL+ALT+H
17.      Display Watch window and move cursor into it..CTRL+ALT+W
18.      End debugging session.................................... SHIFT+F5
19.      Execute code one statement at a time, following
        execution into function calls Step Into)................. F11
20.       Execute the next line of code but not follow
        execution through any function calls (Step Over)......... F10
21.       Execute the remaining lines of a function in
        which the current execution point lies (Step Out)........ SHIFT+F11
22.       Restart a debugging session.............................. CTRL+SHIFT+F5
23.       Resume execution of your code from the current
24.       statement to the selected statement (Run to Cursor)..... CTRL+F10
25.       Run the application..................................... F5
26.       Run the code without invoking the debugger
   (Start without Debugging)............................... CTRL+F5
   Set the next statement.................................. CTRL+SHIFT+F10
   Stop execution (Break).................................. CTRL+BREAK


If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.



Difference between Stored Procedure and Function In Sql

Hello Friends,

Today I am writing this post because of this is very important question in interview 

Inside procedure we can use DML (Insert /Update/Delete) statements, But Inside function we can not use DML statements.

Procedure can have both input\output parameters,  But Function can have only input parameter.

We can use Try-Catch Block in Stored Procedure, But In Function We can not use Try-Catch block.

We can not use Stored Procedure in Select statement, But In Function We can use in Select statement.

Stored Procedure can return 0 or n values (max 1024), But Function can return only 1 value which is mandatory.

Stored Procedure can not be call from Function, But We can call function from Stored Procedure.

We can use transaction in Stored Procedure, But In function we can not use transaction.

We can not use Stored Procedure in Sql statement anywhere in the Where/Having/select section, But In function we can use.

We can not join Stored Procedure, But we can  join function.


If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.





Wednesday, August 21, 2013

12 Steps To Create C# Documentation Using Xml Using SandCastle

C# Documentation Using Xml

Hello Friends,

Today I am writing this post because of creating a documentation of coding for .Net developers.  Documentation will to understand code standard, programming tricks and project that is created by other.


C# Documentation Using Xml

1.    First of all Programmer/Developer have to write xml comment 
       code  in Source  file.

Example:
/// <summary>
/// The constructor sets the name, age and cash
/// </summary>
/// <param name="name">The name of the guy</param>
/// <param name="age">The guy's age</param>
/// <param name="cash">The amount of cash the guy starts with</param>

 2.   There are some predefined tags for xml comment.
        Summary, Param, returns, remarks, code, example etc.

3.    After creating comment create exe/dll and xml file of project which
       will be reside   inside bin or bin\debug folder of project. For 
       creating  xml

4.    Open Solution Explorer--> Right Click on project and open 
       properties-->choose Build tag and Inside Build tag check on
       checkbox XML documentation File and give the appropriate 
       name.



5.     After that build the project for creating the xml and dll/exe.
        For creaing documentation use Microsoft sandcastle tool.

6.     SandCastle Documentation Compiler Tools, can be downloaded 
        at  http://sandcastle.codeplex.com/releases/view/47665

        SandCastle Help File Builder, a tool with GUI to generate 
       documentation  file, can be downloaded at
          http://shfb.codeplex.com/

7.     After Installing SandCastle open SandCastle Help File Builder GUI
        From program menu. Screen would be like

8.    Create New Project from File Menu and give the name of project
       And save it anywhere besides (Desktop, My Document).

9.   HTML HELP 1 (CHM)  is used for creating chm help file.
      WEBSITE (HTML/ASP.NET) is used for creating web page.



          Framework according to your project like 3.5, 4.0 etc.

10.    Right click on Document Source menu from project explorer and
         Choose Add Document Source and select your dll/exe and xml file
         from project.

11.   From path tab give the Help Content Output Path  it could be
        Anywhere besides (Desktop, My Document) and Folder 
        name should be  “Help”


12.   And Last click on Build Project from Documentation Menu. And
         it will create all the file in given path folder.

If you like this post share it.. If you encounter any problems, feel free and comment
 below to find solution. Share Your Experience with us.



Tuesday, August 20, 2013

ASP.NET Application and Page life cycle

Hi Friends, 

Welcome in DotNet Developers Cafe. This is my first post. So, read it and enjoy...



The ASP.Net life cycle could be divided into two groups:
  1. Application Life Cycle
  2. Page Life Cycle
ASP.Net Application Life Cycle:
The application life cycle has the following stages:
  • User makes a request for accessing application resource, a page. Browser sends this request to the web server.
  • A unified pipeline receives the first request and the following events take place:
    • An object of the ApplicationManager class is created.
    • An object of the HostingEnvironment class is created to provide information regarding the resources.
    • Top level items in the application are compiled.
  • Response objects are created . the application objects: HttpContext, HttpRequest and HttpResponse are created and initialized.
  • An instance of the HttpApplication object is created and assigned to the request. The request is processed by the HttpApplication class. Different events are raised by this class for processing the request.
ASP.Net Page Life Cycle:
When a page is requested, it is loaded into the server memory, processed and sent to the browser. Then it is unloaded from the memory. At each of this steps, methods and events are available, which could be overridden according to the need of the application. In other words, you can write your own code to override the default code.
The Page class creates a hierarchical tree of all the controls on the page. All the components on the page, except the directives are part of this control tree. You can see the control tree by adding trace= "true" to the Page directive. We will cover page directives and tracing under 'directives' and 'error handling'.
The page life cycle phases are:
  • Initialization
  • Instantiation of the controls on the page
  • Restoration and maintenance of the state
  • Execution of the event handler codes
  • Page rendering
Understanding the page cycle helps in writing codes for making some specific thing happen at any stage of the page life cycle. It also helps in writing custom controls and initializing them at right time, populate their properties with view-state data and run control behavior code.
Following are the different stages of an ASP.Net page:
  • Page request . when ASP.Net gets a page request, it decides whether to parse and compile the page or there would be a cached version of the page; accordingly the response is sent

  • Starting of page life cycle . at this stage, the Request and Response objects are set. If the request is an old request or post back, the IsPostBack property of the page is set to true. The UICulture property of the page is also set.

  • Page initialization . at this stage, the controls on the page are assigned unique ID by setting the UniqueID property and themes are applied. For a new request postback data is loaded and the control properties are restored to the view-state values.

  • Page load . at this stage, control properties are set using the view state and control state values.

  • Validation . Validate method of the validation control is called and if it runs successfully, the IsValid property of the page is set to true.

  • Postback event handling . if the request is a postback (old request), the related event handler is called.

  • Page rendering . at this stage, view state for the page and all controls are saved. The page calls the Render method for each control and the output of rendering is written to the OutputStream class of the Page's Response property.

  • Unload . the rendered page is sent to the client and page properties, such as Response and Request are unloaded and all cleanup done.
ASP.Net Page Life Cycle Events:
At each stage of the page life cycle, the page raises some events, which could be coded. An event handler is basically a function or subroutine, bound to the event, using declarative attributes like Onclick or handle.
Following are the page life cycle events:
  • PreInit . PreInit is the first event in page life cycle. It checks the IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls and gets and sets profile property values. This event can be handled by overloading the OnPreInit method or creating a Page_PreInit handler.
  • Init . Init event initializes the control property and the control tree is built. This event can be handled by overloading the OnInit method or creating a Page_Init handler.
  • InitComplete . InitComplete event allows tracking of view state. All the controls turn on view-state tracking.
  • LoadViewState . LoadViewState event allows loading view state information into the controls.
  • LoadPostData . during this phase, the contents of all the input fields defined with the <form> tag are processed.
  • PreLoad . PreLoad occurs before the post back data is loaded in the controls. This event can be handled by overloading the OnPreLoad method or creating a Page_PreLoad handler.
  • Load . the Load event is raised for the page first and then recursively for all child controls. The controls in the control tree are created. This event can be handled by overloading the OnLoad method or creating a Page_Load handler.
  • LoadComplete . the loading process is completed, control event handlers are run and page validation takes place. This event can be handled by overloading the OnLoadComplete method or creating a Page_LoadComplete handler.
  • PreRender . the PreRender event occurs just before the output is rendered. By handling this event, pages and controls can perform any updates before the output is rendered.
  • PreRenderComplete . as the PreRender event is recursively fired for all child controls, this event ensures the completion of the pre-rendering phase.
  • SaveStateComplete . state of control on the page is saved. Personalization, control state and view state information is saved. The HTML markup is generated. This stage can be handled by overriding the Render method or creating a Page_Render handler.
  • UnLoad . the UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed. This event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad handler.

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.