My Profile

Monday, January 24, 2011

Programming Structure under various programming languages

C Programming Structure:

fig: C Programming Structure

Procedural programming language like C is a collection of members (variable and fucntions) where these members are explicitly called from the main fucntion for execution because it was the entry point of the program.

Note: for most of the programming languages, main is the entry point from where execution starts.

Procedural languages lacks the features like "security" and "re-usability". To overcome the problems, in 70's a new approach in programming has been introduced known as "Object Oriented Approach" which provides security and re-usability.

In object oriented approach members are defined under a special container or wrapper known as a "Class", which provides the basic security for content that is present inside it.

fig: OOP

If we want to invoke the members of a class, it can done only with the permission of class i.e., by creating its "Object".

CPP Programming Structure:

fig: CPP Programming Structure

A class is a user defined type where types can never be consumed directly. To consume a type we need to create a copy of the type.

                         int = 100;     //invalid
                        int x = 100;   //valid

As a class is also a type, the same rule applies to class also, because it was also a type. so, to consume a class first we require to create a copy of the class which will be called as "Object" of the class and then only the members of class can be invoked.

* C++ language suffers from a criticism that it was not fully OOP, because we cannot define the main function within the class but as per the standards of OOP every line of code should be in the class only.

The reason why main cannot be defined inside the class is, if it was defined inside the class it  requires object of the class for invoking or execution which will be created under main only. So, unless object is created main cannot execute and unless main executes object cannot be created.

Java/C# Programming Structure:

The solution for the above problem has been given by the Java language, which was designed in such a way that the main method will be in the class only but to execute without object creation it should be declared as Static, where a static member doesn't require object of the class for execution.

when Microsoft designed the .Net  languages in terms of Main method they have adopted the same guidelines prescribed by Java. So, here also we use static in case of C# and shared in case of VB languages to execute Main without object creation.

Note: a C# program looks exactly same as a Java program.


** If you like this post please like our page in facebook "Dot Net Support"  


Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More