COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

14
COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

Transcript of COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

Page 1: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

COP 2360 – C# Programming

The Dot Net Environment

The Evolution from C to C#

Page 2: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

Dot Net Platform

Platforms provide environments for development and execution of programs

Two “largest” platforms out there today is Microsoft .Net and Java

– Both provide similar executable modules that rely on an “interpreter” at execution time, but in different ways

.Net runs only on Microsoft Windows devices, – but there are a many front end languages that can be used to generate the

“Common Intermediate Language” (CIL).– Only one IDE is available

Java provides only the Java programming language, – Open Source (although now owned by Oracle)– Multiple IDEs that all pretty much try to do the same thing.– The resulting “bytecodes” can be used on several different operating

systems

Page 3: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

Main Objective of .Net Platform

Provide component based support for Web Applications, Web Services and Windows Application.

– Classes are self-describing and reusable When I had hair

– One would compile a program to an object file, and then link the object files into an executable

Same subroutine was compiled and placed into EXE over and over. (Each EXE would have a copy)

When I had a comb over– Concept of DLL (Dynamic Link Library) introduced

Separate pre-compiled routines that could be called from main programs to do work

Was a mess with the way it was managed usually resulting in multiple DLLs on a machine that did the same thing, but different version.

Page 4: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

Main Objective of .Net Platform

When I shaved it all off:– .Net Assemblies were introduced that used the Common

Intermediate Language (CIL) approach to produce reusable components

Assemblies result in either an EXE or a DLL– Exe has a “Main” entry point– DLL’s can have multiple entry points that are self-described– DLL’s can be shared between programs (or as a Web Service)

Assemblies are what execute through the Common Languages Runtime (CLR)

Page 5: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

.Net Platform Components

.Net Framework– CLR (Common Language Runtime)

Virtual machine that “interprets” the CIL and manages the execution of the program or call to the library

– Framework Class Library A set of base classes used by C# that can be used by other .Net

Languages. (Types, Strings, Objects, etc) Compilers Interactive Development Environment (Visual Studio) .Net Enterprise Servers (SQL Server, BizTalk, Sharepoint for

example) .Net Building Block Services

Page 6: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

In the beginning there was machine code. Programs were entered with a bunch of ones and zeroes (and if you were lucky, maybe in octal or hex). Every machine was different. Life pretty much sucked.

Next came machine language which mapped a mnemonic to an instruction, and introduced variables instead of direct addressing. Life sucked, but not as bad.

Then development programming took off and all the academic and business types got their own damn programming languages. (COBOL, FORTRAN, Basic, PL/1, LISP, etc.)

Finally, the “C” language (based somewhat on ALGOL) was introduced that added a layer of abstraction for lower level system development making it easier and more consistent to program, but still allowing for lower level “stuff” to happen that may not be that welcomed in a development language like Basic, COBOL or FORTRAN.

– All the basics were there. If you needed something else (string manipulation for example), you wrote it yourself or tried to find someone else that already did it and borrowed the code.

– Machine Language finally could be replaced with it’s own “higher level language”– Programs (and operating systems) that were traditionally written in Assembly Language,

quickly adopted “C” Unix, Microsoft Windows for example

– BTW – Yes, there was a “B” developed at Bell Labs. Not so sure about an “A” though!!

Page 7: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

C++ was introduced to support Object Oriented Programming and correct some “mistakes” in base “C”

– Implementation of the New and Delete operators to better request and remove memory allocations during run-time

– Providing byRef type arguments to function calls– Basing types on Classes that can inherit their attributes from other

Classes allowing developers to create their own new data types– Improvements to the struct concept (well, really making a struct

and a class the same thing). Both classes and structures can contain data definitions as well as functions and can specify the visibility of these attributes.

– Many applications written in C were upgraded to C++ when it become available.

Page 8: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

Java was then developed from C++ to provide an overall IDE that resulted in simplifying development and deployment.

– Java Virtual Machine and bytecode meant that one could compile on one operating system and run the resulting object on another

– All Java code is contained in classes (a Java program is a collection of classes, where at least one of these classes contains a main).

– There is compile-time strong type checking between all the classes in a program, regardless of which source files the class definitions are contained in.

– Therefore, there is no need for header files, and header files are not supported.

– Like C, and unlike C++, call by value is the only parameter passing mechanism.

– Java has much more restrictive use of pointers (no address or explicit dereference operator).

Page 9: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

More Info on Java– Note that in Java, a variable is a local variable, parameter,

or a field.– In Java, all garbage collection is automatic.– The existence of a Java execution system (i.e., the JVM)

that guarantees how primitive types are implemented, promotes safety, guarantees binary portability, and provides dynamic linking.

– A modified form of Java became the language for Android App development.

Page 10: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

C# is a modification of Java (in an approximate sense, C# is an enlargement of Java) that:

– Includes some shout-outs from VB and Delphi– Corrects mistakes made in the Java design (e.g., call by reference

and printf style formatting put back in language).– Provides a type system that allows special objects (i.e., instances

of structs) to be treated as values, as opposed to Java where only pointers and instances of primitive types are treated as values (i.e., can be values of variables).

– In C#, the primitive types are defined as structs, arguably providing C# with a type system that is more unified than the one in Java, because, in C#, all types derive from Object (including ValueType), and all value types (i.e., enumeration types and structs) derive from ValueType.

Page 11: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

In C#– A type is either a value type (in which case it derives from ValueType) or a

reference type (such as a class). – Incorporates improved versions of some C++ features (such as operator overloading)

that were excluded from Java.– Provides the option of including unsafe code, in which unprotected pointers are used,

so that C# can replace C and C++ in low-level implementations such as device drivers.

– Provides features (such as properties, events, and attributes) that are useful for component-based programming.

– Provides features such as indexers that are convenient for implementing collection types.

– Provides improved versions of statements from non-C-family languages (e.g., the foreach statement).

Page 12: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

From C To Shining C#

C# Also:– Provides, starting with C# 3.0 (C# 2008), support

for functional programming, via a construct called lambda expressions.

– Provides, starting with C# 4.0 (C# 2010), support for dynamic typing.

– Provides in C# 5.0(C# 2012) improved support for asynchronous programming.

Page 13: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

Top Level Java to C# Comparison

FEATURE JAVA .NET

Execution system JVM (Java Virtual Machine)

CLR (Command Language Run Time)

Class library Java class libraries FCL (Framework Class Library(

Intermediate code bytecodes CIL (Common Intermediate Language)

Unit of deployment class file, jar file assembly

IDE JDeveloper, etc. Visual Studio 2013

SQL API JDBC, SQLJ; TopLink and other ORMs

ADO.NET, ADO.NET Linq to Entities

Web programming API servlets, JSP (Java Server Pages), JSF (Java Server Paces)

ASP.NET Web Forms, ASP.NET MVC (Model View Controller)

GUI programming API AWT, Swing, JavaFX (latter has RIA (rich internet app) support)

Windows Forms, Windows Presentation Foundation (latter has RIA support)

Page 14: COP 2360 – C# Programming The Dot Net Environment The Evolution from C to C#

.NET Other Languages

Because of it’s Common Intermediate Language (CIL) and Common Language Runtime (CLR), .Net provides for many front end languages including:– Visual Basic– COBOL (believe it or not)– F# (Best comparison is a .Net version of Fortran)