18
.NET Application

NET Introduction - III

Embed Size (px)

Citation preview

Page 1: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 1/18

.NET

Application

Page 2: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 2/18

Developing an application in .NET

Page 3: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 3/18

The diagram shows how an application is

developed and executed using .NET Framework.

Steps:

The code is written in any .NET compatible language (in

this case C#) reusing the required classes from the .NETLibrary.

Once the source code is prepared, it is compiled with the

suitable compiler for that language (here C# compiler).

This converts the code into MSIL form which is

independent of the system on which the source code iscompiled.

Page 4: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 4/18

The MSIL code produced in the above step is freelyportable and can be moved on to any machine on whichthe .NET Framework is installed.

The JIT compiler in the CLR again converts the MSILcode into native machine code just before the CLRexecutes it. This conversion is fast as the code getscompiled simultaneously as the execution of compiledmodules is taking place. This compiled code is cachedand there is no need to compile it every time it is

needed. Hence the execution speed is highly improved.

Page 5: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 5/18

Key Featur es in .NET Framework

Page 6: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 6/18

1.Platform Independency

Page 7: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 7/18

Language when compiled produces code in thesame common intermediate language format. Itis this IL code that the CLR understands andexecutes into the native code. CLR cannotexecute the code of any other language, eventhough it is .NET compliant. The IL code isportable and can be run on any other platformwhere the .NET Framework is present. This

makes .NET applications platform independent.

Page 8: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 8/18

2.Language Independency As all the .NET languages follow the CTS and CLS

specifications, the internal representation of the

datatypes in each of these languages is same.Moreover all these languages produce the same

MSIL code when compiled. This means that a

program developed in one language can be freely

used in other language. The best example for this is

the usage of BCL classes ( which are developed inC# ) in all the .NET programming languages.

Page 9: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 9/18

3.InteroperabilityManaged and unmanaged code:

The code developed in .NET for .NET Framework is called

Managed code. This managed code executes under the

supervision of CLR. The CLR consists of a compiler calledJust In Time (JIT) compiler which compiles the IL code into

machine code at runtime prior to executing it. The managed

code consists of two parts- the IL code and its Metadata.

The advantage of executing the code under CLR is that,

during JIT compilation it checks for type-safety and security

by using the information of Metadata. It provides memorymanagement behavior and also checks the correctness of 

the code and refuses to execute it if it finds any discrepancy

in the code.

Page 10: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 10/18

Unmanaged code is the executable code producedby older languages like C, C++, etc. This code is

native to the OS on which it is running. Unmanaged

code executes directly under the operating system

and hence less secure. This code does not get the

services of the .NET runtime. In .NET we can import

this unmanaged code in the form of dll using the

System.EnterpriseServices namespace and

System.Runtime.InteropServices namespace.

Similarly .NET components can be consumed inother non .NET languages. .NET provides this

interoperability support better than any other 

technology or language.

Page 11: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 11/18

Interoperability with COM:

.NET components are easily interoperable with COM

components through a wrapper. A wrapper is a piece of 

code that acts as a broker for .NET and COM

interaction. These wrappers are different for differentenvironments. We use a Runtime Callable Wrapper 

(RCW) to consume a COM component in .NET and

COM Callable Wrapper (CCW) to consume a .NET

component in COM.

.NET RCW COM

COM CCW .NET

Page 12: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 12/18

Interoperability with non .NET:

The .NET concepts like web services, WCF services (provided in 3.5

version) allow the functioning in a heterogeneous environment where

RMI, CORB A (Java Clients), old COM, MTS, MSMQ clients can

consume or work with .NET

.NET Web Ser vices / WCF non .NET

Page 13: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 13/18

4. Memor y Management A very excellent feature that the CLR provides is memory management. A

heap memory is allocated for all the memory requirements of a.NET

program. As long as there exists a reference to an object in the heap, it is

considered as in use memory block. Once the reference is lost, it is marked

as garbage. CLR periodically cleans up the heap and releases the memory

of the objects that are marked as garbage. This task is performed by

something called as a Garbage Collector. Garbage Collector runs at a time

when there is a need for more memory during the runtime, so it is not

possible to say when exactly it frees up the garbage memory. It is also not

possible to free up the memory explicitly through the code. This eliminates

the fear of memory leaks in .NET applications. But we can force the

Garbage Collector to free up garbage memory by calling the GC.Collect()

method. But it is not advisable to use this

method unless absolutely necessary.

Page 14: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 14/18

5. Security.NET provides Code Access Security (C AS) in addition to performing

the actions of verification and validation when an assembly is

loaded. Code Access Security is provided by using the evidence

associated with every assembly. This evidence specifies the

permissions on the calling code. Depending upon these permissions

the C AS performs its tasks. If any assembly is not granted

permission then a security exception is thrown. When the assembly

is loaded, the CLR performs the validation and verification tests.

During validation it checks whether the assembly contains valid

Metadata and CIL code and if the required internal tables arepresent. In verification phase, it just checks if there is anything

unsafe with the code. It executes the code only when all these tests

are successful, otherwise throws an exception.

Page 15: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 15/18

Concerns and Criticisms related to .NET

Page 16: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 16/18

1.  Applications running in a managed environment such as the Microsoft

framework's CLR or Java's JVM tend to require more system resourcesthan similar applications that access machine resources more directly.

Some applications, however, have been shown to perform better in .NET

than in their native version. This could be due to the runtime

optimizations made possible in just-in-time compilation of managed

code, or other aspects of the CLR like Garbage Collection.

2. As JIT languages can be more easily reverse-engineered than native code to

algorithms used by an application, so there is concern over possible loss of trade

secrets and the bypassing of license control mechanisms. Many obfuscation

techniques already developed, however, can help to prevent this; indeed fromMicrosoft's .Net 2.0 these tools are included.

Page 17: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 17/18

3. In a managed environment such as the Microsoft framework's CLR or Java'sJVM the regularly occurring garbage collection for reclaiming memory suspends

execution of the application for an unpredictable lapse of time (typically not

more than few milliseconds).

4. Since the framework is not pre-installed on older versions of Windows an

application that requires it must verify that it is present, and if it is not, guide theuser to install it.

5. Newer versions of the framework (3.0 and up) are not pre-installed on any

versions of the Windows operating system, because Some developers have

expressed concerns about the large size (around 54 MB for end-users

with .NET 3.0 and 65 MB with .NET 3.5).

Page 18: NET Introduction - III

8/6/2019 .NET Introduction - III

http://slidepdf.com/reader/full/net-introduction-iii 18/18

.NET Ver sions