Translate to your language...

15 September 2013

OOPs Concepts: When to use

Hai Friends,

This post is regarding the main OOPs concepts and what is there use and when it’s good to use them.

Below are the concepts which are included in this post:

·                     Encapsulation
·                     Abstraction
·                     Overloading
·                     Method Overriding
·                     Constructor
·                     Interface
·                     Inheritance
·                     Abstract class
 
These OOPs concepts you can use while implementing the functionality of your projects in accordance with the requirements and situations.
Hope it will be useful to learn and in the implementation of the projects.
1) In which situation encapsulation is used in your project?
Encapsulation is hiding and binding of the data.
Accessing the public properties by using private variables is one of the good examples of Encapsulation in all the projects.
e.g.
private string _name;
public String Name
{
get{return _name}
set{_name= value;}
}

Here you are not able to access the private variable _name but its value can be accessible by the public property Name. So a kind of Encapsulation here. Namespace is also an example of Encapsulation which is encapsulating the classes, methods, properties etc.
This is the runtime behaviour of an entity.

2) In which situation abstraction is used in your project?
Hiding the behaviour and showing the necessary things regards an entity can be called as Abstraction. Like for a Car, showing the method like Clutch, Gear etc but hiding its internal functions can be an example of Abstraction. This is the compile time behaviour of the entities.
When there are the specific requirements and that can be flown to their child, then we can use abstraction. it means whatever is essential, we implement to its child classes, else will be inherited automatically.
e.g.
class A
{
public abstract void Add(int a, int b);
protected int x;
public string Name{get; set;};
}
Class B: A
{
 public override void Add(int a, int b)
 {
  Console.WriteLine("Sum of two numbers is:" + int. Parse(a + b).toString());
 }
}
Here the essential method Add is implemented to the child class B. rest all the members will be inherited accordance to their protection levels.

3) In which situation method overloading is used in your project?
The concept where we want the similar functionality but different behaviour, we use overloading.
When we have same functionality to implement with different behaviour, we go with the overloading of method.
e.g. If we have to get the sum of 2 numbers, 3 number and 4 numbers. So in that case we can take only one method name Add with its varied parameters like:

public void Add(int a, int b)
{
 Console.WriteLine("Sum of 2 numbers" + int. Parse(a + b).toString());
}

public void Add(int a, int b, int c)
{
 Console.WriteLine("Sum of 3 numbers" + int. Parse(a + b +c).toString());
}

public void Add(int a, int b, int c, int d)
{
 Console.WriteLine("Sum of 4 numbers" + int. Parse(a + b + c + d).toString());
}

Now according to our requirement, we can call the respective method with its arguments.
Here all the methods are doing sum of the numbers, but their behaviour are different- the first method will give the sum of 2 number while the next one will give the sum of 3 number and the final method will give the sum of 4 numbers.

4) In which situation method overriding is used in your project?
When we may(abstract) or may not(virtual) want to implement the particular method at runtime to its child class according to the requirement, we go with overriding concept.
e.g.

Class X
{
 public virtual void Print()
 {
  Console.WriteLine ("This is the print method. You can override according to your definitions and implementation");
 }
}
Class Y:X
{
 public Override void Print()
 {
  Console.WriteLine("Implementation for Excel print methods");
 }
}

5) In which situation constructor is used in your project?
Constructor is the way to initialize the class with the default values of the members. Constructor is by default initialize with the class.
But if you want to initialize some members when the class in getting instantiate, you can write the constructor and code for initialization inside that constructor.
e.g.

Class MyClass
{int a;
 public MyClass()
 {
   a=10; //initialized with the class instantiation
 }
}

Here the constructor code will get initialized with the class instantiation.

6) In which situation interface is used in your project?
Interface is the collection of abstract members.
So whenever we have the requirements such as it requires through the application at many places, then we create an interface with that method so that we can implement it at our own way according to the requirements.
e.g.
Interface Inf
{
 void Print();
}

Class ExcelClass:Inf
{
 public override void Print()
 {
  //Write code to print in excel
 }
}

Class WordPrintClass: Inf
{
 public override void Print()
 {
  //Write code to print in Word
 }
}
Class PDFPrintClass: Inf
{
 public override void Print()
 {
  //Write code to print in PDF
 }
}

Also to implement the multiple inheritances, we use inheritance.

7) In which situation inheritance is used in your project?
When we want to have some common features for multiple classes then we go for inheritance.
To inherit the properties of base class to their derived class.
8) In which situation abstract class is used in your project?
Abstract class is same as abstract. So go to the Q 2 for the details.


So you can go through the link to get the fair idea about its implementation: 
http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=295763&

8 September 2013

3-6 yr Experience Interview Questions in .Net Technologies PART - II

Hai Friends,

With lot of encouragement and support, I am posting the Part II of the questions and answers for 3-6 years experienced people. These questions will be helpful for those who are preparing for the interview or attending the interviews. This will be helpful for the last minute preparation in quickest way.
If anyone has better answer, please reply to this post and I will include them.

C# / ASP.net/ .Net framework / other .Net related questions:

1. What is the difference between IEnumerable and IQueryable?
Ans. IEnumerable and IQueryable are used to query data from collections and database.  The IEnumerable is basically inherited from IQueryable, so it’s having all the features of the IQueryable in addition to its having additional own features.

S.NoIEnumerableIQueryable
1.
Exists in System.Collections Namespace
Exists in System.Linq Namespace
2.
Can move to forward only in the collection.
Can move to forward, backward or in between the items.
3.
Best for collection like List, Array or in-memory collection
Best for the collections which is out memory like services, remote databases etc
4.
Suitable for LINQ to Object and Linq to XML queries.
Suitable for Linq to SQL queries
5.
It doesn’t supports custom query, Lazy loading so it’s not good for paging scenarios.
It supports custom query using CreateQuery and Execute methods. Also support lazy loading so good for the paging scenarios.
6.
The extension methods which supports be IEnumerable, takes the functional objects as the parameters.
The extension methods which supports be IQueryable, takes the expression tree as the parameters.




In the first example (By using the IEnumerable), the generated SQL is as below:

In the second example (By using the IQueryable), the generated SQL is as below:
We can see that by using the IQueryable, the performance will increase as it has the TOP clause in the query.

2. What is cross site scripting? (XSS)
Ans. Cross-site scripting is the way to attacks and insert the vulnerabilities in Web page. This attack is injected by client-side code. The script which is inject by the client can embed itself in response data. The response data which send back to the malicious user. The browser can’t recognize the scripts as it is responded from the trusted source.
The cross-site scripting attacks also work on the HTTP and HTTPS.
There are 2 ways to prevent the cross site scripting attack:
Constrain input- Validate the input length, type, formatting, range etc
Encode output- Send the input data with encode e.g. Encode to HTML
To prevent the cross-site attack, we can set the below attributes in web.config file: 
3. If I want to see my website similar in all the browsers then what I need to do for that?
Ans. If you want to see the website with the same look and feel then you need to write the common css style which should be same for all browsers. Actually every browser will not support every css elements so it is not possible to use the same css to support all the browsers. You need to write the common css elements in the file and then apply it across the website. Else you need to write the separate css file as per the browser.

4. If say 1 Lac users are using any particular website then what you will do to prevent crashing of server? Which care you will take at the time of coding?
Ans. There are the ways like we can have multiple servers to handle the requests from the users. In this, we can have the Web Gardening concept where we can have the multiple web servers and then one main server to handle the number of requests and switch the requests to other servers.

5. Why to use design patterns?
Ans. Design Pattern is the way to solve the recurring problems which occur during the designing of the applications. As the requirements increases, the projects becomes complex and due to the complexity, it’s difficult to maintain it.
With the help of design patterns, we can reduce the complexity and with the help of OOPs paradigm, we can make our applications more efficient in all the ways.
According to the GoF (Gang of Four) company, the Design Patterns can be classified to 3 ways:-
  • Creational Design Pattern
  • Behavioral Design Pattern
  • Structural Design pattern
6. If I have a class C and two interfaces I1 and I2 and I have 'Add' method inside I1 and I2 then how to specify which one has to be called?
Ans. By using the explicit implement interface, we can implement the same method which is defined in both the interfaces.
e.g.
The implementation will be as below:
7. Garbage collection uses which type of algorithm? How it will find which object is unused?
Ans. Mark-And-Release is the algorithm which the garbage collection uses to reclaim the memory of the unreferenced objects which are no longer used.
The algorithm Mark-and-Release work in 2 steps:-
a.    In the first steps, it marks all the accessible objects of the heap memory. This is called as mark phase.
b.    In the second step, scan the heap and reclaim all the unmarked objects by the Garbage Collection algorithm. This step is called as sweep phase.
Below are the algorithm steps:
For the detailed description, follow the below link:
8. What is the difference between out and ref?
Ans: Ref and Out are the parameters which are used in the methods  [ref] and [out] both allows the called method to modify a parameter. The difference between them is what happens before you make a call.
  • [ref] means that the parameter has a value on it before going into the function. The called function can read and or change the value any time. The parameter goes in, then comes out
  • [out] means that the parameter has no official value before going into the function. The called function must initialize it. The parameter only goes out.
So the main difference between the ref and out parameter is that the out parameter doesn't needs to be initialized while the ref parameter must be initialized before passing to the function.

9. Is it possible to use more than one out parameter?
Ans.  As we know that the method always returns a single value but by using the out parameter, we can return multiple values from the method or function.
In C# we can write the small code snippet which will describe to return the multiple values using the out parameters:
We can also use the struct which will contain the multiple values as the return:

There is another way to return multiple values like using Tuple class (newly introduced in .Net 4.0). The tuple class can return the object which can contain multiple values in it. 

10. Is it possible to use .js files used under script will be in body and not in header? Why?
Ans. The .js file is used in header because first the .js file should be loaded to the application and then rest of the content should be load.


11. What is Expression Tree in C#? How to use Express Trees to create Dynamic LinQ queries?

Ans. Expression Tree is used to create Dynamic Linq query. Sometimes, when the specific criterias' can't be defined at compile time, Expression tree is useful to generate the Linq query at the runtime.
For E.g. In an application, the filter criteria is based on some user actions and is generated dynamically. In this case, we can use the Expression Tree which will generate the criteria at runtime and then we can use that criteria to filter the records from the IQueryable collection.
System.Linq.Expressions is the namespace required to work with the Expression Tree. Here we need to create the predicates using expressions, which will be used in the query.


Hope these questions and answers will be helpful to you.

1 February 2013

MVC 3: MVC (Model View Controller) with Razor Engine

Hai Friends,
Now a days most of companies are asking the latest technology guys specially in Microsoft Technologies as Microsoft Corporation is releasing many technologies day over day. In all those MVC (Model View Controller) is one of them which is very hot in the markets now a days.
So all the Microsoft Techies are looking forward to get in to this new technology as it helps them to get new job, to improve there technical skills and be updated with the current industry standards and requirements.
This is the small initiation in this regards in form of a technical posts. 
This article will  describe about the MVC with Razor Engine
 (MVC 3), about how to create the Controller classes, 
Model classes and generate the Views automatically through the Razor Engine.
 The article is written with all the steps used to create the MVC3 application 
with ASP.Net.
Hope this article will be useful for those who are looking forward to create 
the applications in MVC3 (MVC with Razor) pattern. 
Please go through the below link to get the details about creating the 
MVC3 application in ASP.Net:

http://www.dotnetspider.com/resources/44324-MVC3-MODEL-VIEW-CONTROLLER-A-NEW-MVC-FRAMEWORK-WITH-RAZOR-ENGINE-BY-MICROSOFT.aspx  

5 January 2013

Update Config file settings Automatically using Windows Application

Hi Friends,
Sometimes we need to search for the application or the code snippet which
will work as per our requirements- Like update the configuration file 
automatically. Because this is the tedious task to update the config file
 manually and we want there should be a simple application where I can 
enter the server name, database name, user id and password and click on 
update should update our configuration file automatically.
So now nothing to worry and this article is all about that. This article will 
describe mainly about the updation of Configuration file 
(App.Config or Web.Config) settings by using the Windows Application. 
This windows application will take the inputs from the user like Database
 server name, user name, password etc and will update the configuration 
file settings automatically without opening the config file.
This article will describe each and every steps of creating the windows 
application and then code snippet so that we can use as is or can also 
modify as per our requirements.
For the details of the Windows application creation and the code snippet, 
you can follow my article:

http://www.dotnetspider.com/resources/44327-Windows-Application-Update-Configuration-File-Settings.aspx 

3 January 2013

Convert Numbers to Spellings- A C# Windows Application

Hai Friends,
This article is the small windows application developed in C# to convert the numbers to spellings. This article also explains about each and every steps to create the application with source code and creating the setup so that it can be run on any machine just by copying and pasting of the setup file. The end user can enter any number in the given textbox and click on the Convert to Spelling button. The converted spellings will be displayed in the label. The Program is written in such a way that it can handle the negative numbers also.The validation part is also included in the program so that it will allow the user to accept only the numbers.
You can go through the below link for the detailed explanation of the application including the setup
file:
Convert Numbers to Spellings- C# Windows Application 

8 April 2012

18 most common validation scripts to validate the Controls in ASP.Net

Hai Friends,
Many times, we search in the Google to get the correct validations expression to validate our textboxes. And its true that we get various links where others have given their own validations expressions and controls using some scripts, regular expressions etc.
Then we implement those expressions and at the end, we found that it’s not working and again we start our search for the next link. It becomes very complicated whenever we have to fix the validation issue in a very small time and then we didn’t get the correct expression.
So dear folks, now nothing to worry as I have created a CommonScript.js file which contains the validation expression and they all are tested and in my project.
Like you, I also did the same and finally got this file which contains all the general use validation expressions to validate our controls. This CommonScript.js file can be modified as per your requirements like changing the message, modifying the scripts etc.
You can go through the below link for the detailed description:

24 March 2012

How to write the connection string and place it on to web.config file

Hai Friends,
Today I was thinking that many times, we are having doubt in writing the connection string in the web.config file. Whether the connection string is correct or not? Is it case sensitive? Is the User Id or userid is correct? Can we write pwd in place of password or Password?
As we can't check it in compile time, so all the error we get at the run time and then we try to replace the attributes of confile file by making the cap-locks to small or vice versa.
So I though to write an article which will be useful for we all who are working in Microsoft Technologies with the database.
As it will help to create all type of connection strings for their respective providers, so we need not to worry that it is applicable only to SQL Server.
You can go through the below link for the details with the screenshots where i have explained that how you can create and test your connection string before putting in the configuration file.
Hope it will help to all the members...
Cheers!!!

18 March 2012

Creating Code Snippet with the Shortcut in Visual Studio 2010

Hai friends,
Today i was thinking that lot many times we gets fed-up with writing lot of duplicate code so can't we create such type of shortcut so that no need to write the whole code and we can do it with a small shortcut. Then I created a Code snippet for the header of the files which will write the below stuff for me by just writing a small shortcut FHC and there are few place holders which we need to write it and its done:
/==================================================
//                       CTSInvoiceBO.cs
//
//       This file is the code for Business Objects of CTS invoice.
//------------------------------------------------------------------------
//
//               Modification Control Log
//
// Date           By  Version  Description
// 03/18/2012  PA  1.0       Business Objects of CTS invoice
//
//
//==================================================
Then i created a snippet file and added to my visual studio IDE and now i don't need to write all this code manually. There are few place holders which we need to update and rest all code and other format will be done automatically.
Guys you can follow the below link where you can get the detailed description of how we can create this Code snippet and how can we attach it with our Visual Studio IDE and also how to create the shortcut's for it.


Hope it will be helpful for most of the programmer who work in the maintenance projects where they need to define such kind of header for the file..
Cheers!!!

29 November 2011

Checkboxes in the GridView

Hi Friends,

Today i was thinking about some small JavaScript code regarding the check boxes checked status inside the GridView and then i did some R&D and implemented the code for the Select All/ Unselect All link buttons.
Hope this will be useful for us for our development environment.

Please follow the link below for the detailed description and the Code snippet which can be very useful while implementing the code.

http://www.dotnetspider.com/resources/43376-Smallest-JavaScript-Code.aspx


4 November 2011

Visual Studio Light Switch

Hai Friends,

This post will talk about the latest version of visual studio named as "Light Switch". 

This resource will describe about the new development tool which is the extension of Visual Studio 2011 with lot of features as inbuilt so that the developer only need to think about the application business logic rather than thinking about the whole application architecture and design.

The Light switch application contains many default functionality which are required for every business applications like 
  • Search capabilities: – the business application will have the search feature to search the contents inside the business applications.
  • Sort capabilities: - The business application will also have the sorting and rearranging capabilities in the grid where the data is displayed
  • Export: – this is also a generic requirement where the export feature is also built-in. Means all the business application created by using LightSwitch will have default export functionality of the data.
  • Addition to all the above features, the LightSwitch application will also have the default features to add, update, save and delete features. 
  • The data validation logic is also built-in in the LightSwitch business applications. It means the data which is inserted/updated or deleted can be controlled by using the validations. 
  • Extended features: - With the above all features, there are few extended features like appearance of the application, we can use custom controls. Also we can format the UI by writing the custom business types.
      See the details at the below link: 

Sr .Net Consultant | MCP Certified | Microsoft Technologies(.Net with Sql Server, MVC, AngularJS

My photo
Kuala Lumpur, Kuala Lumpur, Malaysia
Overall 17.0+ years of experience in software industry as a Programmer/Developer/Architect with Web & Windows application development and Maintenance, including analysis, design, coding, testing and documentation. • Proficient in Microsoft Technologies i.e. Visual Studio with .Net Framework. • Excellent analytical, problem solving, communication, interpersonal skills with the ability to handle multiple tasks or projects working independently or in a team. • Consistent attention to detail with an ability to analyze and interpret the implication of decisions to minimize bugs and create user-friendly applications. • Experience of Collaborating with Clients and Team Members. Ability to convey Technical Information at all levels. • Ability to work with team/management to ensure successful execution of project management tasks including scheduling, scope management, outside dependency coordination and priorities resolution. • Experience in working with global clients like UK, USA, Europe, Australia etc. and teams located remotely (e.g. Sydney, Australia, USA, and Sweden). • Worked with the Swedish client ManpowerGroup at onsite client location Stockholm, Sweden.