You are on page 1of 36

<.

Net Fundamentals>

C3: Protected

About the Author


Created By:

My Academy

Credential
Information:

<Enter the technical qualification and experience of the


author> Also mention project details and COE details.

Version and
Date:

V1.1

2007, Cognizant Technology Solutions

Confidential

Icons Used

Questions

Tools

Coding
Standard
s

Test Your
Understandi
ng

Demonstrati
on

A
Welcome
Break
2007, Cognizant Technology Solutions

Hands on
Exercise

Referenc
e

Contacts

Confidential

Introduction
Introduction:
The Microsoft. NET strategy was presented by Microsoft officials
to the rest of the world in June 2000:
.NET is Microsoft's new Internet and Web strategy
.NET is NOT a new operating system
.NET is a new Internet and Web based infrastructure
.NET delivers software as Web Services
.NET is a framework for universal services
.NET is a server centric computing model
.NET will run in any browser on any platform
.NET is based on the newest Web standards

2007, Cognizant Technology Solutions

Confidential

Objectives
Microsoft .Net aims to reduce the cost of
software development by creating re-useable code that can be
used by all applications in the environment, regardless of
operating system or programming language. In this session
you
will get an understanding of the following:
.net Fundamentals
CLR
Memory Management
Classes and Ojjects
Access modifiers
Constructors and Destructors
2007, Cognizant Technology Solutions

Confidential

Framework
.Net Framework
Consists of two main components
.Net Framework Class Library
CLR
.Net Framework Class Library
Provides the types that are common to all
languages
These types can be used to develop different kinds
of applications, such as Console application,
Windows and Web Forms, and XML Web Services

2007, Cognizant Technology Solutions

Confidential

CLR(Common Language
Runtime)
CLR(Common Language Runtime)
CLR is the execution environment of .NET
Code built to depend on CLR is MANAGED CODE
Loads the IL Code into runtime
Compile the IL code into native code
Execute and manage the code
Enforce security and type safety

2007, Cognizant Technology Solutions

Confidential

CLR(Common Language
Runtime)
CLR provides
memory management
garbage collection
tightened security
ease of deployment and maintenance
effective debugging facilities
multi language integration
Replacement of DLLs with versioned assemblies

2007, Cognizant Technology Solutions

Confidential

Learn How
.Net Framework
Microsoft Intermediate Language
Contains CPU independent set of instructions

Meta Data
Defines the type that the code contains and references to
other types that the code uses at run time

Portable Executable File

2007, Cognizant Technology Solutions

Confidential

Learn How
Common Type System
Each language has its own set of types
Type conversion in inter language communication is a
pain
Errors usually goes unnoticed during compilation
Results in runtime errors

CTS addresses this


One set of types for all .NET languages
System.Object is the base type
Offers common set of methods for all types

2007, Cognizant Technology Solutions

Confidential

10

Memory Management
Memory Management
Allocating Memory
Releasing memory
Implementing Finalizes

2007, Cognizant Technology Solutions

Confidential

11

Memory Management
Allocating Memory
CLR administers area of Heap - Managed Heap
Takes full control of object space allocation
As objects created, memory allocated linearly
this allows for fast allocation

2007, Cognizant Technology Solutions

Confidential

12

Memory Management
Releasing Memory
GC(Garbage Collector) periodically releases memory
GC considers all unreachable objects on the managed
heap as garbage
GC performs the memory copy function to compress
the objects in the managed heap.
GC uses the highly optimized mechanism
GC cannot clean the system resources used by
managed objects
Explicitly called by GC.Collect();

2007, Cognizant Technology Solutions

Confidential

13

Finalizers
Implementing Finalizers
Contains the clean up code that is executed before the
object is
garbage collected
Dispose and Finalize methods
GC.SuppressFinalize()

2007, Cognizant Technology Solutions

Confidential

14

.Net Assembly
Manifest
Identity of assembly
Security declarations
Dependencies
Exposed types/resources
Module

Module

Metadata

Metadata

IL

IL

Type
Method
Properties
Fields

Type
Method
Properties
Fields

unit of deployment
2007, Cognizant Technology Solutions

Type
Method
Properties
Fields

Type
Method
Properties
Fields

dll or
exe
Confidential

15

Assembly Types
Assembly is Building blocks of programming
in .Net
Private Assemblies
the default
only intended for use by one application
if several applications use, each will have a copy
(not the intent)

Shared Assemblies
this is intended for use by multiple applications
name must be unique so it does not collide
place in the global assembly cache
2007, Cognizant Technology Solutions

Confidential

16

Assembly
Assembly
Assembly manifest contains information about the
identity of an
assembly
Name, version, culture and strong name information of
an
assembly determine its identity
Assembly should have a strong name to access it
globally. Only
strong named assemblies can be placed inside the
GAC
2007, Cognizant Technology Solutions

Confidential

17

Assembly
Metadata
Assembly carries information that describes it
Details about
classes
properties
methods
fields
execution and security needs

Metadata is piggybacked within the Assembly


Always stays in synch with the code

2007, Cognizant Technology Solutions

Confidential

18

Assembly
Manifest
Describes details about the assembly
version
security
scope
resources
classes
types
dependencies

Stored either
as a Portable Executable (PE) file along with MSIL
or as stand along PE file with only the manifest info

2007, Cognizant Technology Solutions

Confidential

19

Namespace

A namespace eliminates the problem of name collision


Two persons can write two different classes with same
name
Names are resolved using namespace
NS1.CLS1
NS2.CLS1
Classes with same name, but from different namespaces

System is a well defined namespace from library of


classes provided by .NET
several classes that provide widely used functionalities

Namespaces are words separated by periods


2007, Cognizant Technology Solutions

Confidential

20

Namespace
Namespaces represent the single organizing principle
used to
group all the different types in the class library
Every piece of code in .Net exists inside a class. In
turn, every
class exists inside a namespace.
When you import the namespace, you dont need to
type the fully
qualified name.

2007, Cognizant Technology Solutions

Confidential

21

Namespace

Web System.Web.UI
Web Services System. Web.Services
Database System.Data
Example
namespace CTS
{
namespace Training
{
public class Classroom {}
}

2007, Cognizant Technology Solutions

Confidential

22

Namespace
Project, by default, has root namespace
Any namespace you create becomes its child
May not be desirable

You may want to remove the default root namespace

Right click on Assembly name in Solutions Explorer, Properties

2007, Cognizant Technology Solutions

Confidential

23

Classes & Objects


Classes & Objects
Group of Objects with similar

properties (attributes)
behavior
relationship to other Objects
Semantics
Blueprints of Objects
Object is a Concept, abstraction, or thing with crisp

boundary & meaning for a problem.

2007, Cognizant Technology Solutions

Confidential

24

Classes & Objects


Nested Classes
A class may be written within an enclosing class
If nested class is non-public, cant be seen outside

enclosing class
Much like concept of inner class in Java than nested
class in C++
Useful to
implement code that needs to be modularized but not (re)usable

outside a class
useful to implement interfaces
Some times even multiple implementations of same interface

2007, Cognizant Technology Solutions

Confidential

25

Classes & Objects


Example
usingSystem;
classHello
{
publicstaticintMain()
{
Console.WriteLine("HelloWorld!");
return0;

}
2007, Cognizant Technology Solutions

Confidential

26

Access modifiers
Access modifiers
Private (default)
public
protected
internal
Protected internal

2007, Cognizant Technology Solutions

Confidential

27

Access modifiers
Classes
Abstract classes
The abstract modifier is used to indicate that a class is

incomplete and that it is intended to be used only as a base


class.
Abstract classes represent concepts not real objects

Sealed classes
The sealed modifier is used to prevent derivation from a

class

2007, Cognizant Technology Solutions

Confidential

28

Access modifiers
abstract class A
{
public abstract void F();
}
abstract class B: A
{
public void G() {}
}
class C: B{
public override void F()
{
// actual implementation of F }
}
2007, Cognizant Technology Solutions

Confidential

29

Access modifiers
sealed class TestFinal
{
private int SomeData;
public void SomeMethod()
{
}
}
class ExtendFinal: TestFinal
{
}

2007, Cognizant Technology Solutions

Confidential

30

Constructors
Constructors
Object Initialization
Guarantees object is in a valid state upon
creation
Constructor called automatically when object
created
Constructor has the same name as the class in

Java, C++ and C# languages


No return value
2007, Cognizant Technology Solutions

Confidential

31

Constructors
Type of Class Constructor
Instance
Private
Static

Instance constructors are used to create and initialize instances.


A private constructor is a special instance constructor. It is

commonly used in classes that contain static members only.


A static constructor is used to initialize a class. It is called

automatically to initialize the class before the first instance is


created or any static members are referenced.

2007, Cognizant Technology Solutions

Confidential

32

Destructors
Destructors are used to destruct instances of classes.
A class can only have one destructor.
Destructors cannot be called. They are invoked

automatically.
A destructor does not take modifiers or have
parameters.

2007, Cognizant Technology Solutions

Confidential

33

Summary
The Microsoft .NET Framework is a software component which can be added to the Microsoft Windows
operatingsystem.
It provides a large body of pre-coded solutions to common program requirements, and manages the
execution of programs written specifically for the framework. The .NET Framework is a key Microsoft
offering, and is intended to be used by most new applicationscreated for the Windowsplatform.
The pre-coded solutions in the namespaces form the framework's class library and cover a large range
ofprogrammingneeds in areas including the user interface,dataaccess, cryptography, numeric
algorithms, and network communications. The functions of the class library are used by programmers who
combine them with their own code to produce applications.
Programs written for the .NET Framework execute in a software environment that manages the program's
runtime requirements. This runtime environment, which is also a part of the .NET Framework, is known as
the Common Language Runtime (CLR). The CLR provides the appearance of an application virtual machine,
so that programmers need not consider the capabilities of the specific CPU that will execute the program.
The CLR also provides other important services such as security guarantees, memory management, and
exception handling.
The class library and the CLR together compose the .NET Framework. The framework is intended to make it
easier to develop computer applications and to reduce the vulnerability of applications and computers to
security threats. First released in 2002, it is included with Windows Server 2003 and Windows Vista, and
can be installed on most older versions.

2007, Cognizant Technology Solutions

Confidential

34

<RIO Name>: Source


http://www.academictutorials.com

Disclaimer: Parts of the content of this course is based on the materials available from the
Web sites and books listed above. The materials that can be accessed from linked sites are
not maintained by Cognizant Academy and we are not responsible for the contents thereof.
All trademarks, service marks, and trade names in this course are the marks of the
respective owner(s).
2007, Cognizant Technology Solutions

Confidential

35

You have successfully completed


<RIO Name>
Click here to proceed

You might also like