04/09/2014
Week 01: Introduction
• Programming Paradigms
• Dot Net Framework Architecture
• C# Compilation and Execution
• Structure of a C# Program
• Console and Windows Applications
Outline
Programming Paradigms
• Structured Programming
• Object Oriented Programming
• Visual Programming
• Component Oriented programming
Visual Programming - Fall 2014
Instructor: Saima Jawad 1
04/09/2014
Structured Programming
• Aimed on improving the clarity, quality, and
development time of a program
• Makes extensive use of subroutines, block
structures and loops
• ALGOL, Pascal, PL/I, C etc.
Structured Programming
Visual Programming - Fall 2014
Instructor: Saima Jawad 2
04/09/2014
Structured Programming
Object-oriented Programming
• Programmers define the data type and the types
of operations (functions) that can be applied to
the data.
• An object includes both data and functions.
• Programmers can create relationships between
objects.
Visual Programming - Fall 2014
Instructor: Saima Jawad 3
04/09/2014
Object-oriented Programming
Visual Programming
• Programming using meaningful visual
representation such as graphics,
drawings, animation or icons.
• Supports visual interaction
Visual Programming - Fall 2014
Instructor: Saima Jawad 4
04/09/2014
Visual Computing
Visual
Programming
Computer
Graphics
Algorithm
Animation
Scientific
User Interfaces Visualization
End User Languages
Related Areas
• Graphical User Interfaces
• Computer Graphics
• Information Visualization / Scientific
Visualization
• End User Languages (Databases etc.)
• Special Purpose Languages (e.g. UML)
• Algorithm Animation
Visual Programming - Fall 2014
Instructor: Saima Jawad 5
04/09/2014
.NET Framework
.NET Framework
Common Language Runtime (CLR)
• a runtime environment
• similar to Java Virtual Machine (JVM)
Framework Class Library (FCL)
• provide services for applications
Visual Programming - Fall 2014
Instructor: Saima Jawad 6
04/09/2014
.NET Architecture
.NET is tiered and modular
.NET Framework
MicroSoft Intermediate Language (MSIL)
o CPU independent set of instructions
o All .NET languages compile into MSIL
o Similar to Java Byte Code
o Also abbreviated as IL
Visual Programming - Fall 2014
Instructor: Saima Jawad 7
04/09/2014
C# Compilation & Execution
C# source
code
MSIL
C#
compiler
CLR
Machine
code
C# Compilation & Execution
• The C# compiler translates C# source code (.cs
files) into a special representation called
Microsoft Intermediate Language (MSIL)
• MSIL is not the machine language for any
traditional CPU, but a virtual machine
• The Common Language Runtime (CLR) then
translates MSIL format to machine code
Visual Programming - Fall 2014
Instructor: Saima Jawad 8
04/09/2014
MSIL Advantages
o Portability between OS
.NET compliant languages are all compiled
into MSIL (portable between OS)
o Language Interoperability
Different languages can communicate easily
MSIL codes from different languages can be
linked together to form a program
Interoperability
Visual
C# VB .NET
J# .NET
Compile
into MSIL
Link the MSIL
MSIL MSIL MSIL codes
CLR generate
single application
(native code)
Windows
Native Code
Visual Programming - Fall 2014
Instructor: Saima Jawad 9
04/09/2014
Framework Class Library
Similar to MFC for Windows Programming
FCL classes are grouped by namespaces and
exported by assemblies
o Namespace similar to Java package
o Assembly similar to .dll
FCL
Some Namespaces in FCL are
o System
o System.IO
o System.Windows.Forms
o System.Drawing
Visual Programming - Fall 2014
Instructor: Saima Jawad 10
04/09/2014
C# Program Structure
• In C#, a program is made up of
– Program specifications (header comments,
optional)
– Library imports (optional)
– One or more class (and namespace) definitions
• A class contains one or more methods
• A method contains program statements
A Simple C# Program
// This program prints a string called "Hello, World!”
using System;
class HelloWorld
{
static void Main(string[] args)
{
Console.WriteLine(“Hello, World!”);
}
}
Visual Programming - Fall 2014
Instructor: Saima Jawad 11
04/09/2014
Namespace
• All .NET library code are organized using namespaces
• To refer to code within a namespace,
– use qualified name (as in System.Console) or
– import explicitly (as in using System; )
using System;
class HelloWorld
class HelloWorld {
{ static void Main(string[] args)
static void Main(string[] args) {
{ System.Console.WriteLine(“Hello”);
Console.WriteLine(“Hello”); }
} }
}
Comments
– Comments are ignored by the compiler: used only
for human readers (i.e., inline documentation)
• Single-line comments use //…
// this comment runs to the end of the line
• Multi-lines comments use /* … */
/* this comment runs to the terminating
symbol, even across line breaks */
Visual Programming - Fall 2014
Instructor: Saima Jawad 12
04/09/2014
Identifiers
• Identifiers are the words that a programmer uses
in a program
• An identifier can be made up of letters, digits, and
the underscore character, they cannot begin with a
digit
• C# is case sensitive, therefore args and Args are
different identifiers
Keywords
• Often we use special identifiers called keywords
that already have a predefined meaning in the
language
– Example: class
• A keyword cannot be used in any other way
• All C# keywords are lowercase
Visual Programming - Fall 2014
Instructor: Saima Jawad 13
04/09/2014
C# Keywords
C# Keywords
abstract as base bool break
byte case catch char checked
class const continue decimal default
delegate do double else enum
event explicit extern false finally
fixed float for foreach get
goto if implicit in int
interface internal is lock long
namespace new null object operator
out override params private protected
public readonly ref return sbyte
sealed set short sizeof stackalloc
static string struct switch this
throw true try typeof uint
ulong unchecked unsafe ushort using
value virtual void volatile while
C# Class Structure
// comments about the class
class HelloWorld
{
class header
class body
Comments can be added almost anywhere
};
Visual Programming - Fall 2014
Instructor: Saima Jawad 14
04/09/2014
C# Class Structure
Each class name is an identifier
Convention: Class names are capitalized, with
each additional English word capitalized as well
(e.g., MyFirstProgram )
Class body starts with a left brace {
Class body ends with a right brace }
C# Methods
Building blocks of a program
The Main() method
Each application must have exactly one
All
programs start by executing the Main
method
Visual Programming - Fall 2014
Instructor: Saima Jawad 15
04/09/2014
Console vs. Windows Applications
• Console Application
– No visual component
– Only text input and output
– Run under Command Prompt or DOS Prompt
• Window Application
– Forms with many different visual components
– Contains Graphical User Interfaces (GUI)
– GUI is more user friendly!
C# Console Application
using System;
Class Hello
{
static void Main(string[] args)
{
Console.Write(“Your Name Please: “);
string name = Console.ReadLine();
Console.WriteLine(“Hello “ + name);
}
}
Visual Programming - Fall 2014
Instructor: Saima Jawad 16
04/09/2014
C# Windows Application
// Printing multiple lines in a dialog Box.
using System;
using System.Windows.Forms;
class Welcome
{
static void Main( string[] args )
{
MessageBox.Show("Welcome\n to\n C#\n programming!");
}
}
Visual Programming - Fall 2014
Instructor: Saima Jawad 17