Top Banner
Synapse India Dotnet Framework Development
26

Synapse India Dotnet Framework Development

Jun 02, 2018

Download

Documents

tarunsingh19866
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 1/26

Synapse India DotnetFramework Development

Page 2: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 2/26

Agenda

• Goals

• Background Information• C# - Up and Running

• Quick Comparison to Java

• Networking Namespaces

• References

Page 3: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 3/26

Goals

• Provide enough information to allow you to

follow the code samples• Highlight key differences with Java

• Tell you where you can get the compilers

• Tell you where to go for more details on C#

• Tell you where to go for more detailedcomparisons with Java

• Not to debate which is better, more important,faster, slower, or looks better in emacs

Page 4: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 4/26

Quick Glossary

• BCL – Base Class Library

• CLR – Common Language Runtime• GUI – Graphic User Interface

• MSIL – Microsoft Intermediate Language

• MS – Microsoft

• SCM – Service Control Manager

SOA – Service Oriented Architecture

Page 5: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 5/26

.NET

• .NET is:

• Microsoft’s Platform for Windows Development  • CLR – the Virtual Machine that runs MSIL aka MS

Byte Code

BCL aka .NET Framework•  A set of compilers that can generate MSIL C#,

Visual Basic, C++, Java (the MS flavor)

• Most interoperate with each other

Page 6: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 6/26

C#

• Language Created by Anders Hejlsberg (fatherof Delphi)

• The Derivation History can be viewed here:Principle Influencing Languages:

• C++

• Delphi

• Java

• Designed to be an optimal Windowsdevelopment language

Page 7: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 7/26

C# - Up and Running

•  A Simple C# Application

•  Application Types• Compiler & Run Time

Page 8: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 8/26

A Sample C# Application

Page 9: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 9/26

Application Types

• Console Application

Has standard streams (out, in, err)• GUI can be added manually

• Windows Application

• GUI based

• No standard streams (out, in, err)

• Main thread is shared by the GUI message pump & yourcode

Service• No standard streams (out, in, err)

• Main thread is commandeered by the SCM

• No GUI

Page 10: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 10/26

Compiler Options from MS

• SDK contains the command line compiler

(C:\WINDOWS\Microsoft.NET\Framework\{version}\csc.exe)

• {version} looks like v2.0.50727

Express Edition – Free IDE to work with VisualC#

• Reduced runctionality version of Visual Studio

Visual Studio – The full development system• Optimizations, Data Access, Multi-Language, etc

• $$$

Page 11: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 11/26

Options Beyond MS

• Mono

• Open source development SDK for .NET• Windows, Linux, Mac OS X, Solaris, Unix

• Sponsored by Novell

Food for thought: Suse + KDE + Mono = ???• Sharp Develop

• Open source IDE that uses .NET SDK or Mono

Written in C#

Page 12: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 12/26

Quick Comparison to Java

• What’s the same 

• Syntactically Similar• Garbage Collected VM Environment

• Immutable Strings

Exceptions (try / catch / finally)• Object as root

• Single Inheritance model

Multi-Interface model

’ ff &

Page 13: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 13/26

What’s Different & Relevant 

• Keywords

• base vs. super• lock vs. synchronized

• : vs. extends & implements

is vs. instanceof• Exceptions

• No throws keyword

Wh t’ Diff t & R l t t

Page 14: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 14/26

What’s Different & Relevant –  cont.

• Namespaces

• namespace vs. package• using vs. import

• No wildcard using

• using namespace; // brings it all in – non-recursive

• Type Aliasing

• using newtypename = namespace.type;

• Directory structure != namespace hierarchy (as in

C++)

Wh t’ Diff t & R l t t

Page 15: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 15/26

What’s Different & Relevant –  cont.• Properties

• get, set and get/set•  public string MyProperty { get { return(_text); } set { _text =

value; } }

• Delegates• Type safe function pointers

• To create•  public delegate bool CompareHandler(object left, object

right);

To use• CompareHandler ch = new CompareHandler(myMethod);

• bool retval = ch(obj1, obj2);

Wh t’ Diff t & R l t t

Page 16: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 16/26

What’s Different & Relevant –  cont.

• Enumerations

•  public enum Protocol { UDP, TCP };•  public enum Direction { Up = 0, Down = 1, Left = 2,

Right = 4 };

Direction d = Direction.Down;• int x = (int)d;

• Direction d = Direction.Parse(“Up”); 

• string s = d.ToString();

Wh t’ Diff t & R l t t

Page 17: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 17/26

What’s Different & Relevant –  cont.

• Value Types

• Primitives are the same plus• Unsigned values

• ubyte, ushort, uint, ulong

• Careful : by te in java is sb yte in C#

• Class objects to wrap primitives• Int32 x = new Int32(4);

• int x = Int32.Parse(“4”); 

Wh t’ Diff t & R l t t

Page 18: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 18/26

What’s Different & Relevant –  cont.

• Structures

• Stack based elements, not heap based• Value type

• struct packet { int code; string data; };

• Boxing / Unboxing• Conversion between value type and reference type

•  packet p = new packet();

object o = (object)p; // boxed•  packet p2 = (packet)o; // unboxed

• Significant performance cost!

Wh t’ Diff t & R l t t

Page 19: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 19/26

What’s Different & Relevant –  cont.

• Cross Platform Support

• .NET from Microsoft is not cross platform• It is for Windows only

• Mono can run cross platform, but is unproven in

large production environments• MS is currently resisting moving cross platform

• The future is not set

Page 20: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 20/26

What’s not Relevant, but Useful 

•  App Domains

• One or more per process• Represents a VM hosted logical process

• Communications between App Domains requires

marshalling (IPC)•  Assemblies

• Similar to Java JAR files

Physically they are EXE and/or DLL files

Wh t’ t R l t b t U f l

Page 21: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 21/26

What’s not Relevant, but Useful 

•  Attributes

• Meta tags that provide run time information for atype, NOT the instance

• Example: [Serializable] public class foo { int x; };

[Serializable] is converted into the classSerializableAttribute

•  Attributes can be retrieved at run time

• Many framework sub-systems use attributes

• Serialization, XML, Interop, Conditional, Obsolete, etc… 

Wh t’ t R l t b t U f l

Page 22: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 22/26

What’s not Relevant, but Useful 

• Polymorphism

• Methods default to being non-virtual

• To be virtual it must be defined as virtual

• eg: public virtual int Add(int x, int y);

• To override a virtual method, you use the override

keyword• eg. public override int Add(int x, int y);

• Methods not marked virtual are equivalent to Java

final methods• Methods can be marked with new to break the

virtual chain

Wh t’ t R l t b t U f l

Page 23: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 23/26

What’s not Relevant, but Useful 

• Interop

•  Access to native code through attributes• [DllImport(“user32.dll”)] static int

GetSystemMetrics(int);

The DllImport attribute informs the compiler andruntime that the tagged method is inside a nativeDLL.

• Options such as the actual name in the DLL,

marshalling strategies, calling convention, and morecan be set using the attribute

What’s not Relevant but Useful

Page 24: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 24/26

What’s not Relevant, but Useful • .NET 2.0 – out now

• Generics

• Partial Types

 Anonymous Methods• Nullable Types

• .Net 3.0• Its all about data

• Tuples & Query constructs

public void  Linq1()

{int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

var  lowNums = from n in numbers where n < 5 select n;

Console.WriteLine("Numbers < 5:");

foreach (var  x in lowNums) { Console.WriteLine(x); }

}

Result

Numbers < 5:41320

Networking Namespaces

Page 25: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 25/26

Networking Namespaces

• System.Messaging• Functionality for MSMQ

• System.Net• Provides access to higher protocols (FTP, HTTP, DNS)

• System.Net.Information• Network information classes providing statistics, interface

information, and ping• System.Net.Sockets

• Light weight wrappers around TCP and UDP sockets

• System.Runtime.Remoting

• Provides functionality for high level distributed programming(similar to RMI)

• System.Web• Provides high level access to HTTP

Future of NET Networking

Page 26: Synapse India Dotnet Framework Development

8/10/2019 Synapse India Dotnet Framework Development

http://slidepdf.com/reader/full/synapse-india-dotnet-framework-development 26/26

Future of .NET Networking

• Windows Communications Foundation

•Formally code named Indigo

• Designed to make SOA an integral part of Windows

• Tight coupling with .NET designs