Monday, July 26, 2010

Introduction to Data Types

Data types:

 

 Data type specifies size and type of data.

 

Computer Memory capacity is measured in bytes

1 byte = 8bits(01010101)

1 bit = 0 (or) 1

 

Data types in C#.Net can be categorized into 5 types

 

I) Numeric datatype:

   

  Numerical

  

     A) Signed:                               

   

         1)sbyte---1byte

              

1       sbyte: Holds 8-bit signed integers. The s in sbyte stands for signed, meaning that     the variable's value can be either positive or negative. The smallest possible value for an sbyte variable is -128; the largest possible value is 127

        

       2)short----2 bytes

 

2       short: Holds 16-bit signed integers. The smallest possible value for a short variable is -32,768; the largest possible value is 32,767.

    

         3)int---4 bytes

 

3       int: Holds 32-bit signed integers. The smallest possible value of an int variable is -2,147,483,648; the largest possible value is 2,147,483,647.

         4)long---8 bytes

Ø          long: Holds 64-bit signed integers. The smallest possible value of a long variable is 9,223,372,036,854,775,808; the largest possible value is 9,223,372,036,854,775,807.

 

 

   

 

 

 

 

 

B)Unsigned:  

        

          1)Byte --- 1 byte

 

4       byte: Holds 8-bit unsigned integers. Unlike sbyte variables, byte variables are not signed and can only hold positive numbers. The smallest possible value for a byte variable is 0; the largest possible value is 255.

       2) ushort--- 2 bytes

 

Ø ushort: Holds 16-bit unsigned integers. The u in ushort stands for unsigned. The smallest possible value of an ushort variable is 0; the largest possible value is 65,535.

 

       3)uint--- 4 bytes

 

5       uint: Holds 32-bit unsigned integers. The u in uint stands for unsigned. The smallest possible value of a uint variable is 0; the largest possible value is 4,294,967,295.

       4)ulong---8 bytes

 

6       ulong: Holds 64-bit unsigned integers. The u in ulong stands for unsigned. The smallest possible value of a ulong variable is 0; the largest possible value is 18,446,744,073,709,551,615.

VB.Net doesn’t have unsign data types.

 

II)Floating point datatype:   

 

      1)Float--- 4 bytes

7       float: Holds a 32-bit signed floating-point value

      2)Double--- 8 bytes

8       double: Holds a 64-bit signed floating-point value

      3)Decimal--- 16 bytes

9       decimal: Holds a 128-bit signed floating-point value

 

III)Character related:

  

         1)Char- 2 bytes(with Unicode characters)

        

10  char: Holds 16-bit Unicode characters. The smallest possible value of a char variable is the Unicode character whose value is 0; the largest

 possible value is the Unicode character whose value is 65,535.

 

       Unicode characters:

 

11  Fundamentally, computers just deal with numbers. They store letters and other characters by assigning a number for each one. Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.

 

1V)Logical data types:

         -

        1)bool--- 1 byte

12  bool: Holds one of two possible values, true or false.

                It can hold only true/false as values.

 

 

 

 

V)General data types:

 

           1)String:

 

13  string: Represents a string of Unicode characters. It allows easy manipulation and assignment of strings

           2)Object:

 

14  object: Represents a general purpose type. In C#, all predefined and user-defined types inherit from the object type or System.Object class.

 

     String and Object data types do not have predefined sizes.

 

 

 

 

 

 

 

Value & Reference types:

 

Based on the storage C# data types can be categorized into 2 category.

 

 

 

-Value type

 

1       Stack based

 

In the case of value type, memory is allocated on the stack which works on LIFO(Last in first out) approach as far as memory allocation and de-allocation is concerned.

 

Stack is a data structure, which works on LIFO approach.

Data structure defined as collection of related data.                                                                                                                           

 

-Reference type

                   

2       Heap based

Reference type supports heap-based memory allocatin,memory is allocated in the free pool of unused area called the heap .The size of the memory is determined at run-time, and the memory de-allocation is subjected to Garbage Collector.

 

In contrast, the heap can be pictured as a random jumble of objects.  Its advantage is that it allows objects to be allocated or deallocated in a random order.  As we’ll see later, the heap requires the overhead of a memory manager and garbage collector to keep things in order

 

Difference between Value types and Reference types

Value Types                                               Reference Types

1)Memory is allocated  on the Stack

1)Memory is allocated on the heap

2)A value type variable contains the data itself.

2)Reference type variable contains the address of memory location where data is actually stored.

3)Examples for Value types

     a)Primitive data type

     b)Structures

     c)Enumerators

3)Examples for reference types

   a)Classes

   b)Interfaces

   c)Delegates

 

 

 

Introduction to Data Types

Data types:

 

 Data type specifies size and type of data.

 

Computer Memory capacity is measured in bytes

1 byte = 8bits(01010101)

1 bit = 0 (or) 1

 

Data types in C#.Net can be categorized into 5 types

 

I) Numeric datatype:

   

  Numerical

  

     A) Signed:                               

   

         1)sbyte---1byte

              

1       sbyte: Holds 8-bit signed integers. The s in sbyte stands for signed, meaning that     the variable's value can be either positive or negative. The smallest possible value for an sbyte variable is -128; the largest possible value is 127

        

       2)short----2 bytes

 

2       short: Holds 16-bit signed integers. The smallest possible value for a short variable is -32,768; the largest possible value is 32,767.

    

         3)int---4 bytes

 

3       int: Holds 32-bit signed integers. The smallest possible value of an int variable is -2,147,483,648; the largest possible value is 2,147,483,647.

         4)long---8 bytes

Ø          long: Holds 64-bit signed integers. The smallest possible value of a long variable is 9,223,372,036,854,775,808; the largest possible value is 9,223,372,036,854,775,807.

 

 

   

 

 

 

 

 

B)Unsigned:  

        

          1)Byte --- 1 byte

 

4       byte: Holds 8-bit unsigned integers. Unlike sbyte variables, byte variables are not signed and can only hold positive numbers. The smallest possible value for a byte variable is 0; the largest possible value is 255.

       2) ushort--- 2 bytes

 

Ø ushort: Holds 16-bit unsigned integers. The u in ushort stands for unsigned. The smallest possible value of an ushort variable is 0; the largest possible value is 65,535.

 

       3)uint--- 4 bytes

 

5       uint: Holds 32-bit unsigned integers. The u in uint stands for unsigned. The smallest possible value of a uint variable is 0; the largest possible value is 4,294,967,295.

       4)ulong---8 bytes

 

6       ulong: Holds 64-bit unsigned integers. The u in ulong stands for unsigned. The smallest possible value of a ulong variable is 0; the largest possible value is 18,446,744,073,709,551,615.

VB.Net doesn’t have unsign data types.

 

II)Floating point datatype:   

 

      1)Float--- 4 bytes

7       float: Holds a 32-bit signed floating-point value

      2)Double--- 8 bytes

8       double: Holds a 64-bit signed floating-point value

      3)Decimal--- 16 bytes

9       decimal: Holds a 128-bit signed floating-point value

 

III)Character related:

  

         1)Char- 2 bytes(with Unicode characters)

        

10  char: Holds 16-bit Unicode characters. The smallest possible value of a char variable is the Unicode character whose value is 0; the largest

 possible value is the Unicode character whose value is 65,535.

 

       Unicode characters:

 

11  Fundamentally, computers just deal with numbers. They store letters and other characters by assigning a number for each one. Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.

 

1V)Logical data types:

         -

        1)bool--- 1 byte

12  bool: Holds one of two possible values, true or false.

                It can hold only true/false as values.

 

 

 

 

V)General data types:

 

           1)String:

 

13  string: Represents a string of Unicode characters. It allows easy manipulation and assignment of strings

           2)Object:

 

14  object: Represents a general purpose type. In C#, all predefined and user-defined types inherit from the object type or System.Object class.

 

     String and Object data types do not have predefined sizes.

 

 

 

 

 

 

 

Value & Reference types:

 

Based on the storage C# data types can be categorized into 2 category.

 

 

 

-Value type

 

1       Stack based

 

In the case of value type, memory is allocated on the stack which works on LIFO(Last in first out) approach as far as memory allocation and de-allocation is concerned.

 

Stack is a data structure, which works on LIFO approach.

Data structure defined as collection of related data.                                                                                                                           

 

-Reference type

                   

2       Heap based

Reference type supports heap-based memory allocatin,memory is allocated in the free pool of unused area called the heap .The size of the memory is determined at run-time, and the memory de-allocation is subjected to Garbage Collector.

 

In contrast, the heap can be pictured as a random jumble of objects.  Its advantage is that it allows objects to be allocated or deallocated in a random order.  As we’ll see later, the heap requires the overhead of a memory manager and garbage collector to keep things in order

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Difference between Value types and Reference types

Value Types                                               Reference Types

1)Memory is allocated  on the Stack

1)Memory is allocated on the heap

2)A value type variable contains the data itself.

2)Reference type variable contains the address of memory location where data is actually stored.

3)Examples for Value types

     a)Primitive data type

     b)Structures

     c)Enumerators

3)Examples for reference types

   a)Classes

   b)Interfaces

   c)Delegates

 

 

 

 

 

Introduction To Loops

Conditional Statements

                  1)IF Conditon

                  2)SWITCH Condition

I)                  IF Condion

Syntax1:

      if 

           Statement 1;

   Else

      Statement 2;

 Syntax2:

  If 

        {

           statement 1;

         statement 2;

         }

 else

     {

      statement 3;

      statement 4;

 

     }

Syntax3:

If    //nested if condition

      Statement 1;

   Else if

               Statement 2;

    

Else if

       

         Statement 3;

   Else

    

        Statement 4;

 

Example:

      Comparing 2 numbers

private void button1_Click(object sender, EventArgs e)

        {

             int i=10,j=20;

                 if(I>j)

 

                MessageBox.Show("i is greater than j");

              

             Else

             

               Messagebox.show(“j is greater than I”);

 

 

        }

 

I)                  SWITCH Condition:

 

Syntax:

 

               Switch

              

                 {

                          case 1:

 

                                statement 1;

                                statement 2;

                                break;

         

                       case 2:

                       

                          statement 3;

                          statement 4;

  

                       break;

 

                   default:

                     

                       statement 5;

                       statement 6;

 

                          break;

    

        

  }

 

LOOPS:

1)    For Loop:

2) while Loop:

3) Do while Loop:

 

1       Executing body once is called as one iteration

2       When number of iterations are defined use for loop

3       When number of iterations are defined use while loop

4       When number of iterations are not defined but to execute at least once use do-while loop

Syntax:

 

   For (Initialization; condition;++/--)

         {

            statement 1;

           statement2;

       }

 

Example1: write a program to print from 1 to 10?

class Program

    {

        static void Main(string[] args)

        {

            for (int i = 1; i <= 10; i++)

 

                Console.WriteLine(i);

            Console.ReadLine();

 

 

        }

    }

Syntax of while loop:

 

      While(condition)

         {

 

            statement1;

            statement2;

            statement3;

   

        }

Syntax of do while loop:

 

       Do

          {

 

          statement 1;

          statement 2;

          statement 3;

 

         }

 

    while(condition)


Evaluation of .Net:

Evaluation of .Net:

 

Drawbacks of existing technologies:

 

1) Platform dependency

2)Language interpretability

3)Distributed application development

4)Cross languageError handling

5)Web application

6)Mobile application development

7)Security

8)Database connectivity

 

 

.Net releases:

1       1998  In professional conference Microsoft announced about new environment.

2       2000 Beta version of .Netframework

3       2002 Actual release of .Net framework1.0

4       2003  .Net framework1.1 release

5       2005  Net framework 2.0 released

6       2006 .Net framework 3.0 released

7       2007 .Net framework 3.5 released.

.Net Framework Architecture

 

 

        NET Framework Architecture

 

1       .Defination:Net Framework is a common platform for developing various types of applications(windows,web apps..etc) using dotnet compatible languages(VB.Net,C#.Net…etc)

2       NET Framework Architecture has languages at the top layer such as VB .NET C#, VJ#, VC++ .NET;

3       Layer2 has types of application such as Windows Forms, Web Form, Windows Services and XML Web Services.

4       Bottom two layers consist of .NET Framework class library and Common Language Runtime

The .NET Framework has two components: the .NET Framework class library and the common language runtime.

Common Language Runtime

The common language runtime is the foundation of the .NET Framework. CLR act as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and facilitates with code accuracy that ensure security and robustness

 

.Net Framework class library::

The class library, is a integral component of the .NET Framework, consists of object-oriented collection of reusable classes (types) that we can use to develop applications ranging from traditional command-line or any graphical user interface (GUI) applications such as Windows Forms, ASP. NET Web Forms and Windows Services the newly invented XML Web services

Types of applications:

 

1)Console applications are light weight programs run inside the command prompt (DOS) window. They are commonly used for test applications.

2)Windows Applications are form based standard Windows desktop applications for common day to day tasks. Microsoft word is an example of a Windows application.

3)Web applications are programs that used to run inside some web server (e.g., IIS) to fulfill the user requests over the http. A typical example of web application is Hotmail .



4)Web services are web applications that provide services to other applications over the internet. Google search engine’s web service, e.g., allows other applications to delegate the task of searching over the internet to Google web service and use the result produced by it in their own applications

 

Common Language Runtime(CLR):

Common language runtime is the foundation of the .Net framework.

CLR is a common runtime for all the .net languages.CLR is providing language integration without depending on COM.

CLR can understand only one language i.e. MSIL(Microsoft Intermediate language).

MSIL code will be similar to assembly language syntax.MSIL is platform independent code.

.Net framework is providing set of high level languages to produce MSIL code.

These high level languages(.Net languages) are two types

1       Microsoft .Net languages:

VB.Net,C#.Net,VC++.Net,VJ#.Net..etc,these languages are provided by Microsoft

When we buy .Net framework from Microsoft, it will provide .Net language compilers for thes high level languages.

2       Non Microsoft .Net languages:

Non Microsoft languages which are .Net compatible languages are called third party languages

 Ex: cobol.net,fotron.net,python.net

 For these languages we have to purchase compilers from vendors.

 

 

Understanding Architecture of .NET Framework CLR

 

 

Ø Class loader, which loads classes into CLR.

Ø MSIL to native code compiles, this converts MSIL code into native code.

Ø Code manager, this manages the code during execution.

Ø Garbage collector, this performs automatic memory management.

Ø Thread support, which provides multithreading support to applications.

Ø Exception manager, which provides a mechanism to handle the run-time exceptions handling.

Ø Type checker, which enforces strict type checking.

Ø COM marshaler, which allows .NET applications to exchange data with COM applications.

Ø Security engine, this enforces security restrictions as code level security folder level and machine level security using tools provided by Microsoft .NET and using .NET Framework setting under control panel.

Ø Debug engine, which allows developer to debug different types of applications.

Ø Base class library support, which provides the classes (types) that the applications need at run time.

 

 

JIT(Just InTime) compiler is the integral part of CLR.When we compile the .Net application language compilers convert high level code into MSIL code and JIT compiler convert MSIL code  to Native code,because operating system can under stand only Native code.

 

Managed code and Unmanaged Code:

The concept of code management is the fundamental principal of the CLR,code that targets the CLR is known as manged code,and code that does not target the CLR is know as unmanged code.

 

Common Language Specification:

 

 CLS is common Language specification,Microsoft has released a small set of specification that each language should meet to qualify as a .Net compliant language.

 

Common Type System:

 

CTS is Common Type System,it is a set of standards.

CTS defines the basic datatypes. Each .net compliant language should map its datatypes to these standard datatype.

For example,CTS defines a typeInt32,an integral datatype of 32 bits(4Bytes),which is mapped by C# through int and VB.Net through its integer data type.

 

This makes its possible for the 2 languages to communicate with each other. Therefore in .Netframework you have single class called System.Int32 to interpret these variables.

In .Netframework,system.object is the common base type from where all the other types are derived.