cs4443 - modern programming language - i lecture (1)

41
CS4443 MODERN PROGRAMMING LANGUAGE – I Mr. Dilawar Lecturer, Computer Science Faculty, Bakhtar University Kabul, Afghanistan.

Upload: dilawar-khan

Post on 12-Apr-2017

72 views

Category:

Education


2 download

TRANSCRIPT

Page 1: CS4443 - Modern Programming Language - I Lecture (1)

CS4443MODERN PROGRAMMING

LANGUAGE – I Mr. Dilawar

Lecturer,Computer Science Faculty,

Bakhtar UniversityKabul, Afghanistan.

Page 2: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 3: CS4443 - Modern Programming Language - I Lecture (1)

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

Page 4: CS4443 - Modern Programming Language - I Lecture (1)

Course Outline• Arrays, Collections & String Manipulation

• Exception Handling

• Generics

• Working with Delegates and Events

• C# Language Enhancements

Page 5: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 6: CS4443 - Modern Programming Language - I Lecture (1)

Introducing C#Chapter 1

Page 7: CS4443 - Modern Programming Language - I Lecture (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#

Page 8: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 9: CS4443 - Modern Programming Language - I Lecture (1)

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)

Page 10: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 11: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 12: CS4443 - Modern Programming Language - I Lecture (1)

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

Page 13: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 14: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 15: CS4443 - Modern Programming Language - I Lecture (1)

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?

Page 16: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 17: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 18: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 19: CS4443 - Modern Programming Language - I Lecture (1)

The .NET Architecture and .NET Framework

Page 20: CS4443 - Modern Programming Language - I Lecture (1)

The .NET Architecture and .NET Framework

Page 21: CS4443 - Modern Programming Language - I Lecture (1)

The .NET Architecture and .NET Framework

Page 22: CS4443 - Modern Programming Language - I Lecture (1)

The .NET Architecture and .NET Framework

Page 23: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 24: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 25: CS4443 - Modern Programming Language - I Lecture (1)

Applications You Can Write with C#• Console Application

• Desktop Application

• Windows Store Application• Using WPF.

• Cloud/Web Applications

• Web APIs

• WCF • Distributed applications.

Page 26: CS4443 - Modern Programming Language - I Lecture (1)

C# Compare to C++

Do it Yourself…..!!!

Page 27: CS4443 - Modern Programming Language - I Lecture (1)

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

Page 28: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 29: CS4443 - Modern Programming Language - I Lecture (1)

Working with First Hello World Program in C#

Page 30: CS4443 - Modern Programming Language - I Lecture (1)

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++.

Page 31: CS4443 - Modern Programming Language - I Lecture (1)

Understanding the Hello World Program• Namespaces in C#

Page 32: CS4443 - Modern Programming Language - I Lecture (1)

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;

Page 33: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 34: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 35: CS4443 - Modern Programming Language - I Lecture (1)

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.

Page 36: CS4443 - Modern Programming Language - I Lecture (1)

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

Page 37: CS4443 - Modern Programming Language - I Lecture (1)

Points to Remember

Page 38: CS4443 - Modern Programming Language - I Lecture (1)

Points to Remember

Page 39: CS4443 - Modern Programming Language - I Lecture (1)

More Interactive HelloWorld Application

Page 40: CS4443 - Modern Programming Language - I Lecture (1)

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#

Page 41: CS4443 - Modern Programming Language - I Lecture (1)

Thank YouFor your Patience