SlideShare a Scribd company logo
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" );
    }
}
C# for Java Developers
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
Ad

Recommended

A closure ekon16
A closure ekon16
Max Kleiner
 
C# - What's next
C# - What's next
Christian Nagel
 
Clojure intro
Clojure intro
Basav Nagur
 
Ponies and Unicorns With Scala
Ponies and Unicorns With Scala
Tomer Gabel
 
S1 DML Syntax and Invocation
S1 DML Syntax and Invocation
Arvind Surve
 
More on Lex
More on Lex
Tech_MX
 
Use of an Oscilloscope - maXbox Starter33
Use of an Oscilloscope - maXbox Starter33
Max Kleiner
 
CNIT 127 Ch 4: Introduction to format string bugs
CNIT 127 Ch 4: Introduction to format string bugs
Sam Bowne
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide show
Max Kleiner
 
Klee and angr
Klee and angr
Wei-Bo Chen
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
Prof. Wim Van Criekinge
 
Meta Object Protocols
Meta Object Protocols
Pierre de Lacaze
 
Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7
Yuji Otani
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
Sam Bowne
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
Sam Bowne
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
Sam Bowne
 
TechTalk - Dotnet
TechTalk - Dotnet
heinrich.wendel
 
Ruby Programming Assignment Help
Ruby Programming Assignment Help
HelpWithAssignment.com
 
Clojure 7-Languages
Clojure 7-Languages
Pierre de Lacaze
 
Chapter 2
Chapter 2
application developer
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdb
Wei-Bo Chen
 
Java Generics
Java Generics
Carol McDonald
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Max Kleiner
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
Sam Bowne
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
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# 8
Christian Nagel
 
Android Security, Signing and Publishing
Android Security, Signing and Publishing
Jussi Pohjolainen
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
Jussi Pohjolainen
 
Android Essential Tools
Android Essential Tools
Jussi Pohjolainen
 

More Related Content

What's hot (19)

Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide show
Max Kleiner
 
Klee and angr
Klee and angr
Wei-Bo Chen
 
Bioinformatics v2014 wim_vancriekinge
Bioinformatics v2014 wim_vancriekinge
Prof. Wim Van Criekinge
 
Meta Object Protocols
Meta Object Protocols
Pierre de Lacaze
 
Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7
Yuji Otani
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
Sam Bowne
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
Sam Bowne
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
Sam Bowne
 
TechTalk - Dotnet
TechTalk - Dotnet
heinrich.wendel
 
Ruby Programming Assignment Help
Ruby Programming Assignment Help
HelpWithAssignment.com
 
Clojure 7-Languages
Clojure 7-Languages
Pierre de Lacaze
 
Chapter 2
Chapter 2
application developer
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdb
Wei-Bo Chen
 
Java Generics
Java Generics
Carol McDonald
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Max Kleiner
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
Sam Bowne
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
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# 8
Christian Nagel
 
Metrics ekon 14_2_kleiner
Metrics ekon 14_2_kleiner
Max Kleiner
 
Arduino C maXbox web of things slide show
Arduino C maXbox web of things slide show
Max Kleiner
 
Why choose Hack/HHVM over PHP7
Why choose Hack/HHVM over PHP7
Yuji Otani
 
CNIT 127 Ch 2: Stack overflows on Linux
CNIT 127 Ch 2: Stack overflows on Linux
Sam Bowne
 
CNIT 127 Ch 3: Shellcode
CNIT 127 Ch 3: Shellcode
Sam Bowne
 
CNIT 127: Ch 3: Shellcode
CNIT 127: Ch 3: Shellcode
Sam Bowne
 
Triton and symbolic execution on gdb
Triton and symbolic execution on gdb
Wei-Bo Chen
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Max Kleiner
 
CNIT 127: Ch 2: Stack overflows on Linux
CNIT 127: Ch 2: Stack overflows on Linux
Sam Bowne
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
ASIT Education
 
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# 8
Christian Nagel
 

Viewers also liked (20)

Android Security, Signing and Publishing
Android Security, Signing and Publishing
Jussi Pohjolainen
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
Jussi Pohjolainen
 
Android Essential Tools
Android Essential Tools
Jussi Pohjolainen
 
Quick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
Qt Translations
Qt Translations
Jussi Pohjolainen
 
Building Web Services
Building Web Services
Jussi Pohjolainen
 
Responsive Web Site Design
Responsive Web Site Design
Jussi Pohjolainen
 
Android 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 Connection
Jussi Pohjolainen
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt
Jussi Pohjolainen
 
Android UI Development
Android UI Development
Jussi Pohjolainen
 
Android Location and Maps
Android Location and Maps
Jussi Pohjolainen
 
Android Threading
Android Threading
Jussi Pohjolainen
 
Android Data Persistence
Android Data Persistence
Jussi Pohjolainen
 
Android Sensors
Android Sensors
Jussi Pohjolainen
 
Android Multimedia Support
Android Multimedia Support
Jussi Pohjolainen
 
Android Telephony Manager and SMS
Android Telephony Manager and SMS
Jussi Pohjolainen
 
Short Intro to Android Fragments
Short Intro to Android Fragments
Jussi Pohjolainen
 
Moved to Speakerdeck
Moved to Speakerdeck
Jussi Pohjolainen
 
Android Basic Components
Android Basic Components
Jussi Pohjolainen
 
Android Security, Signing and Publishing
Android Security, Signing and Publishing
Jussi Pohjolainen
 
Android Http Connection and SAX Parsing
Android Http Connection and SAX Parsing
Jussi Pohjolainen
 
Quick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 
Android 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 Connection
Jussi Pohjolainen
 
00 introduction-mobile-programming-course.ppt
00 introduction-mobile-programming-course.ppt
Jussi Pohjolainen
 
Android Telephony Manager and SMS
Android Telephony Manager and SMS
Jussi Pohjolainen
 
Short Intro to Android Fragments
Short Intro to Android Fragments
Jussi Pohjolainen
 
Ad

Similar to C# for Java Developers (20)

Intro to .NET and Core C#
Intro to .NET and Core C#
Jussi Pohjolainen
 
1204csharp
1204csharp
g_hemanth17
 
Introduction to csharp
Introduction to csharp
Satish Verma
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
Sachin Singh
 
Introduction to csharp
Introduction to csharp
Raga Vahini
 
Introduction to csharp
Introduction to csharp
singhadarsh
 
Introduction to CSharp
Introduction to CSharp
Mody Farouk
 
Introduction To Csharp
Introduction To Csharp
g_hemanth17
 
DotNet Introduction
DotNet Introduction
Wei Sun
 
Csharp
Csharp
Swaraj Kumar
 
CSharp presentation and software developement
CSharp presentation and software developement
frwebhelp
 
C# for beginners
C# for beginners
application developer
 
Introduction to csharp
Introduction to csharp
hmanjarawala
 
Introduction to csharp
Introduction to csharp
voegtu
 
Introduction to csharp
Introduction to csharp
voegtu
 
C#
C#
Joni
 
Introduction to c#
Introduction to c#
singhadarsh
 
Introduction To Csharp
Introduction To Csharp
sarfarazali
 
C Language fundamentals hhhhhhhhhhhh.ppt
C Language fundamentals hhhhhhhhhhhh.ppt
lalita57189
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
yazad dumasia
 
Introduction to csharp
Introduction to csharp
Satish Verma
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
Sachin Singh
 
Introduction to csharp
Introduction to csharp
Raga Vahini
 
Introduction to csharp
Introduction to csharp
singhadarsh
 
Introduction to CSharp
Introduction to CSharp
Mody Farouk
 
Introduction To Csharp
Introduction To Csharp
g_hemanth17
 
DotNet Introduction
DotNet Introduction
Wei Sun
 
CSharp presentation and software developement
CSharp presentation and software developement
frwebhelp
 
Introduction to csharp
Introduction to csharp
hmanjarawala
 
Introduction to csharp
Introduction to csharp
voegtu
 
Introduction to csharp
Introduction to csharp
voegtu
 
Introduction to c#
Introduction to c#
singhadarsh
 
Introduction To Csharp
Introduction To Csharp
sarfarazali
 
C Language fundamentals hhhhhhhhhhhh.ppt
C Language fundamentals hhhhhhhhhhhh.ppt
lalita57189
 
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
C# .NET: Language Features and Creating .NET Projects, Namespaces Classes and...
yazad dumasia
 
Ad

More from Jussi Pohjolainen (20)

Java Web Services
Java Web Services
Jussi Pohjolainen
 
Box2D and libGDX
Box2D and libGDX
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
libGDX: Tiled Maps
libGDX: Tiled Maps
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
Introduction to JavaScript
Introduction to JavaScript
Jussi Pohjolainen
 
Introduction to AngularJS
Introduction to AngularJS
Jussi Pohjolainen
 
libGDX: Scene2D
libGDX: Scene2D
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: User Input
libGDX: User Input
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Creating 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 - platform
Jussi Pohjolainen
 
Intro to Asha UI
Intro to Asha UI
Jussi Pohjolainen
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
Jussi Pohjolainen
 
Intro to PhoneGap
Intro to PhoneGap
Jussi Pohjolainen
 
libGDX: Screens, Fonts and Preferences
libGDX: Screens, Fonts and Preferences
Jussi Pohjolainen
 
libGDX: User Input and Frame by Frame Animation
libGDX: User Input and Frame by Frame Animation
Jussi Pohjolainen
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
Jussi Pohjolainen
 
Advanced JavaScript Development
Advanced JavaScript Development
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
libGDX: Simple Frame Animation
libGDX: Simple Frame Animation
Jussi Pohjolainen
 
Implementing a Simple Game using libGDX
Implementing a Simple Game using libGDX
Jussi Pohjolainen
 
Building Android games using LibGDX
Building Android games using LibGDX
Jussi Pohjolainen
 
Creating 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 - platform
Jussi Pohjolainen
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
Jussi Pohjolainen
 

Recently uploaded (20)

GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 

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" ); } }
  • 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!