SlideShare a Scribd company logo
1 of 35
Download to read offline
C#	
  for	
  Java	
  Developers	
  

            Jussi	
  Pohjolainen	
  
Tampere	
  University	
  of	
  Applied	
  Sciences	
  
Overview	
  
•  Ecma	
  and	
  ISO	
  Standard	
  
•  Developed	
  by	
  MicrosoD,	
  uses	
  in	
  .NET	
  and	
  
   WP7	
  
•  Most	
  recent	
  version	
  is	
  C#	
  4.0	
  
Versions	
  
Common	
  Language	
  Infrastructure	
  (CLI)	
  
CLI	
  
•  CLI	
  is	
  an	
  open	
  specificaRon	
  that	
  describes	
  
   executable	
  code	
  and	
  runRme	
  environment	
  
•  CLI	
  is	
  core	
  of	
  
    –  MicrosoD	
  .NET	
  Framework	
  
    –  Mono	
  (Open	
  Source)	
  
    –  Portable.net	
  (Open	
  Source)	
  	
  
CTS,	
  CLS,	
  VES,	
  CIL	
  
•  Common	
  Type	
  System	
  (CTS)	
  
    –  A	
  set	
  of	
  data	
  types	
  and	
  operaRons	
  that	
  are	
  share	
  by	
  all	
  
       CTS-­‐compliant	
  programming	
  languages,	
  such	
  as	
  C#	
  and	
  VB	
  
•  Common	
  Language	
  SpecificaRon	
  (CLS)	
  
    –  Set	
  of	
  base	
  rules	
  to	
  which	
  any	
  language	
  targeRng	
  the	
  CLI	
  
       should	
  conform.	
  	
  
•  Virtual	
  ExecuRon	
  System	
  (VES)	
  
    –  VES	
  loads	
  and	
  executes	
  CLI-­‐compaRble	
  programs	
  
•  Common	
  Intermediate	
  Language	
  (CIL)	
  
    –  Intermediate	
  language	
  that	
  is	
  abstracted	
  from	
  the	
  
       plaXorm	
  hardware	
  (In	
  Java:	
  class)	
  
Mono:OSX	
  »	
  C#	
  File	
  
Mono:OSX	
  »	
  Building	
  
Mono:OSX	
  »	
  Running	
  
.NET	
  on	
  Windows	
  7	
  




    Add	
  C:WindowsMicrosoft.NETFrameworkv3.5 to	
  path!	
  
Common	
  Language	
  RunRme:	
  Mac	
  

                                  Dropbox	
  –	
  
                                    folder	
  
Common	
  Language	
  RunRme:	
  Win	
  




                                 And	
  run	
  
                                the	
  .exe	
  in	
  
                                Windows!	
  
Almost	
  the	
  Same	
  but	
  Not	
  Quite	
  

C#	
  
Keywords	
  
•  Single	
  rooted	
  class	
  hierarchy:	
  all	
  objects	
  
   inheritate	
  System.Object	
  
•  Almost	
  every	
  keyword	
  in	
  Java	
  can	
  be	
  found	
  
   from	
  C#	
  
    –  super                            ->   base
    –  instanceof                       ->   is
    –  import                           ->   using
    –  extends / implements             ->   :
•  Otherwise,	
  pre`y	
  much	
  the	
  same	
  
Memory	
  Handling	
  and	
  RunRme	
  
•  Memory	
  Handling	
  
   –  Most	
  objects	
  in	
  C#	
  to	
  heap	
  using	
  new	
  
   –  CLR	
  handles	
  garbage	
  collecRons	
  
•  RunRme	
  
   –  C#	
  is	
  compiled	
  to	
  intermediate	
  langage	
  (IL)	
  
   –  IL	
  runs	
  on	
  top	
  of	
  CLR	
  
   –  IL	
  code	
  is	
  always	
  naRvely	
  compiled	
  before	
  running	
  
OO	
  
•  No	
  global	
  methods,	
  just	
  like	
  in	
  Java	
  
•  Interface	
  is	
  pure	
  abstract	
  class	
  
•  No	
  mulRple	
  inheritance	
  
	
  
Main	
  
 using System;

 class A {

    public static void Main(String[] args){

        Console.WriteLine("Hello World");

    }
}
Compiling	
  Several	
  Files	
  in	
  C#	
  
C:CodeSample> csc /main:A /out:example.exe A.cs B.cs

C:CodeSample> example.exe
 Hello World from class A

C:CodeSample> csc /main:B /out:example.exe A.cs B.cs

C:CodeSample> example.exe
 Hello World from class B
Inheritance:	
  Base	
  Class	
  
using System;
abstract public class Figure {
    private int x;
    private int y;
    public Figure(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public void SetX(int x) {
        this.x = x;
    }
    public void SetY(int y) {
        this.y = y;
    }
    public int GetY() {
        return y;
    }
    public int GetX() {
        return x;
    }
    public abstract double CalculateSurfaceArea();
}
Inheritance:	
  Interface	
  
interface IMove {
    void MoveTo(int x, int y);
}
Inheritance	
  
public class Rectangle : Figure, IMove {
    private int width;
    private int height;

    public Rectangle(int x, int y, int width, int height) : base(x,y) {
        this.width = width;
        this.height = height;
    }

    public void MoveTo(int x, int y) {
        SetX( GetX() + x );
        SetY( GetY() + y );
    }

    public override double CalculateSurfaceArea() {
        return width * height;
    }

    public static void Main(String [] args) {
        Rectangle r = new Rectangle(4, 5, 10, 10);
        Console.Write( "Rectangle x: " );
        Console.Write( r.GetX() );
        r.MoveTo(5, 0);
        Console.Write( "nRectangle y: " );
        Console.Write( r.GetX() );
        Console.Write( "nRectangle Surface Area: " );
        Console.Write( r.CalculateSurfaceArea() );
        Console.Write( "n" );
    }
}
Run	
  Time	
  Type	
  IdenRficaRon	
  
public static void Main(String [] args) {
       Object rectangleObject = new Rectangle(4, 5, 10, 10);

       // Type cast from Object to Rectangle
       Rectangle temp1 = rectangleObject as Rectangle;

       // Check if cast was successfull
       if(temp1 != null) {
           Console.Write("Success: Object was casted to Rectangle!");
           temp1.SetX(0);
       }
   }
ProperRes	
  
public class Rectangle : Figure, IMove {
    private int height;
    private int width;

    public int Width {
        get {
            return width;
        }
        set {
            if(value > 0) {
                width = value;
            } else {
                Console.WriteLine("Value was not set.");
            }
        }
    }

    public Rectangle(int x, int y, int width, int height) : base(x,y) {
        this.width = width;
        this.height = height;
    }

    …

    public static void Main(String [] args) {
        Rectangle r = new Rectangle(5,5,10,10);
        r.Width = 10;
        Console.Write(r.Width);
        // Value was not set
        r.Width = -5;
    }
}
Alias	
  
using Terminal = System.Console;

class Test {
     public static void Main(string[] args){
       Terminal.WriteLine("Please don’t use this");
     }
}
Namespaces	
  
using System;

namespace fi.tamk.tiko.ohjelmistotuotanto {
    public class Test {
        public static void method() {
            Console.Write("ohjelmistotuotanton");
        }
    }
}

namespace fi.tamk.tiko.pelituotanto {
    public class Test {
        public static void method() {
            Console.Write("pelituotanton");
        }
    }
}

class App {
    public static void Main(String [] args) {
        fi.tamk.tiko.ohjelmistotuotanto.Test.method();
        fi.tamk.tiko.pelituotanto.Test.method();
    }
}
Constant	
  Variables	
  
•  const int VARIABLE = 10;
Variable	
  Length	
  Parameters	
  and	
  foreach	
  
using System;

public class Params {

    public static void Method(params int[] array) {
        foreach(int num in array) {
            Console.Write(num);
            Console.Write("n");
        }
    }

    public static void Main(String [] args) {
        Method(1,2,3,4,5);
        Method(1,2);

        int [] myArray = {1,2,3,4};
        Method(myArray);
    }
}
OperaRon	
  Overloading	
  
using System;

public class MyNumber {

    private int value;

    public MyNumber(int value) {
        this.value = value;
    }

    public static MyNumber operator+(MyNumber number1, MyNumber number2) {
        int sum = number1.value + number2.value;
        MyNumber temp = new MyNumber(sum);

        return temp;
    }

    public static void Main(String [] args) {
        MyNumber number1 = new MyNumber(5);
        MyNumber number2 = new MyNumber(5);

        MyNumber sum = number1 + number2;

        Console.Write(sum.value);
    }
}
ParRal	
  Types	
  
•  The	
  parRal	
  types	
  feature	
  enables	
  one	
  to	
  
   define	
  a	
  single	
  class	
  across	
  mul/ple	
  source	
  
   files!	
  
•  So	
  one	
  class	
  can	
  be	
  declared	
  in	
  several	
  files!	
  
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers

More Related Content

What's hot

What's hot (19)

Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleinerMetrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide showArduino C maXbox web of things slide show
Arduino C maXbox web of things slide show
 
Klee and angr
Klee and angrKlee and angr
Klee and angr
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekingeBioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
 
Meta Object Protocols
Meta Object ProtocolsMeta Object Protocols
Meta Object Protocols
 
Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on LinuxCNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: ShellcodeCNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: ShellcodeCNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Clojure 7-Languages
Clojure 7-LanguagesClojure 7-Languages
Clojure 7-Languages
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdbTriton and symbolic execution on gdb
Triton and symbolic execution on gdb
 
Java Generics
Java GenericsJava Generics
Java Generics
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on LinuxCNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 

Viewers also liked

Android Security, Signing and Publishing
Android Security, Signing and PublishingAndroid Security, Signing and Publishing
Android Security, Signing and Publishing
Jussi Pohjolainen
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX ParsingAndroid Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
Jussi Pohjolainen
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
Jussi Pohjolainen
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth Connection
Jussi Pohjolainen
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt
Jussi Pohjolainen
 
Android Telephony Manager and SMS
Android Telephony Manager and SMSAndroid Telephony Manager and SMS
Android Telephony Manager and SMS
Jussi Pohjolainen
 
Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android Fragments
Jussi Pohjolainen
 

Viewers also liked (20)

Android Security, Signing and Publishing
Android Security, Signing and PublishingAndroid Security, Signing and Publishing
Android Security, Signing and Publishing
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX ParsingAndroid Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
 
Android Essential Tools
Android Essential ToolsAndroid Essential Tools
Android Essential Tools
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
Qt Translations
Qt TranslationsQt Translations
Qt Translations
 
Building Web Services
Building Web ServicesBuilding Web Services
Building Web Services
 
Responsive Web Site Design
Responsive Web Site DesignResponsive Web Site Design
Responsive Web Site Design
 
Android 2D Drawing and Animation Framework
Android 2D Drawing and Animation FrameworkAndroid 2D Drawing and Animation Framework
Android 2D Drawing and Animation Framework
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth Connection
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt
 
Android UI Development
Android UI DevelopmentAndroid UI Development
Android UI Development
 
Android Location and Maps
Android Location and MapsAndroid Location and Maps
Android Location and Maps
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
Android Sensors
Android SensorsAndroid Sensors
Android Sensors
 
Android Multimedia Support
Android Multimedia SupportAndroid Multimedia Support
Android Multimedia Support
 
Android Telephony Manager and SMS
Android Telephony Manager and SMSAndroid Telephony Manager and SMS
Android Telephony Manager and SMS
 
Short Intro to Android Fragments
Short Intro to Android FragmentsShort Intro to Android Fragments
Short Intro to Android Fragments
 
Moved to Speakerdeck
Moved to SpeakerdeckMoved to Speakerdeck
Moved to Speakerdeck
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 

Similar to C# for Java Developers

Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
Dr-archana-dhawan-bajaj
 

Similar to C# for Java Developers (20)

Next .NET and C#
Next .NET and C#Next .NET and C#
Next .NET and C#
 
Dr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot netDr archana dhawan bajaj - c# dot net
Dr archana dhawan bajaj - c# dot net
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
Intro to .NET and Core C#
Intro to .NET and Core C#Intro to .NET and Core C#
Intro to .NET and Core C#
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 
srgoc
srgocsrgoc
srgoc
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
 
Basic info on java intro
Basic info on java introBasic info on java intro
Basic info on java intro
 
Basic info on java intro
Basic info on java introBasic info on java intro
Basic info on java intro
 
Java introduction
Java introductionJava introduction
Java introduction
 
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
L04 Software Design 2
L04 Software Design 2L04 Software Design 2
L04 Software Design 2
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 

More from Jussi Pohjolainen

Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Jussi Pohjolainen
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
Jussi Pohjolainen
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
Jussi Pohjolainen
 

More from Jussi Pohjolainen (20)

Java Web Services
Java Web ServicesJava Web Services
Java Web Services
 
Box2D and libGDX
Box2D and libGDXBox2D and libGDX
Box2D and libGDX
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and PreferenceslibGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame AnimationlibGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Advanced JavaScript Development
Advanced JavaScript DevelopmentAdvanced JavaScript Development
Advanced JavaScript Development
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
libGDX: Scene2D
libGDX: Scene2DlibGDX: Scene2D
libGDX: Scene2D
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: Simple Frame Animation
libGDX: Simple Frame AnimationlibGDX: Simple Frame Animation
libGDX: Simple Frame Animation
 
libGDX: User Input
libGDX: User InputlibGDX: User Input
libGDX: User Input
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDXImplementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and GesturesCreating Asha Games: Game Pausing, Orientation, Sensors and Gestures
Creating Asha Games: Game Pausing, Orientation, Sensors and Gestures
 
Creating Games for Asha - platform
Creating Games for Asha - platformCreating Games for Asha - platform
Creating Games for Asha - platform
 
Intro to Asha UI
Intro to Asha UIIntro to Asha UI
Intro to Asha UI
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

C# for Java Developers

  • 1. C#  for  Java  Developers   Jussi  Pohjolainen   Tampere  University  of  Applied  Sciences  
  • 2. Overview   •  Ecma  and  ISO  Standard   •  Developed  by  MicrosoD,  uses  in  .NET  and   WP7   •  Most  recent  version  is  C#  4.0  
  • 5. CLI   •  CLI  is  an  open  specificaRon  that  describes   executable  code  and  runRme  environment   •  CLI  is  core  of   –  MicrosoD  .NET  Framework   –  Mono  (Open  Source)   –  Portable.net  (Open  Source)    
  • 6. CTS,  CLS,  VES,  CIL   •  Common  Type  System  (CTS)   –  A  set  of  data  types  and  operaRons  that  are  share  by  all   CTS-­‐compliant  programming  languages,  such  as  C#  and  VB   •  Common  Language  SpecificaRon  (CLS)   –  Set  of  base  rules  to  which  any  language  targeRng  the  CLI   should  conform.     •  Virtual  ExecuRon  System  (VES)   –  VES  loads  and  executes  CLI-­‐compaRble  programs   •  Common  Intermediate  Language  (CIL)   –  Intermediate  language  that  is  abstracted  from  the   plaXorm  hardware  (In  Java:  class)  
  • 7. Mono:OSX  »  C#  File  
  • 10. .NET  on  Windows  7   Add  C:WindowsMicrosoft.NETFrameworkv3.5 to  path!  
  • 11. Common  Language  RunRme:  Mac   Dropbox  –   folder  
  • 12. Common  Language  RunRme:  Win   And  run   the  .exe  in   Windows!  
  • 13. Almost  the  Same  but  Not  Quite   C#  
  • 14. Keywords   •  Single  rooted  class  hierarchy:  all  objects   inheritate  System.Object   •  Almost  every  keyword  in  Java  can  be  found   from  C#   –  super -> base –  instanceof -> is –  import -> using –  extends / implements -> : •  Otherwise,  pre`y  much  the  same  
  • 15. Memory  Handling  and  RunRme   •  Memory  Handling   –  Most  objects  in  C#  to  heap  using  new   –  CLR  handles  garbage  collecRons   •  RunRme   –  C#  is  compiled  to  intermediate  langage  (IL)   –  IL  runs  on  top  of  CLR   –  IL  code  is  always  naRvely  compiled  before  running  
  • 16. OO   •  No  global  methods,  just  like  in  Java   •  Interface  is  pure  abstract  class   •  No  mulRple  inheritance    
  • 17. Main   using System; class A { public static void Main(String[] args){ Console.WriteLine("Hello World"); } }
  • 18. Compiling  Several  Files  in  C#   C:CodeSample> csc /main:A /out:example.exe A.cs B.cs C:CodeSample> example.exe Hello World from class A C:CodeSample> csc /main:B /out:example.exe A.cs B.cs C:CodeSample> example.exe Hello World from class B
  • 19. Inheritance:  Base  Class   using System; abstract public class Figure { private int x; private int y; public Figure(int x, int y) { this.x = x; this.y = y; } public void SetX(int x) { this.x = x; } public void SetY(int y) { this.y = y; } public int GetY() { return y; } public int GetX() { return x; } public abstract double CalculateSurfaceArea(); }
  • 20. Inheritance:  Interface   interface IMove { void MoveTo(int x, int y); }
  • 21. Inheritance   public class Rectangle : Figure, IMove { private int width; private int height; public Rectangle(int x, int y, int width, int height) : base(x,y) { this.width = width; this.height = height; } public void MoveTo(int x, int y) { SetX( GetX() + x ); SetY( GetY() + y ); } public override double CalculateSurfaceArea() { return width * height; } public static void Main(String [] args) { Rectangle r = new Rectangle(4, 5, 10, 10); Console.Write( "Rectangle x: " ); Console.Write( r.GetX() ); r.MoveTo(5, 0); Console.Write( "nRectangle y: " ); Console.Write( r.GetX() ); Console.Write( "nRectangle Surface Area: " ); Console.Write( r.CalculateSurfaceArea() ); Console.Write( "n" ); } }
  • 22.
  • 23. Run  Time  Type  IdenRficaRon   public static void Main(String [] args) { Object rectangleObject = new Rectangle(4, 5, 10, 10); // Type cast from Object to Rectangle Rectangle temp1 = rectangleObject as Rectangle; // Check if cast was successfull if(temp1 != null) { Console.Write("Success: Object was casted to Rectangle!"); temp1.SetX(0); } }
  • 24. ProperRes   public class Rectangle : Figure, IMove { private int height; private int width; public int Width { get { return width; } set { if(value > 0) { width = value; } else { Console.WriteLine("Value was not set."); } } } public Rectangle(int x, int y, int width, int height) : base(x,y) { this.width = width; this.height = height; } … public static void Main(String [] args) { Rectangle r = new Rectangle(5,5,10,10); r.Width = 10; Console.Write(r.Width); // Value was not set r.Width = -5; } }
  • 25. Alias   using Terminal = System.Console; class Test { public static void Main(string[] args){ Terminal.WriteLine("Please don’t use this"); } }
  • 26. Namespaces   using System; namespace fi.tamk.tiko.ohjelmistotuotanto { public class Test { public static void method() { Console.Write("ohjelmistotuotanton"); } } } namespace fi.tamk.tiko.pelituotanto { public class Test { public static void method() { Console.Write("pelituotanton"); } } } class App { public static void Main(String [] args) { fi.tamk.tiko.ohjelmistotuotanto.Test.method(); fi.tamk.tiko.pelituotanto.Test.method(); } }
  • 27. Constant  Variables   •  const int VARIABLE = 10;
  • 28. Variable  Length  Parameters  and  foreach   using System; public class Params { public static void Method(params int[] array) { foreach(int num in array) { Console.Write(num); Console.Write("n"); } } public static void Main(String [] args) { Method(1,2,3,4,5); Method(1,2); int [] myArray = {1,2,3,4}; Method(myArray); } }
  • 29. OperaRon  Overloading   using System; public class MyNumber { private int value; public MyNumber(int value) { this.value = value; } public static MyNumber operator+(MyNumber number1, MyNumber number2) { int sum = number1.value + number2.value; MyNumber temp = new MyNumber(sum); return temp; } public static void Main(String [] args) { MyNumber number1 = new MyNumber(5); MyNumber number2 = new MyNumber(5); MyNumber sum = number1 + number2; Console.Write(sum.value); } }
  • 30. ParRal  Types   •  The  parRal  types  feature  enables  one  to   define  a  single  class  across  mul/ple  source   files!   •  So  one  class  can  be  declared  in  several  files!