cs4443 - modern programming language - i lecture (1)

Post on 12-Apr-2017

72 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CS4443MODERN PROGRAMMING

LANGUAGE – I Mr. Dilawar

Lecturer,Computer Science Faculty,

Bakhtar UniversityKabul, Afghanistan.

Course Objectives• After successfully completing this course, you will be able to: • Understand the solid concept of .NET technology.• Learn, implement and use the C# programming skills.

Course Outline• Introducing C#

• C# Language Fundamentals

• Introduction to OOP

• Classes and Objects

• Inheritance and Polymorphism

• Structures, Enumeration, Garbage Collection & Nested Classes

• Abstract Classes & Interfaces

Course Outline• Arrays, Collections & String Manipulation

• Exception Handling

• Generics

• Working with Delegates and Events

• C# Language Enhancements

Text Books to Follow• Beginning C# 6.0 Programming with a Visual Studio 2015,

Benjamin Perkins, Wrox Publishers.

• Professional C# 6 and .NET Core 1.0 by Christian Nagel, Wrox Publishers.

Introducing C#Chapter 1

Lecture Outline• The C# language

• The .NET Architecture and .NET Framework

• CLR, MSIL, JITers, FCL, CLS, CTS and GC

• C# compare to C++

• Development Environment

• Console Applications and Windows Form Application

• Working with First Hello World Program in C#

• Understanding namespaces, using keyword, class keyword, main() method and comments in C#

The C# Language• It is an OOP language and has its core, many similarities to Java, C++

and VB.• It combines the power and efficiency of C++, the simple and clean OO design

of Java and the language simplification of VB.

• To understand more clearly, Let’s have discussion on .NET framework first.

The .NET Architecture and .NET Framework• To understand clearly about the mentioned concepts let’s first have a

look on some terms.• Common Language Runtime (CLR)• Microsoft Intermediate Language (MSIL) code• Just In Time Compilers (JITers)• Framework Class Library (FCL)• Common Language Specification (CLS)• Common Type System (CTS)• Garbage Collection (GC)

The .NET Architecture and .NET Framework• Common Language Runtime (CLR)• Also called .NET runtime in short.• It is a framework layer that resides above

the OS and handles the execution of all the .NET application.• Or simply, CLR is used to run .NET programs.

• The program goes through the CLR while executing.

The .NET Architecture and .NET Framework• Microsoft Intermediate Language (MSIL) Code• In .NET complaint language, the source code is not directly converted into

binary code.• It is converted to an intermediate code known as MSIL.

• MSIL code is interpreted by CLR.• MSIL is OS and hardware-independent code that is later converted to

executable code (native code).• Cross language relationships are possible as MSIL code is similar for each .NET

language.

The .NET Architecture and .NET Framework• Microsoft Intermediate Language (MSIL) Code

The .NET Architecture and .NET Framework• Just In Time Compilers (JITers)• When IL code needs to be executed, the CLR invokes the JIT compiler.• The JIT generates the native code (.exe or .dll) from IL.

• Generates machine specific and OS specific code.

• The just-in-time part of the name reflects the fact that CIL code is compiled only when it is needed.• The CLR reuses the same copy without re-compiling.

The .NET Architecture and .NET Framework• Framework Class Library(FCL)• FCL is a huge framework (or Base) Class Library (FCL) for common, usual tasks.• FCL contains thousands of classes to provide access to Windows API and

common functions like string manipulation, common data structures, IO, streams, threads, security, network programming, windows programming, web programming, data access etc…• It is simply the largest standard library ever shipped with any development

environment or programming languages.• The classes in FCL can be used in program as any other class.

The .NET Architecture and .NET Framework• Common Language Specification (CLS)• Earlier, we used the term ‘.NET Complaint Language’ and stated that all

the .NET complaint languages can make use of CLR and FCL.

What makes a language a .NET complaint language?

The .NET Architecture and .NET Framework• Common Language Specification (CLS)• The answer is the Common Language Specification (CLS).• Microsoft has released a small set of specifications that each language should

meet to qualify as a .NET complaint language.• CLS basically addresses language design issues and lays down certain

standards.• For instance, there shouldn’t be any global function declarations, no pointers, no

multiple inheritance and things like that.

• The more you keep your code inside the boundary of CLS, it is guaranteed to be usable in any other .NET language.

The .NET Architecture and .NET Framework• Common Type System (CTS)• CTS defines the basic data types that IL understands.

• Each .NET complaint language should map its data types to these standard data types.

• Makes it possible for the 2 languages to communicate with each other by passing/receiving parameter's to and from each other.

• E.g. CTS defines a type, Int32, an integral data type of 32 bits (4 bytes) which is mapped by C# through int and VB.NET through its Integer data type.

The .NET Architecture and .NET Framework• Garbage Collection (GC)• CLR also contains the Garbage Collector (GC), which runs in a low-priority

thread and checks for un-referenced, dynamically allocated memory space.• It finds some data that is no longer referenced by any variable/reference, it

re-claims it and returns it to the OS.• The standard Garbage Collector frees the programmer from keeping track of

dangling data.

The .NET Architecture and .NET Framework

The .NET Architecture and .NET Framework

The .NET Architecture and .NET Framework

The .NET Architecture and .NET Framework

The .NET Architecture and .NET Framework• The .NET framework is the

combination of layers of CLR, FCL, Data and XML classes and our Windows, Web applications, and Web Services.

• The .NET framework consists primarily of a huge library of code that you use from your client languages such as C# using OOP techniques.

The .NET Architecture and .NET Framework• This library is categorized into different modules.• E.g. one module contains the building blocks for Windows applications,

another for network programming, and another for Web development.

• Part of the .NET library defines some basic types – CTS.• A type is representation of data.

• It also includes the CLR, which is responsible for the execution of all applications developed using the .NET library.

Applications You Can Write with C#• Console Application

• Desktop Application

• Windows Store Application• Using WPF.

• Cloud/Web Applications

• Web APIs

• WCF • Distributed applications.

C# Compare to C++

Do it Yourself…..!!!

Development Environment• You can either go with VS or VCE.

Console and Windows Forms Application• Console applications are those that don’t make use of the

graphical Windows environment.• You won’t have to worry about buttons, menus, interaction with the

mouse pointer and so on.

• Desktop applications are applications that have the look and feel of standard Windows applications, including the familiar icons to maximize, minimize, and close an application.

The lab will demonstrate the creation of applications.

Working with First Hello World Program in C#

Understanding the Hello World Program• Namespaces in C#• A namespace is simply a logical collection of related classes in C#.

• E.g. Bundle all related database activity classes into a single namespace.

• C# doesn’t allows two classes having the same name in the program.• Namespaces are used.

• The namespace may contain classes, events, exceptions, delegates and even other namespaces called internal namespaces.• Written in the body of namespace.

• Similar to packages in Java and namespaces in standard C++.

Understanding the Hello World Program• Namespaces in C#

Understanding the Hello World Program• The using Keyword• It allows us to use the classes in the namespace specified.• In the previous example, the use keyword allows us to access the classes

available in the System namespace.• It allows us to access the classes in the referenced namespaces, not in

internal/child namespaces.• We use dot operator and name of child namespace to access the classes of child.

• E.g. using System.Collections;

Understanding the Hello World Program• The class Keyword• All our C# programs contains at least one class.• The Main() method resides in one of these classes.• Classes are a combination of data (fields) and functions (methods) the can be

performed on the data in order to achieve the solution to our program.• Classes in C# are defined using the class keyword followed name of class.

Understanding the Hello World Program• The Main() Method• The standard signature of Main() method in C# is:

static void Main(string[] args)• The Main() method is the entry point of our program.• The Main() method is designated as static and it will called by CLR without

making any object of HelloWorld class.• The method is also declared as void, which describe no value return.• string[] args is the list of parameters that can be passed to main while

executing the program from command line.

Understanding the Hello World Program• Printing on the Console

Console.WriteLine(“Hello World”);• Here we called WriteLine(), a static method of the Console class

defined in the System namespace.• This method takes a string (enclosed in double quotation marks) and its

parameters and prints it on the console window.

Understanding the Hello World Program• Comments• Line, Block, and Documentation comment

Points to Remember

Points to Remember

More Interactive HelloWorld Application

Summery• The C# language

• The .NET Architecture and .NET Framework

• CLR, MSIL, JITers, FCL, CLS, CTS and GC

• C# compare to C++

• Development Environment

• Console Applications and Windows Form Application

• Working with First Hello World Program in C#

• Understanding namespaces, using keyword, class keyword, main() method and comments in C#

Thank YouFor your Patience

top related