Microsoft NET Object Oriented Software Engineering Course Presentation
Microsoft. NET Object Oriented Software Engineering Course Presentation Murat Can Ganiz 04/01/2004 Murat Can Ganiz, Lehigh University, 2004
Agenda n . NET n C# n . NET vs. J 2 EE (C# vs. Java) n Any. NET or C# programmers here? Murat Can Ganiz, Lehigh University, 2004 2
Definition… n “Microsoft. NET is a set of Microsoftware technologies for connecting information, people, systems and devices. ” n Defining the Basic Elements of. NET: http: //www. microsoft. com/net/basics/whatis. asp n In real terms to the developer: q A new platform for building applications that run in stand-alone mode or over the Internet Murat Can Ganiz, Lehigh University, 2004 3
Evolution n Next Generation of COM: q Component oriented software: n n n Common Object Runtime: q An execution environment for components written in any language: n n n Win 32/C-style APIs are outdated COM was step in right direction, but painful to program with COM was restricted to VB, C++ Binary compatibility/portability an issue: x 86 version of COM component needed to be compiled for e. g. Power. PC Memory management also a pain Eventually became. NET with incorporation of Web Services Standardised API Web Services: q Interoperability is key in the connected world: n Require open standards for interoperability and leveraging legacy code Murat Can Ganiz, Lehigh University, 2004 4
Architecture Murat Can Ganiz, Lehigh University, 2004 5
. NET Core Components • FCL is Framework Class Library, comparable to JDK’s library Murat Can Ganiz, Lehigh University, 2004 6
Java and. NET: Runtime environments n Java q q q n Intermediate language is bytecode Original design targeted interpretation Java VMs with JIT compilation are now also used . NET Framework q q Intermediate language is MSIL Provides JIT compilation What is JIT? Just-In-Time compilation: translates a bytecode method into a native method on the fly, so as to remove the interpretation overhead Murat Can Ganiz, Lehigh University, 2004 7
Common Language Runtime n CLR sits on top of OS to provide a virtual environment for hosting managed applications q q n n CLR loads modules containing executable and executes their code Code might be managed or unmanaged q n n What is similar to in Java? Java Virtual Machine (JVM) In either case the CLR determines what to do with it Managed Code consists of instructions written in a pseudo-machine language called common intermediate language, or IL. IL instructions are just-in-time (JIT) compiled into native machine code at run time Murat Can Ganiz, Lehigh University, 2004 8
Compiling and executing managed code Compilation Source Code Language Compiler Microsoft Intermediate Language (MSIL) The first time each method is called Native Code JIT Compiler Execution Murat Can Ganiz, Lehigh University, 2004 9
Common Language Runtime Murat Can Ganiz, Lehigh University, 2004 10
C# Murat Can Ganiz, Lehigh University, 2004
. NET languages n Over 20. NET-compatible languages q n Most are provided by 3 rd parties . NET languages provided by Microsoft q q q C++ Visual Basic C# Murat Can Ganiz, Lehigh University, 2004 12
Language Compiler List n n n Ada APL Basic (Visual Basic) C# C C++ Java Language COBOL Component Pascal (Queensland U Tech) ECMAScript (JScript) Eiffel (Monash U. ) Haskell (Utrecht U. ) n n n n n lcc (MS Research Redmond) Mondrian (Utrecht) ML (MS Research Cambridge) Mercury (Melbourne U. ) Oberon (Zurich University) Oz (Univ of Saarlandes) Perl Python Scheme (Northwestern U. ) Small. Talk Murat Can Ganiz, Lehigh University, 2004 13
Why C# ? n Important features are spread out over multiple languages q n Old languages + new features = poor syntax q q n Example: do you think developers should have to choose between pointers (C++) or garbage collection (Java)? Garbage collection in C++? Event-driven GUIs in Java? Increase developer productivity! q q q Type safety Garbage collection Exceptions Murat Can Ganiz, Lehigh University, 2004 14
The safety of Java n n n 100% object oriented Automatic garbage collection Array bounds checking at runtime Strict type checking Structured exception handling Murat Can Ganiz, Lehigh University, 2004 15
The ease of Visual Basic n First class support for properties n First class support for events n foreach loops Murat Can Ganiz, Lehigh University, 2004 16
The power of C++ n n Enumerations Operator overloading q n Function pointers q q n Mathematical, Indexing, and Casting Called “delegates” Type safe Structs Murat Can Ganiz, Lehigh University, 2004 17
The power of C++ n Option to pass parameters by reference or by value n Can disable type-safety, garbage collection, and bounds checking n Can directly manipulate memory with pointers Murat Can Ganiz, Lehigh University, 2004 18
“foreach” loops n Iterates over arrays or any class that implements the IEnumerable interface Int 32[] my. Array = new Int 32[]{10, 20, 30, 40}; foreach(Int 32 i in my. Array){ Console. Write. Line(i); } Murat Can Ganiz, Lehigh University, 2004 19
Automatic “boxing” n Automatically converts primitive values to objects as needed Stack s s. push(. . . int x = = new Stack(); new Integer( 42 ) ); ((Integer)s. pop()). int. Value(); Stack s s. push(. . . int x = = new Stack(); 42 ); (int)s. pop(); Murat Can Ganiz, Lehigh University, 2004 20
Inheritance and interfaces n C++ syntax q n n Simply use a colon and separate by commas Can inherit from one base class Can implement any number of interfaces class Array. List : Collection, IEnumerable { … } Murat Can Ganiz, Lehigh University, 2004 21
Fruit example: class Fruit & constructor using System; namespace Fruit. Project 1 { public abstract class Fruit { protected string color; protected double size; protected Point center; /// <summary> /// Constructor with parameters /// </summary> /// <param name="color"></param> /// <param name="size"></param> /// <param name="center"></param> protected Fruit(string color, double size, Point center) { My. Exception ex = new My. Exception(); if (valid. Color(color)) this. color = color; else { ex. what. Error = "Invalid color"; throw ex; } if (valid. Size(size)) this. size = size; else { ex. what. Error = "Invalid size"; throw ex; } this. center = center; } Murat Can Ganiz, Lehigh University, 2004 22
Fruit example: a few Fruit methods public void change. Size(double size) { My. Exception ex = new My. Exception(); if (valid. Size(size)) this. size = size; else { ex. what. Error = "Invalid size"; throw ex; } } public double get. Size() { return size; } public abstract bool valid. Size(double size); public abstract bool valid. Color(string color); public abstract void print(); /// <summary> /// For identifying object types /// </summary> /// <returns>Type of the object</returns> public override string To. String() { return "Fruit"; } Murat Can Ganiz, Lehigh University, 2004 23
A couple of methods from class Apple public override bool valid. Size(double size) { if ((size>500) || (size<10)) return false; else return true; } public override void print() { // Automatically invoke To. String methods of object parts Console. Write. Line("Type: " + this + "- size: " + this. size + "- color: " + this. color + "- center" + this. center); } Murat Can Ganiz, Lehigh University, 2004 24
Snippets from class Bowl using System; using System. Collections; namespace Fruit. Project 1 { /// <summary> /// class Bowl models a bowl of fruit /// </summary> public class Bowl { private int capacity; private Array. List fruit. List = new Array. List(); public Bowl(int capacity) { this. capacity = capacity; } public int get. Capacity() { return capacity; } public int get. Numberof. Fruits() { return fruit. List. Count; } public bool add. Fruit(Fruit f) { if (fruit. List. Count<capacity) fruit. List. Add(f); else return false; return true; } //More methods… } Murat Can Ganiz, Lehigh University, 2004 25
. NET vs. J 2 EE Murat Can Ganiz, Lehigh University, 2004
Basic Truths n J 2 EE n n n Java-centric and platform-neutral J 2 EE is not a product you buy from Sun. J 2 EE is a set of specifications which indicate how various J 2 EE functions must interoperate If I don’t buy J 2 EE from Sun, how does Sun make money? J 2 EE 1. 4 released with features to completely support web services – JAX-RPC 1. 1 API, J 2 EE Management 1. 0 API, web service endpoints etc. (Hard to learn, hard to implement!) Murat Can Ganiz, Lehigh University, 2004 27
Basic Truths n . NET n n n Windows-centric and language-neutral. NET is a Microsoft product strategy that includes a range of products from development tools and servers to end-user applications. Plans to make. NET platform neutral are in progress, Mono –open source implementation of the. NET development environment ( http: //www. go-mono. com ) Murat Can Ganiz, Lehigh University, 2004 28
Typical N-tier application architecture Murat Can Ganiz, Lehigh University, 2004 29
. NET and Java: application platforms n . NET q n The. NET Framework Java q q Java application servers Products include: n n n IBM Web. Sphere Application Server BEA Web. Logic Application Server Sun i. Planet Application Server Oracle Application Server Many others Murat Can Ganiz, Lehigh University, 2004 30
. NET vs. Java: standard libraries n . NET Framework class library q q q n Defined by Microsoft Somewhat Windows-oriented Organized into a hierarchy of namespaces J 2 SE, J 2 EE q q q Defined by Sun and the Java Community Process Not bound to any operating system Defined as packages and interfaces Murat Can Ganiz, Lehigh University, 2004 31
Class Libraries Murat Can Ganiz, Lehigh University, 2004 32
. NET Class Library n n n n n IO GUI Programming System Information Collections Components Application Configuration Connecting to Databases (ADO. NET) Tracing and Logging Manipulating Images/Graphics Murat Can Ganiz, Lehigh University, 2004 33
Class Library n n n n n Interoperability with COM Globalization and Internationalization Network Programming with Sockets Remoting Serialization XML Security and Cryptography Threading Web Services Murat Can Ganiz, Lehigh University, 2004 34
Thanks… This presentation available at: www. cse. lehigh. edu/~glennb/oose/Csharp_dot. NET. ppt Questions? murat@lehigh. edu (Murat Ganiz) Murat Can Ganiz, Lehigh University, 2004
- Slides: 35