Saturday, September 24, 2011

Program structure of C#



C++ language suffer from a criticism that it was not fully object oriented because as par the rules of OOP programming every line of cod should be defined inside the class only but main function in C++ program will always be outside the class.
NOTE- while design C++ the designers could not place Main inside the class because if Main is inside the class it can execute only when called by using object of the class in which it was present, whereas object is getting created main function only. (Circular dependency)

When the java language were designed the designers are given a permanent solution to the problem of main by introducing “static method(function)”, which can execute without the object of class. So if the main method is declared as static inside the class it can become the entry point of the program where the object of the class created and rest of the members in the class can execute as following.


                                                                             C#/JAVA Program

Class example
{
Collection of member
Static void Main ( )  ß entry point

{
Create the object invoke
Member of class
}
}
While designing C# the developers of the language has followed the same guideline prescribed by java in case of Main so in C# also Main method gets defined with in the class as Static and the program structure looks exactly same as the java programs structure we have seen above.
Suppose if your class contain only main method in it to execute the class we don’t reqired to create object of the class for execution.
THE SOFTWARE REQUIREMENT, THE HARDWARE REQUIREMENT AND THE WEBSITE FOR c#.NET.
Hardware requirement-
  1.       2.5-3 GB hard disk space for install
  2.       Min. 1 GB RAM in it.

Software required-
  1.     Windows XP with server pack 3 or windows vista (home premium business) or windows 7.
  2.      Visual Studio .Net 2010 or 2008.
  3.      Oracle DB 11g or SQL server 2008 or 2005.
  4.      MS office.
Books – C#3.0 unleashed (SAMS)
C# 2008 developers (SAMS)
Professional C# 2008 (work press).

Website-
   1. www.msdn.com

Syntax to define a class in C#;- 
[<modifiers>]class<name>
{
-stmts
}


  1.     Modifiers or few optional keywords like public, private, static etc. which can be used on a cclass.
  2.       C# is a case sensitive language so in case of casing it adopts few conventions—
  - All keywords will be in lower case only.
  - All library function must be used in proper case only i.e. class name, Method name etc.
(WriteLine) – Proper case
Syntax of Main Method:-
static void/int Main ([string[]argr])
{
- stmts
}

- As discussed earlier must and should name should be declared as static if we want the execution to start from there.
- Main can be either a non value returning method and can also return a value of type int only.
- Main method can tack parameters also but only of type string [] array.

Writing a First Program:-

  1. to write a program in any .net language wee can use of any editor like Visual Studio or noted etc.
  2. developing a program in notepad
  3.  Open the notepad and write following code in it.
class Example
{
int x = 100;
static void Main()
{
System.Console.WriteLine("First c# program");
}
}

4 .
 Now save the program in a desire location as Example.cs
Note- a C# program should use an extension of .cs and the VB program should use an extension of .vb
       5. Compiling the program – to compile a C# program we required a C# compiler, which comes along with the visual studio software. It is a command line tool which has to be used from Visual; Studio command prompt. To use it –

Go to start menu à program à MS visual studio à visual studio tools à visual studio command prompt, click on it to open.

Now move into the folder ware your program has been saved. And used the C# compiler as following. And used the C sharp compiler as following
                              
C:\......................................\vc>cd\
C:\>cd csharp4
C:\csharp4>csc Example.cs
If the program is compiled successfully without any error it creates a file Example.exe , which contains IL code in it. 
      6. Executing the program- Now from the command prompt run your exe file as following –
C:\csharp4>Example
ildasm : (intermediate language disassembly )-->
        It is a tool that can be used for viewing that contained of the exe file generated after compilation which contains IL code in it.
It can be used from visual studio command prompt as following
C:\csharp4>ildasm Example.exe


.NET FRAMEWORK ARCHITECTURE


.NET FRAMEWORK ARCHITECTURE
BCL is a set of library function that is provided in common for all the .net languages.
ADO.net is a technology that is used for communication with databases.
ASP.net is a technology for developing WEB application using .net languages.
WIN FORM is used in the development of graphical user interfaces
WPF windows presentation foundation is all so used in the development of GUI only with support for graphics, animation 2 dimensional and three dimensional imagine.
WCF is stand for windows communication foundation is used in the development of distributed application.
WWF – windows workflow foundation.
LINQ( language integrated query), it is used for communication with SQL server database apart from AVO.net whereas LINQ is simple and easy for programming then AVO.net.
Avo.net entity framework provides added fetchers to ADO.net which is available traditional.
CLR is the core component of .nets framework which is responsible for execution of .net applications it contains various think in it like-
  1. Security manager whose tack cares of application security,
  2. CLASS LOADER – This is responsible for loading of required library
  3. JIT Compiler (JUST IN TIME COMPILER) is responsible in converting IL code into machine code. In this problem to improvise the performance of compilation it adopts few optimization techniques like – conversion gradually during the program execution and also storing of machine code in the memory for consuming it for next time.
  4. Garbage collector is responsible for memory management which is a process of allocating and de-allocating the memory that is required for a program.
Managing memory is very critical for a system in this process it used as garbage collector that provides implicit memory management (automatic memory management when compiled with manual memory management that is explicit allocation and de-allocation.
Garbage collector when it finds unused objects in the program treats them as garbage and destroys immediately. Garbage collector was invented by john mecheciv in the year 1959 to resolve the problems of manual memory management

COM component object model

COM component object model   It is a specification from Microsoft which advises never built software as a monolithic unit in spite it tells building of software by dividing it into smaller library and then build it as software.
The advantage of building software using a COM architecture will be like –

  1. maintenance of the software easier.
  2. reusability – which allows using a library or component under multiple software 

COM Interoperability - Com component or library were unmanaged so OS dependent . When Microsoft introduce .net it has straight away provided tools to the industry which can convert Com libraries into managed version and then consumed under .net application development.
The managed version of the COM library is known as RCW (runtime callable wrapper ) . in the same thing it also providing option for converting .net libraries into unmanaged version CCW( com callable wrapper ) for consuming the under COM application.
Concerns and criticism related to .NET-

  1. Managed applications that executes under the .net framework CLR or JAVA JVM required more system resources when compiled with unmanaged applications but some applications have however shows to performance better in managed version when compiled wit unmanaged version.
  2. In a managed environment such as the Microsoft framework CLR or JAVA’s JVM the regularly accruing garbage collection for reclaiming memory suspends execution of the application for an unpredictable waits of time typically not more than few milliseconds.
  3. As JIT languages can be more easily reveres engrained them machine code to source code used by an application ,so there is concern over possible loss of trade secrete many obfuscation techniques already developed however can help to prevent this . Indeed Microsoft visual studio 2005 (.net 2.0) includes such a tool.
  4. Since the framework is not preinstalled on older versions of windows an application is required is must verified that it is present or not.
  5. Newer versions of the framework 3.0 and up) are not preinstalled on any version of the windows OS and some developers have expressed concerns about the large size.



C Sharp programming language

C Sharp programming language it is an object-oriented programming language developed by Microsoft, as the part of the .net initiative and later approved as a standard by ECMA and ISO.

ANDERs Hejlsberg leads development of the language which have procedural object oriented syntax based on the C++ and includes influences from several other programming languages most importantly DEPIN and JAVA With a particular emphasis on simplification.

History Of the Language – during the development of .net class library were originally written in a language called Simple Managed C (SMC). In January 1999 Anders Hejlsberg formed a team to build a new language at that time called Cool later the language has been renamed C# and the class library as well as ASP.net runtime have been posted to C#.

C#’s principal designer and led architect Anders Hejlsberg, has previously invoked with the design of visual J++, Borland Delphi and the turbo Pascal languages. In interviews and technical papers he has state it that flows in most major programming languages like C++, JAVA, DELPHI, and SMALLTALK drove the fundamentals of CLR, which in turn draw the design of C# programming language itself

Design goals -
  1. The ECMA standard list this design goal for C# , it is intended to be simple , modern , general purpose and Object oriented programming language.
  2. The language should include strong type checking, array bounds checking, detection of attempts to used uninitialized variables, source code portability and automatic garbage collector.
  3. The language is intended for used in developing software component that can take advantages of distributed environment.
  4. Programmer portability is very important as specially for those programmers already familiar with C and C++.
  5. Support for internationalization is very important.
  6. C# is intended to be suitable for writing applications for both hosted and embedded systems.
           Versions of Language C#-
            1.0, 1.5, 2.0, 3.0, 4.0.

Feature of C# 2.0-
  1. Partial classes which allow class implementation across more than one source field.
  2. Generics or parameterized type.
  3. Static class that cannot be instantiated and that only allows static members.
  4. Anonymous delegates,
  5. The accessibility of property assessors can be set independently.
  6. Null able value types , which provides improved interaction with SQL databases.
  7. Coalesce operator (??) Returns the first of its operant’s which is not NULL and NULL , if no such operant exist
Features of C# 3.0-
  1. Language Integrated Query (LINQ)
  2. Object initializers and collection initializers.
  3. Anonymous types.
  4. Implicitly typed arrays.
  5. Lambda expressions.
  6. Automatic properties.
  7. Extension methods.
  8. Partial methods.
      Features of C# 4.0 –
  1.       Dynamic programming.
  2.       Named and optional parameters.
  3.       Covariance and contraverians.
  4.     . Dynamic lookups.
  5.      Indexed properties.
  6.     Com’s specific interop features.
       Programming Structure under various programming languages.
C programming –
Collection of members
Void main () <- entry point
{
Call the members from here for execution
}
     C is a procedural programming language, which consists of variable and functions (members) in it. The member which we define in the programming gets executed when we explicitly called them from main function.
     NOTE- most of the programming languages starts their execution from main which is considers as the entry point for your program.
      Procedural programming language doesn’t provide code security and code reusability.
      To resolve the drawbacks of procedural programming in 70s object oriented languages came in to existence which provides security and reusability of the code.
      In an object oriented program the members are defined not directly with in the program, but under a container and wrapper known as class, which provide the basic security for content inside it. 
   
      A class is a user defines type. And to consume the members of a class we required to create an object of the class and using the object members of the class can be invoked.

      Note- a type can never be consumed directly because they do not having any memory allocation so for consume the type we need to create a copy of the type.
     Int = 100; //invalid
     Int X =100; // valid
     Test t;
      t.add(100,50);
      As a class is also a type. The same rule applies to class also, so consume a class we need to first create a copy of the class which is referred as object.

CPP Program-
-Class example
{
Collection of members
};
Void main < --entry point
{
-create the object of class
     -using the object invoke members of class
}

CLI Specification



BCL ( Base class library )  A library is a set of reusable functionalities every programming language have predefined library to consume under them in the same way .net languages are all so provided with library which or not separate for each .net language here all the languages of .net will be consuming a single set of libraries is known as base class library that are implemented in C# language .

BCl is the best example for language interoperability which is possible among .net languages
VES ( virtual executing system )  all high level .net languages after compilation generate the same type of code known as CIL code , which can be carried executed on any machine provided an OS specific virtual execution system is available that converts IL code into Machine code according to OS and hard ware .
VES is responsible and providing OS independency for CIL code

Following the CLI specification, Microsoft has implemented Framework for windows operating system and MONO has implemented the framework for few other machine like UNIX, LINEX, SUN SOLARIS, MAC-OS etc . , MONO is a suppository of Novell networks.
.net is theoretically 100% platform independent but practical implementation of the framework is available only for few machine.
Framework version – Microsoft has launched the framework in to the market in the year 2000 and 1.0 BETA 1 and again in 2001 1.0 BETA 2 has been launched and finally in 2002 the first RTM version 1.0 is launched in to the market
Version
Relies date
1.0
2002
1.1
2003
2.0
2005
3.0
2006
3.5
2007
4.0
2009