1. CHAPTER 1 : INTRODUCTION TO .NET
2 Marks:
1. Write the use of common language specification(CLS) in .net architecture.
Ans :- The basic use of CLS is to identify whether a particular language is .NET
compliant language or not. Microsoft has released a small set of specifications that each
language must satisfy so as to be used with .NET framework. These are set of standards
or rules led down for languages to work under .NET umbrella. For example:- there
should not be any global function declaration or there should not be multiple
inheritance. If a language code is within these boundaries then it is said to be .NET
compatible.
2. What are the uses of .net framework class library (FCL)?
Ans :- Framework class library is also knownas base class library. Its main motive is to
provide the common functions like String manipulations, Common data structures, IO,
streams, Security, Threads, Windows programming, Network programming, Data
access. The library follows extremely efficient Object Oriented design pattern which
makes it more useful and easy to access.
3. List the basic building blocks used in .NET framework along with their use.
Ans:-
Namespaces: Namespaces are similar to packages in JAVA. It is a logical grouping of
functionally related classes and helps in avoiding the errors occurring due to referring
to the classes with same name. Namespace is a container (e.g Class, Structures,
Interfaces, Enumerations, Delegates etc.), example System.IO logically groups
input output related features, System.Data.SqlClient is the logical group of ADO.NET
Connectivity with Sql server related features.
System - This is a namespace is the root namespace for built in types provided by the
Microsoft .NET framework and Object is the root class in the inheritance hierarchy of
the System namespace.
For example:- System.IO, System.threading, System.Drawing
Assemblies: Assemblies are the building blocks of .NET framework, they form the
fundamental unit of deployment, version control, reuse, scoping and security. It
2. contains the code that a CLR executes. It is the smallest unit of deployment of a .net
application and it can be a .dll or an exe file. During the compile time Metadata is
created with Microsoft Intermediate Language (MSIL) and stored in a file
called Assembly Manifest. Both Metadata and Microsoft Intermediate Language
(MSIL) together wrapped in a Portable Executable (PE) file. Every Assembly you
create contains one or more program files and a Manifest. Assembly Manifest contains
information about itself. It contains information about the members, types, references
and all the other data that the runtime needs for execution. There are two types of
program files: Process Assemblies (EXE) and Library Assemblies (DLL). Each
Assembly can have only one entry point (that is, DllMain, WinMain, or Main).
We can create two types of Assembly:
1. Private Assembly
2. Shared Assembly
4. Write the hardware and software requirements of .NET framework.
Ans: Software requirements
Windows XP service Pack 2 or Above, Windows server 2003 Service pack 1 or above,
Windows server 2003 R2 or above, Windows Vista, Windows Server 2008, Windows 7,
Windows 8, Windows 8.1, Windows 10
Hardware Requirements
Hardware Minimum Recommended
CPU 1.6 GHz 2.2 GHz or Higher
RAM 384 MB 1024 MB or more
Display 1024 x 768 1280 x 1024
Hard Disk 5400 RPM 7200 RPM or higher
5. Name any five .NET compatible languages.
Ans:- VC++, VB.NET, Jscript.NET, J#, C#.
6. Write the use of ADO.NET component in .NET framework.
Ans:- ADO.NET component of .NET framework is used for database connectivity
for .NET application. ADO.NET consists of a set of Objects that expose data access
services to the .NET environment. It is a data access technology from Microsoft .Net
Framework, which provides communication between relational and non relational
systems through a common set of components.
3. System.Data namespace is the core of ADO.NET and it contains classes used by all
data providers.
7. Enlist the different .NET initiatives.
Ans:-
.NET
Framework
Version
CLR Version Features Included in
Visual Studio
1.0 1.0 First version
of .NET
framework
Visual
Studio .NET
1.1 1.1 ASP.NET and
ADO.NET
updates
Side-by-side
execution
2003
2.0 2.0 Generics
ASP.NET
additions
2005
3.0 2.0 WPF, WCF,
WF,
CardSpace
-
3.5 2.0 AJAX-enabled
websites
LINQ,
Dynamic data
2008
4 4 Expanded base
class libraries
Cross-platform
2010
4. development
with Portable
Class Library
MEF, DLR,
code contracts
4.5 4 Support for
Windows Store
apps
WPF, WCF,
WF, ASP.NET
updates
2012
4.5.1 4 Support for
Windows
Phone Store
apps
Automatic
binding
redirection
Performance
and debugging
improvements
2013
8. Enlist the different types of applications that can be developed using .NET.
Ans:-
ASP.NET web applications, Windows form based application, Console application,
component libraries, windows custom controls, web custom control, web services,
windows services
5. 4 Marks:
1. Write the functions of CLR in brief.
Ans:- CLR (Common Language Runtime) is a heart of Dot Net Framework. It works as
a layer between Operating Systems and the applications written in .Net languages that
conforms to the Common Language Specification (CLS). The main function of
Common Language Runtime (CLR) is to convert the Programming language Code
(Managed code) into native code and then execute the Program. The Managed Code
compiled only when it needed, that is it converts the appropriate instructions when each
function is called . The Common Language Runtime (CLR) 's Just In Time (JIT)
compilation converts Intermediate Language (MSIL) to native code on demand at
application run time. Common Language Runtime (CLR) manages Thread executions,
Memory Management that is allocation of Objects and Buffers , Garbage Collection
(GC) - Clean up the unused Objects and buffers , Exception Handling, Common Type
System (CTS) that is all .NET language that conforms to the Common Language
Specification (CLS) have the same primitive Data Types, Code safety verifications -
code can be verified to ensure type safety, Language integration that is Common
Language Runtime (CLR) follow a set of specification called Common Language
Specification (CLS) , this will ensure the interoperability between languages,
Integrated security and other system services.
1. Choosing the Source Code language compiler.
At this stage we can choose the source code language for .NET. The primary languages
available are C#, VB.NET and Python.
6. 2. Compiling the source code to MSIL assemblies using the language compiler.
Compiling the source code using the language compiler generates the corresponding
assembly containing the MSIL. The assembly can be either a .exe or a .dll depending on
the entry point defined in the
Application.
3. Executing the code by CLR
At execution time the CLR converts the MSIL to native code using the JIT compiler at
runtime.
JIT Compiler
The CLR provides a JIT compiler for each supported CPU architecture. JIT converts
the MSIL to native code at application execution time. Instead of converting all the
code in the assembly to native code, the JITconverts the MSIL to native code as needed
during execution and stores the resulting native code in memory, so the next time the
same code is executed it will be executed directly from memory instead of being
compiled again.
The resulting MSIL will run on every CPU for which JIT compiler exists (and it exists
for most CPU's), but if the managed code calls platform specific API's then it will not
run on other platforms.
When the method is loaded the loader attaches a stub to each method. Once the native
code is generated for the method, the stub is modified to point to the native code, so the
next time the method is called the native code is executed directly.
Garbage Collector
Garbage Collector handles automatic memory management and it will release memory
of unused objects in an application, this provides automatic memory management.
Security Engine
It enforces security permissions at code level security, folder level security, and
machine level security using Dot Net Framework setting and tools provided by Dot
Net.
2. Explain the CTS and its use in detail.
Ans:
CTS (Common Type System):
It specifies data types which are created in two different languages get compiled in to
base common data type system. Common Type System (CTS) describes a set of types
that can be used in different .Net languages in common. That is, the Common Type
System (CTS) ensure that objects written in different .Net languages can interact with
7. each other. For Communicating between programs written in any .NET complaint
language, the types have to be compatible on the basic level.
These types can be Value Types or Reference Types . The Value Types are passed by
values and stored in the stack. The Reference Types are passed by references and stored
in the heap. Common Type System (CTS) provides base set of Data Types which is
responsible for cross language integration. The Common Language Runtime (CLR)
can load and execute the source code written in any .Net language, only if the type is
described in the Common Type System (CTS). Most of the members defined by types
in the .NET Framework Class Library (FCL) are Common Language
Specification(CLS) compliant Types.
3. Write any eight points of difference between VB and VB.NET.
Ans:
Feature VB VB.NET
Runtime Environment VB-runtime Common Language
Runtime (CLR)
Type Safety Not a type safe language Type safe language
Exception handling โOn Error GoToโ syntax to
handle exceptions at
runtime
Try-Catch-Finally block
Threading No Multithreaded
applications
Can create multithreaded
applications
Types of Applications
developed
Desktop Windows
applications
Web applications,
distributed applications
Component Architecture Uses COM as a component
Architecture
Uses assemblies as its
component architecture
Database connectivity Uses ADODB and record
sets to implement data
access
Uses ADO.NET and
Datasets to built data
access applications.
Language Type Interpreter Based Compiler Based
OOP Support Object Oriented
programming is missing
from VB
Present in VB.NET
Mathematical Poor in complex Fast in Complex
8. Calculations speed Mathematical Calculations Mathematical Calculations
4. Draw and explain the different types of application architectures.
Ans:-
Single Tier Architecture
In single tier architecture database, application and presentation services i.e. the user
interface all reside in the single system. These types of systems does no external
processing apart from the platform on which it is running.
2-tier architecture
In 2-tier, the application logic is either buried inside the User Interface on the client or
within the database on the server (or both). With two tier client/server architectures, the
user system interface is usually located in the user's desktop environment and the
database management services are usually in a server that is a more powerful machine
that services many clients. Processing management is split between the user system
interface environment and the database management server environment. These
applications are suited for small applications that do not have a lot of forms.
9. 3-tier architecture
In 3-tier, the application logic (or) process lives in the middle-tier, it is separated from
the data and the user interface. Three tier architecture uses an XML web service to
seperate the database access to another component which returns data to front end.
3-tier systems are more scalable, robust and flexible. Inaddition, they can integrate data
from multiple sources. In the three tier architecture, a middle tier was added between
the user system interface client environment and the database management server
environment. There are a variety of ways of implementing this middle tier, such as
transaction processing monitors, message servers, or application servers. The middle
tier can perform queuing, application execution, and database staging. For example, if
the middle tier provides queuing, the client can deliver its request to the middle layer
and disengage because the middle tier will access the data and return the answer to the
client. In addition the middle layer adds scheduling and prioritization for work in
progress. Flexibility in partitioning can be a simple as "dragging and dropping"
application code modules onto different computers in some three tier architectures. A
limitation with three tier architectures is that the development environment is
reportedly more difficult to use than the visually-oriented development of two tier
applications. The most basic type of three tier architecture has a middle layer consisting
of Transaction Processing (TP) monitor technology. The TP monitor technology is a
type of message queuing, transaction scheduling, and prioritization service where the
client connects to the TP monitor (middle tier) instead of the database server. The
transaction is accepted by the monitor, which queues it and then takes responsibility for
managing it to completion, thus freeing up the client.
10. Logical N-Tier Application Architecture
The best approach to building an application using .NET is to separate all logical
processes into discrete classes. In a typical application, this generally involves a
business rule component, a data layer component, and the front-end code that uses these
components. Using a logical N-tier development strategy is appropriate for all types of
applications. It works equally well in small, medium and large applications with both
desktop and web applications.
5. Explain the features of .NET.
Ans:
Interoperability
Because interaction between new and older applications is commonly required,
the .NET Framework provides means to access functionality that is implemented in
programs that execute outside the .NET environment. Access to COM components is
provided in the System.Runtime.InteropServices and System.EnterpriseServices
namespaces of the framework; access to other functionality is provided using
the P/Invoke feature.
Common Runtime Engine
The Common Language Runtime (CLR) is the virtual machine component of the .NET
framework. All .NET programs execute under the supervision of the CLR,
guaranteeing certain properties and behaviors in the areas of memory management,
security, and exception handling.
Language Independence
11. The .NET Framework introduces a Common Type System, or CTS. The
CTS specification defines all possible datatypes and programming constructs
supported by the CLR and how they may or may not interact with each other. Because
of this feature, the .NET Framework supports the exchange of instances of types
between programs written in any of the .NET languages.
Base Class Library
The Base Class Library (BCL), part of the Framework Class Library (FCL), is a library
of functionality available to all languages using the .NET Framework. The BCL
provides classes which encapsulate a number of common functions,
including file reading and writing, graphic rendering, database interaction
and XML document manipulation.
Simplified Deployment
The .NET framework includes design features and tools that help manage
the installation of computer software to ensure that it does not interfere with previously
installed software, and that it conforms to security requirements.
Security
The design is meant to address some of the vulnerabilities, such as buffer overflows,
that have been exploited by malicious software. Additionally, .NET provides a
common security model for all applications.
Portability
The design of the .NET Framework allows it to theoretically be platform agnostic, and
thus cross-platform compatible. That is, a program written to use the framework should
run without change on any type of system for which the framework is implemented.
Microsoft submits the specifications for the Common Language Infrastructure (which
includes the core class libraries, Common Type System, and the CommonIntermediate
Language) making them available as open standards. This makes it possible for third
parties to create compatible implementations of the framework and its languages on
other platforms.
6. Explain the advantages of .NET framework.
Ans:
Managed Code
Managed code is simply code written to execute in the .NET environment. Managed
code offers a few benefits in terms of integrated security, type-safe code, and automatic
memory allocation and deallocation.
12. Cross-Language Operation
A .NET-compliant language is one that adheres to the Common Language
Specification (CLS) and the Common Type System (CTS) laid out in the CLI. It is now
possible to have C#, managed C++, and VB.NET code in the same module.
Consistent programming model
With .NET, accessing data with a C# and VB.NET very similar apart from slight
syntactical differences. Both the programs need to import the System.Data namespace,
both programs establish connection with database and both programs run a query and
display the data.
Direct Support for Security
.Net framework enables the developer and the system administrator to specify method
level security. Consider an application that accesses data on a remote machine or has to
perform a privileged task on behalf of a non-privileged user.In this scenario security is
much more important as application is accessing data from remote machine. With.NET
the framework enables the developers and system administrator to specify method level
security.
Simplified Development efforts
The .Net Framework simplifies debugging with support for three types of Runtime
diagnostics Event logging, Performance counters and tracing. Runtime diagnostics
helps you to track down bugs and also helps you to determine how well an application
performs.
Easy application deployment and Maintenance
The .Net Framework makes easy to deploy applicaitons.The .Net Framework handles
the details of locating and loads the components.
Assemblies
Assembly is elementary unit in a framework application. It performs various functions
in programming with the .Net Frame work. Every computer that has the .Net
Framework installed with have the Global Assembly Cache.
7. Explain any four drawbacks of previous languages.
Ans:
1. It is not suited for modern programming techniques. Because it has been largely
superseded by VB.NET and other languages.
2. Programs written in VBare not tend to be quickest as it requires additional code to be
written which is not often necessary for program to run.
13. 3. VB is interpreter based language which again slows the working of a program.
4. VB programs requires large libraries to work if you are not a programmer you have
to download them.
5. OOP is missing from VB which is used by all new languages for code reuse.
6. There is no threading support in VB although it is available in VB.NET.
7. VB is good for windows applications but it is poor in web applications.
8. Draw architecture of .NET framework and also explain every component in
detail. Also state the use of console, windows forms, asp.net and .net remoting.
Ans:
Common Language Infrastructure (CLI)
The core aspects of the .NET Framework lie within the Common Language
Infrastructure, or CLI. The purpose of the CLI is to provide a language-neutral platform
for application development and execution, including functions for exception handling,
garbage collection, security, and interoperability. Microsoft's implementation of the
CLI is called the Common Language Runtime or CLR.
Assemblies
The CLI code is housed in .NET assemblies. As mandated by specification, assemblies
are stored in the Portable Executable (PE) format, common on the Windows platform
for all DLL and EXE files. The assembly consists of one or more files, one of which
must contain the manifest, which has the metadata for the assembly. The complete
name of an assembly contains its simple text name, version number, culture, and public
key token. The public key token is a unique hash generated when the assembly is
compiled, thus two assemblies with the same public key token are guaranteed to be
identical from the point of view of the framework. A private key can also be specified
known only to the creator of the assembly and can be used for strong naming and to
guarantee that the assembly is from the same author when a new version of the
assembly is compiled (required to add an assembly to the Global Assembly Cache).
Metadata
All assemblies are self-describing through .NET metadata. The CLR checks the
metadata to ensure that the correct method is called. Metadata is usually generated by
language compilers but developers can create their own metadata through custom
attributes. Metadata contains information about the assembly, and is also used to
implement the reflective programmingcapabilities of .NET Framework.
Security
14. .NET has its own security mechanism with two general features: Code Access
Security (CAS), and validation and verification. Code Access Security is based on
evidence that is associated with a specific assembly. Typically the evidence is the
source of the assembly (whether it is installed on the local machine or has been
downloaded from the intranet or Internet). Code Access Security uses evidence to
determine the permissions granted to the code. Other code can demand that calling code
is granted a specified permission. The demand causes the CLR to perform a call stack
walk: every assembly of each method in the call stack is checked for the required
permission; if any assembly is not granted the permission a security exception is
thrown.
When an assembly is loaded the CLR performs various tests. Two such tests are
validation and verification. During validation the CLR checks that the assembly
contains valid metadata and CIL, and whether the internal tables are correct.
Verification is not so exact. The verification mechanism checks to see if the code does
anything that is 'unsafe'. The algorithm used is quite conservative; hence occasionally
code that is 'safe' does not pass. Unsafe code will only be executed if the assembly has
the 'skip verification' permission, which generally means code that is installed on the
local machine.
Base Class library (BCL) / Framework Class Library
Namespaces in the BCL
System
System. CodeDom
System. Collections
System. Diagnostics
System. Globalization
System. IO
System. Resources
System. Text
System. Text.RegularExpressions
The .NET Framework includes a set of standard class libraries. The class library is
organized in a hierarchy of namespaces. Most of the built in APIs are part of
either System.* or Microsoft.* namespaces. These class libraries implement a large
number of common functions, such as file reading and writing, graphic rendering,
15. database interaction, and XML document manipulation, among others. The .NET class
libraries are available to all .NET languages. The .NET Framework class library is
divided into two parts: the Base Class Library and the Framework Class Library.
The Base Class Library (BCL) includes a small subset of the entire class library and is
the core set of classes that serve as the basic API of theCommon Language Runtime.
The classes in mscorlib.dll and some of the classes
in System.dll and System.core.dll are considered to be a part of the BCL. The BCL
classes are available in both.NETFramework as well as its alternative implementations
including .NET Compact Framework,Microsoft Silverlight and Mono.
The Framework Class Library (FCL) is a superset of the BCL classes and refers to the
entire class library that ships with .NET Framework. It includes an expanded set of
libraries, including WinForms, ADO.NET, ASP.NET,Language Integrated
Query, Windows Presentation Foundation,Windows Communication
Foundation among others. The FCL is much larger in scope than standard libraries for
languages like C++, and comparable in scope to the standard libraries of Java.
Memory management
The .NET Framework CLR frees the developer from the burden of managing memory
(allocating and freeing up when done); instead it does the memory management itself.
To this end, the memory allocated to instantiations of .NET types (objects) is done
contiguously from the managed heap, a pool of memory managed by the CLR. As long
as there exists a reference to an object, which might be either a direct reference to an
object or via agraph of objects, the object is considered to be in use by the CLR. When
there is no reference to an object, and it cannot be reached or used, it becomes garbage.
However, it still holds on to the memory allocated to it. .NET Framework includes
a garbage collector which runs periodically, on a separate thread from the application's
thread, that enumerates all the unusable objects and reclaims the memory allocated to
them.
The .NET Garbage Collector (GC) is a non-deterministic, compacting,
mark-and-sweep garbage collector. The GC runs only when a certain amount of
memory has been used or there is enoughpressure for memory onthe system. Since it is
not guaranteed when the conditions to reclaim memory are reached, the GC runs are
non-deterministic. Each .NET application has a set of roots, which are pointers to
objects on the managed heap (managed objects). These include references to static
objects and objects defined as local variables or method parameters currently in scope,
as well as objects referred to by CPU registers When the GC runs, it pauses the
application, and for each object referred to in the root, it recursively enumerates all the
objects reachable from the root objects and marks them as reachable. It uses .NET
metadata andreflection to discover the objects encapsulated by an object, and then
recursively walk them. It then enumerates all the objects on the heap (which were
initially allocated contiguously) using reflection. All objects not marked as reachable
16. are garbage. This is the mark phase. Since the memory held by garbage is not of any
consequence, it is considered free space. However, this leaves chunks of free space
between objects which were initially contiguous. The objects are
then compacted together, by using memcpy to copy them over to the free space to
make them contiguous again. Any reference to an object invalidated by moving the
object is updated to reflect the new locationby the GC. The application is resumed after
the garbage collection is over.
The GC used by .NET Framework is actually generational. Objects are assigned
a generation; newly created objects belong to Generation 0. The objects that survive a
garbage collectionare tagged as Generation1, and the Generation 1 objects that survive
another collection are Generation 2objects. The .NET Framework uses up to
Generation 2 objects. Higher generation objects are garbage collected less frequently
than lower generation objects. This helps increase the efficiency of garbage collection,
as older objects tend to have a larger lifetime than newer objects. Thus, by removing
older (and thus more likely to survive a collection) objects from the scope of a
collection run, fewer objects need to be checked and compacted.
Console
Console applications refer to the traditional DOS kind of applications like batchscripts.
Here the user is not provided with GUI based applications.
Windows forms
These are the traditional rich client applications including GUI.
ASP.NET web applications
These types of applications include dynamic data driven browser based applications.
.NET Remoting
.NET remoting enables you to build widely distributed applications easily, whether the
application components are all on one computer or spread out across the entire world.
You can build client applications that use objects in other processes on the same
computer or on any other computer that is reachable over its network. You can also
use .NET remoting to communicate with other application domains in the same
process. .NET remoting provides an abstract approach to interprocess communication
that separates the remotable object from a specific client or server application domain
and from a specific mechanism of communication. You can replace one
communication protocol with another, or one serialization format with another without
recompiling the client or the server.
In addition, the remoting system assumes no particular application model. You can
communicate from a Web application, a console application, a Windows Service โ
from almost anything you want to use. Remoting servers can also be any type of
17. application domain. Any application can host remoting objects and provide its services
to any client on its computer or network.
To use .NET remoting to build an application in which two components communicate
directly across an application domain boundary, you need to build only the following:
1. A remotable object.
2. A host application domain to listen for requests for that object.
3. A client application domain that makes requests for that object.
Even in a complex, multiclient or multiserver application, .NET remoting can be
thought of in this way. The host and the client application must also be configured with
the remoting infrastructure and you must understand the lifetime and activation issues
that the remoting infrastructure introduces.