Your SlideShare is downloading. ×
0
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
C# for Java Developers
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

C# for Java Developers

860

Published on

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
860
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  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  
  3. Versions  
  4. Common  Language  Infrastructure  (CLI)  
  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  
  8. Mono:OSX  »  Building  
  9. Mono:OSX  »  Running  
  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.csC:CodeSample> example.exe Hello World from class AC:CodeSample> csc /main:B /out:example.exe A.cs B.csC: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. 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); } }
  23. 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; }}
  24. Alias  using Terminal = System.Console;class Test { public static void Main(string[] args){ Terminal.WriteLine("Please don’t use this"); }}
  25. 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(); }}
  26. Constant  Variables  •  const int VARIABLE = 10;
  27. 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); }}
  28. 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); }}
  29. 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!  

×