Saturday, September 15, 2012

c# interview question :- What is the difference between Debug and Release?

See the following C# / .NET training video: - In this video we will understand how c# debug and release compile modes are different and when to use them. Debug is mainly meant for development environment while release is meant for production environment.



See for more stuffs on c# interview questions and answers

Regards,

Click to view more from author's on C# training

Friday, June 8, 2012

Site is under maintenance, please visit later: - ASP.NET trick

24 x 7 uptime guaranteed



As a web site owner we all boast about 24 x 7 uptime. But somewhere down below in our hearts we know it’s difficult. We need to bring down the website for maintenance, fixingdefects, upgrading etc.

Easy way…

As an innocent c# ASP.NET developer you would think how about just stopping IIS web server, do your activity(maintenance, fixing defect etc.) and then start the IIS again.



While this looks to be a but obvious way of solving the problem but it’s not the best way if we consider the end user perspective. The end user would see an ugly screen as shown below leading to more confusion.



Rather than end user seeing that kind of absurd screen how about showing something more better and informative like: - “Site is under maintenance and will be live till 3:00 AM”.

Going offline graciously:-App_Offline.htm

Also I would like to highlight here it’s not about showing the error message but technically we would like to ensure that the following things happen in IIS:-
  • Application domain under which the website is running is brought down.
  • All incoming request coming to the ASP.NET site needs to stopped.
  • All request to be routed to the temporary page which is created.
  • After maintenance the application domain should be loaded and the incoming request should be processed in a normal manner.
Thanks to Microsoft they always understand our needs. The proper way of approaching this problem is to create a simple “App_offline.htm” file in your application root directory. In this “App_offline.htm” you can put your user friendly message which the end users can see when the site is under maintenance.
Once done you can delete the file and your web site app domain is loaded and the normal life continues.






You can visit my site for
C# and .NET interview questions and in case you are a fresher you can attend FREE C# training by clicking on C# training videos.

Take a quick look as revision for practical video on "Site is under maintenance"

Monday, June 4, 2012

C# and .NET interview advice for freshers: - Not getting a job for a year should I put fake experience, switch to DBA or pay money for getting a job?

As a .NET interview questions author I always get lots of emails. One of the common things which people ask should I put a fake experience. Below is an answer to one such email.

Sir I've completed b.tech in 2011 ,,,,and searching for a job,,,, I was trained on .NET from NIIT institute ,,,, I've faced some .NET interviews but they are asking for money to pay them,,,,

If someone says pay money to get a job that means they do not need you, you are kind of a baggage on them. Also beware it can be a fraud also. Lately lot of small size software companies and training institutes who are not doing well have turned up to these kind of activities.


When we say we are doing a job, means we are helping company to grow and company pays money in return. So people who are asking for money straight say No No , if that means sitting at home for some time that’s fine, enjoy family.

and other side i am jobless till now and its been 1year,,,and now i don't understand what to do now to see my self as a engineer

If you are jobless for a year you need to see what’s going on wrong. Do connect me personallyfor a mock on .NET interview so that I can personally judge to see what is wrong.

IT market is not so bad. It must be a bit strict for fresher’s but not that horrible as you see. See one is that you are jobless for a year and the other is that in this 1 year you have been to at least 15 interviews and you got till the last round. So if you belong to later part of it that means you are doing well and you should get a job soon.

I personally understand what it means to be at home for a year. But believe me when you get good positions in life ahead you will cherish this struggle and you will be proud of the same.

How about switching to DBA

Courtesy: - http://everydayclimb.files.wordpress.com/

There's a saying in Hindi,DusrokagharSuhanalagtahai( The other side of the grass is always green). .NET, c# has large number of jobs as compared to DBA. Definitely DBA has its own Niche but the numbers of jobs are less. So if for C# you have 100 jobs then for DBA you will have 10. In those 100 c# jobs the number of applicants will be 1000 while in DBA it will be 10.

So one scores high in the number of jobs while the other has less competition. My suggestion would be you have already been trained in NIIT , you are already in full swing of searching a job , stick to .Net for now. You can switch to DBA later when you have a job on hand.

Will a fake 1 year experience help me?


For one Lie you will have to tell 100 Lies ahead. Smaller companies look for people who can code and complete their project. Bigger and mid-level companies look for experience. So start with smaller companies, do not expect sky rocketing salary, be truthful, show your expertise by showing some sample projects. Let them you are serious as well as competent.

I know you will not believe as you are jobless for a year but TRUTH finally wins.

C# interview questions: - What’s the difference between String and String Builder?



Also visit my site for more C# training.

Sunday, May 20, 2012

The unsung hero, Volatile keyword: - c# threading

The unsung hero, Volatile keyword: - c# threading


My mad and blind love with c# threading


When I first saw c# threading code, I just falled in love forever. As days passed by the power and simplicity of “System.Threading” namespace converted my love in to blind love.

Thread t1 = new Thread(SomeThread);
t1.Start(o1);

In case you have not still fallen in love and new to c# threading, you can start looking at my c# training threading video from here.


















The blind love was but obvious because in today’s modern world parallel task execution is compulsory component.My love helped me to please users with mind blowing UI interfaces, multi-threaded batch processes, until one day…..

End of blind love with c# threads
























But one fine day my love with c# thread’s had a bump.I had two threads running and both where updating the same local variable.  The updation done by one thread was not visible to the other thread.

Let me detail what I am saying. I had create a local variable called as “_loop” as shown in the below abstract code snippet. This variable was set to ‘true’ by default.


class Program
{
bool _loop = true;
…
…        
}

In the same application I had created one function called as “SomeThread” which will run until the “_loop” is true.

private static void SomeThread(object o1)
{
….
….
while (o._loop)
{}
}

From the main thread I was spawning this some thread which was running the loop continuously. In this main thread I was setting the “_loop” to false. In other words the infinite loop of “SomeThread” should stop and exit…VOILA it did not.

static void Main(string[] args)
{
Thread t1 = new Thread(SomeThread);
t1.Start(o1);
o1._loop = false;
….
….
}

Below is the complete source code, you download and see it for yourself. https://skydrive.live.com/redir?resid=658DB05866C4E8A3!257&authkey=!ABOTw_YQ_czfnNc

bool _loop = true;
static void Main(string[] args)
{
            Program o1 = new Program();
            Thread t1 = new Thread(SomeThread);
            t1.Start(o1);
            Thread.Sleep(2000);
            o1._loop = false;
            Console.WriteLine("Value Set to false");
}
        private static void SomeThread(object o1)
        {
            Program o = (Program)o1;
            Console.WriteLine("Loop Starting...");
            while (o._loop)
            {}
            Console.WriteLine("Loop Stopping...");
        }

If you run the above code you can see the infinite loop starting, but I does not end even if the value was set to “false”.


You can also see the actual video demo of the code by clicking on c# training for threading .
Note :- When you run the code ensure that you have selected release  with CNTRL + F5 pressed.


Why did my love ditch me:- Local Thread memory storage and synchronization


After so many years of successful relationship it was difficult to believe this unexpected behavior. So I started googling to get reasons for it.

After long hours of reading, I was stunned that there are two kinds of memory we have to deal when it comes to threading.

One is the main memory where our variables are allocated and the thread also has his own local memory…SURPRISED, same here.

In other words the “_loop” is present at three places one in the main memory and second in the local memories of “mainthread” and “somethread” functions.

When the program kick starts the “_loop” is set to true. So all the memory storages have “_loop” set to true. See the below visual representation.


As the program runs the main thread set the value to false. This updation is done in the local memory of “mainthread” and main the memory, but it does not update the local memory of “SomeThread”. So the “SomeThread” function still sees the stale value and keeps running in a loop.

Below is a visual representation of how things look internally at various points.



The unsung hero: - Volatile keyword
















All relationships have problem, we just need to adjust, find solution and move with life. I was definitely in no mood of leaving c# threading after such a wonderful relationship.

The solution to get around this multiple memory storages was “VOLATILE” keyword.

If you declare your variable as volatile the thread tries to access values from main memory rather than from his local memory where data is stale. It does slow down a bit but it addresses this big confusion.

See it yourself, take the same source code and change the “_loop” variable to volatile as shown in the below code snippet and run it.

class Program
{
  volatile bool _loop = true;

Ensure that you select mode “release” and hit control + f5 to see the expected behavior.








Feel and See it yourself

In case you want to see it live what I have said in this blog see the video below
http://www.youtube.com/watch?v=DZUXDSEuqek

You can also see it yourself by downloading the code from the below link.

I am trainer by profession, interested in c# training , click here c# training .

Friday, May 18, 2012

UML Training: - Elaborate all types of diagrams in UML(Unified Modeling Language)?

There are nine types of diagrams in UML:-

Use case diagram:
They describe "WHAT" of a system rather than "HOW" the system does it. They are used to identify the primary elements and processes that form the system. The primary elements are termed as "actors" and the processes are called "use cases". Use Case diagrams shows "actors" and there "roles".

Class diagram:
From the use case diagram, we can now go to detail design of system, for which the primary step is class diagram. The best way to identify classes is to consider all "NOUNS" in use cases as classes, "VERBS" as methods of classes, relation between actors can then be used to define relation between classes. The relationship or association between the classes can be either an "is-a" or "has-a" relationship which can easily be identified from use cases.

Object diagram:
An object is an instance of a class. Object diagram captures the state of classes in the system and their relationships or associations at a specific point of time.

State diagram:
A state diagram, as the name suggests, represents the different states that objects in the system undergo during their life cycle. Object change in response to certain simulation so this simulation effect is captured in state diagram. Therefore, it has a initial state and final state and events that happen in between them. Whenever you think that some simulations are complicated, you can go for this diagram.

Sequence diagram:
Sequence diagrams can be used to explore the logic of a complex operation, function, or procedure. They are called sequence diagrams because sequential nature is shown via ordering of messages. First message starts at the top and the last message ends at bottom. The important aspect of a sequence diagram is that it is time-ordered. This means that the exact sequence of the interactions between the objects is represented step by step. Different objects in the sequence diagram interact with each other by passing "messages".

Collaboration diagram:
A collaboration diagram groups together the interactions between different objects to fulfill a common purpose.

Activity diagram:
Activity diagram is typically used for business process modeling, for modeling the logic captured by a single use case, or for visualizing the detailed logic of a business rule. Complicated process flows in the system are captured in the activity diagram. Similar to a state diagram, an activity diagram also consists of activities, actions, transitions, initial and final states, and guard conditions. However, difference is state diagrams are in context of simulation while activity gives detail view of business logic.

Deployment diagram:
Deployment diagrams show the hardware for your system, the software that is installed on that hardware, and the middleware used to connect the disparate machines to one another. It shows how the hardware and software work together to run a system. In one, line its shows the deployment view of the system.

Component diagram:
The component diagram represents the high-level parts that make up the system. From .NET angle point of view, they form the "NAMESPACES". This diagram depicts, at a high level, what components form part of the system, and how they are interrelated. Its shows the logical grouping of classes or group of other components.

See the following video on UML diagram: -



Click to get UML Training

Regards,

Get more UML training stuffs from author's blog