1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 39: Case Study: C# and.NET COMP 144 Programming Language Concepts Spring 2002 Felix.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Introduction to .NET Framework
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 1: Introduction COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
Principles of Object-Oriented Software Development The language Java.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Introduction to the C# Programming Language for the VB Programmer.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 32: The Java Virtual Machine COMP 144 Programming Language Concepts Spring 2002.
Outline Java program structure Basic program elements
Trey Mack James Moore Osa Osar-Emokpae
History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow 
C#: Project Cool Arthur Ketchel II Keith Francisco Chris McInnis.
INSTRUCTOR: DR MARCO VALTORTA CSCE 330 C# GROUP MEMBERS: KONSTANTINOS MALEGOS YASSER AL-MUTAIRY CHRIS HESTER UNIVERSITY OF SOUTH CAROLINA.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 24: Dynamic Binding COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 22: Object-Oriented Programming COMP 144 Programming Language Concepts Spring 2002.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Java versus C# An introduction to C# and Visual Studio.
Java vs. C# By Abrar Siddiqui.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Lecture 17 Modern Programming Trends JVM, C#, .NET
Session 1 - Introduction and Data Access Layer
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Introduction to.NET Framework. .NET – What Is It? Software platform Language neutral In other words:.NET is not a language (Runtime and a library for.
Compiling and Executing Code in.Net Microsoft Intermediate Language and Common Language Runtime.
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
Component-Based Software Engineering Introduction to.NET Paul Krause.
The Java Programming Language
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
This is delicious cookie you must eat. :O~. Problem Domain Designed to be Reliable, high-performance and secure Comfortable and familiar to Java-language.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
ILM Proprietary and Confidential -
1 C# A brief overview by Jack Senechal and Bryan Powell.
Hoang Anh Viet Hà Nội University of Technology Chapter 1. Introduction to C# Programming.
1 Introduction to Java. 2 What is Java? A programming language. A platform –A virtual machine (JVM) definition. –Runtime environments in diverse hardware.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Applications Development
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
Bill Campbell, UMB Microsoft's.NET C# and The Common Language Runtime.
A Quick Java Course part 1 Michael McDougall CIS 573 September 27 th, 1999.
Introduction to Java John Lewis. Course Overview Introduction Object Orientated Programming Java Structure and Syntax Using the Java Platform Advanced.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
A comparison of C-Sharp and Java Zunaid Jogee Supervisor: T. Stakemire.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
OOP Basics Classes & Methods (c) IDMS/SQL News
Object Oriented Programming Lecture 2: BallWorld.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
CLASSES IN JAVA Primitive Types Example of a Class Allocating Objects of a Class Protecting Class data Constructors Static data and Static Methods.
Introduction to .NET Framework
Basic 1964 PC general purpose Imperative Small Easy to use.
Chapter No. : 1 Introduction to Java.
Lecture 39: Case Study: C# and .NET
Lecture 2: Data Types, Variables, Operators, and Expressions
C# and the .NET Framework
CS360 Windows Programming
Introduction to C# AKEEL AHMED.
Programming in C# CHAPTER 1
Lecturer: Mukhtar Mohamed Ali “Hakaale”
null, true, and false are also reserved.
Introduction to Java Programming
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
(Computer fundamental Lab)
Instructor: Alexander Stoytchev
Presentation transcript:

1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 39: Case Study: C# and.NET COMP 144 Programming Language Concepts Spring 2002 Felix Hernandez-Campos April 29 The University of North Carolina at Chapel Hill

2 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# and.NET In 2000, Microsoft releases a new language, C#, heavily influences by Java and C++In 2000, Microsoft releases a new language, C#, heavily influences by Java and C++ –Is there anything new from the programming languages point of view? Microsoft is making it the key stone in their new development strategy (.NET)Microsoft is making it the key stone in their new development strategy (.NET) –Big bucks… big evil… Let’s have a brief look at it, so you can put it our resumes or simply laugh at Microsoft, depending on your point of view about the worldLet’s have a brief look at it, so you can put it our resumes or simply laugh at Microsoft, depending on your point of view about the world –I’m neutral (yeah, right…)

3 COMP 144 Programming Language Concepts Felix Hernandez-Campos Hello World public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello world!"); } } class HelloWorld { static void Main(string[] args) { System.Console.WriteLine(“Hello world!"); } } JavaJava C#C#

4 COMP 144 Programming Language Concepts Felix Hernandez-Campos Motivation for C#.NET.NET –New development framework that promises to simplify Windows programming »COM/DCOM is hard to learn –Heavy on component orientation –Language independence run-time system »Common Language Run- time (CLR) Framework Class Libraries Windows Common Language Runtime C# programs VB.NET

5 COMP 144 Programming Language Concepts Felix Hernandez-Campos Common Language Runtime It can execute.NET program in an intermediate representation, the Common Language Interface (CLI)It can execute.NET program in an intermediate representation, the Common Language Interface (CLI) CLR is designed to work well in a multi-language environmentCLR is designed to work well in a multi-language environment –Java Virtual Machines is rather Java-oriented –CLR is supposed to work well with imperative programming languages (e.g., C, Pascal) and statically typed object oriented languages (e.g., C#, Eiffel) –Many language have compilers for CLR at different stages of development, including Python, Perl, Scheme, Haskell, Prolog,…

6 COMP 144 Programming Language Concepts Felix Hernandez-Campos Motivation for C# Rapid application development (RAD)Rapid application development (RAD) –Visual development tools/languages such as Visual Basic and Delphi, are very popular and useful »Remember Java Beans lecture –C# is optimized for such development model Platform-independencePlatform-independence –CLR and CLI Access to platform-native resourcesAccess to platform-native resources –A more direct approach than the one taken by Java Native Interface (JNI)

7 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax Comparison with Java If/then/elseIf/then/else int i = 0; if (i == 0) { i = 1; } else { i = 2; } Java C#

8 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax SwitchSwitch int i = 0; switch (i) { case 0: int i = 0; switch (i) { case 0: i = 1; i = 1; break; case 1: break; case 1: i = 2; break; default: i = -1; i = -1; break; } int i = 0; switch (i) { case 0: int i = 0; switch (i) { case 0: i = 1; break; case 1: i = 2; break; default: i = -1; break; } Java C#

9 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax WhileWhile Do/WhileDo/While int i = 0; while (i++ < 10) { } Java C# int i = 0; do { } while (i++ < 10); Java C#

10 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax foreach import java.util.Vector; public static int sum(Vector v) { int sum = 0; for (int j = 0; j < v.size(); j++) { Integer i = (Integer)v.elementAt(j); sum = sum + i.intValue(); } return sum; } using System.Collections; static int SumList(ArrayList theList) { int sum = 0; foreach (int j in theList) { sum = sum + j; } return sum; } Java C#

11 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax Break/ContinueBreak/Continue ReturnReturn int i = 0; while (i++ < 10) { if (i < 5) continue; break; } Java public void returnNothing() { return; } public int returnOne() { return 1; } int i = 0; while (i++ < 10) { if (i < 5) continue; break; } C# public void returnNothing() { return; } public int returnOne() { return 1; }

12 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax Object instantiationObject instantiation Exclusive accessExclusive access Something s = new Something(); Java synchronized(this) { // do something } Something s = new Something(); C# lock(this) { // do something }

13 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax try/catch/finally try { throw new SampleException(); } catch (SampleException ex) { } finally { } try { throw new SampleException(); } catch {} finally { } Java C# catch clause is optional catch clause is optional catch argument is optional catch argument is optional No throws keyword No throws keyword

14 COMP 144 Programming Language Concepts Felix Hernandez-Campos C# Syntax Class definitionClass definition Interface definitionInterface definition Interface implementationInterface implementation class Foo extends Bar {... } Java interface IFoo extends IBar {... } class Foo extends Bar {... } C# interface IFoo : IBar {... } class Foo implements IFoo, IBaz {... } class Bar: IFoo, IBaz { }

15 COMP 144 Programming Language Concepts Felix Hernandez-Campos Other C# Features C# provides Java-style garbage collectionC# provides Java-style garbage collection C# implements a Java- and Delphi-style value/reference-type systemC# implements a Java- and Delphi-style value/reference-type system –Variables of primitive types also act like objects (unlike Java primitive objects) Integer iobj = new Integer(12); System.out.println(iobj.toString()); Console.WriteLine(12.ToString()); Java C#

16 COMP 144 Programming Language Concepts Felix Hernandez-Campos Other C# Features EnumerationsEnumerations enum description: ulong { Good, Bad, Ugly }; Properties (forced getter and setters)Properties (forced getter and setters) TextBlock tb; if (tb.backgroundColor == Color.green) { // "get" is called for comparison tb.backgroundColor = Color.red; // "set" is called tb.backgroundColor = Color.red; // "set" is called } else { tb.backgroundColor = Color.blue; // "set“ is called tb.backgroundColor = Color.blue; // "set“ is called}

17 COMP 144 Programming Language Concepts Felix Hernandez-Campos Other C# Features Get/setGet/set public class TextBlock { // Assume Color is an enum // Assume Color is an enum private Color _bgColor; private Color _fgColor; public Color backgroundColor { get { public Color backgroundColor { get { return _bgColor; return _bgColor; } set { } set { _bgColor = value; } //... and so on... } _bgColor = value; } //... and so on... }}

18 COMP 144 Programming Language Concepts Felix Hernandez-Campos Other C# Features DelegatesDelegates –Safe method reference (solved with interfaces in Java) delegate int Comparator(object a, object b); class Quicksort { static void sort(Comparator c, object[] objectsToSort) { //... quicksort logic leading to a comparison if (c(objectsToSort[left], objectsToSort[pivot]) > 0) { objectsToSort[pivot]) > 0) { // recursive call... // recursive call... } else { //...and so on... } }; } else { //...and so on... } };

19 COMP 144 Programming Language Concepts Felix Hernandez-Campos References Perry, C#, the natural progressionPerry, C#, the natural progression – itw-csharp.html itw-csharp.htmlhttp:// itw-csharp.html Johnson, C#: A language alternative or just J--?Johnson, C#: A language alternative or just J--? – itw-csharp.html itw-csharp.htmlhttp:// itw-csharp.html Meijer and Gough, Technical Overview of the Common Language RuntimeMeijer and Gough, Technical Overview of the Common Language Runtime –