Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java vs C# Johan Lindfors Microsoft AB. What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications.

Similar presentations


Presentation on theme: "Java vs C# Johan Lindfors Microsoft AB. What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications."— Presentation transcript:

1 Java vs C# Johan Lindfors Microsoft AB

2 What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications  GUI applications, event handling  Distributed applications, remoting  Java on.NET  Visual J#.NET  Java Language Conversion Assistant

3 What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications  GUI applications, event handling  Distributed applications, remoting  Java on.NET  Visual J#.NET  Java Language Conversion Assistant

4 Code architecture Java source code C# source code Java byte code CIL.class file.module file.jar file.dll file Compiles toLives inGrouped into

5 Similarities  Hello world in 4 languages… import java.lang.System; public class HelloWorld { public static void main(String[] args) { System.out.println("Zdravo, zemjata!"); } using System; public class HelloWorld { public static void Main(string[] args) { Console.WriteLine("Salut, monde!"); } Java C#

6 Keyword similarities  Complex type keywords  class / interface  new  Conditional and flow keywords  if / then / else  switch / case / default  for / while / do while  break / continue  return  Exception handling keywords  try / catch / finally / throw

7 Keyword differences  Package and namespace keywords  import in Java=using in C#  package = namespace  Complex keywords  extends=: (colon)  implements= :  instanceof= is  super=base  final=sealed / readonly  native=extern  synchronized=lock

8 Example of issues  Enums  No value types in Java  In C# we support both value and reference types  The compiler handles the strain  Iterations  Iterations are very similar in Java and in C#, but…  ”foreach” is a very powerful ally  Resources  Resource management is also similar, but…  ”using” is your true friend

9 Other topics  Unmanaged code through ”unsafe”  Attributes  Use keywords as identifiers  @ prefix can be used to differentiate keywords from identifiers using System; public class @class { public string @public(string @string) { string @return = @string + @string; return @return; } public static void Main() { Console.WriteLine(new @class().@public(“Simple test!”)); }

10 What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications  GUI applications, event handling  Distributed applications, remoting  Java on.NET  Visual J#.NET  Java Language Conversion Assistant

11 Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class App Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class.DLL 0101.DLL 0110 Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...) End Sub... Sub unlock() MessageBox.Show(...) End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...) End Sub... Sub unlock() MessageBox.Show(...) End Sub End Class Application Deployment on Windows

12 App Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class.DLL 0101.DLL 0110 Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...) End Sub... Sub unlock() MessageBox.Show(...) End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...) End Sub... Sub unlock() MessageBox.Show(...) End Sub End Class Application backout on Windows

13 App.jar JBC.jar JBC Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Application Deployment with Java

14 App.jar JBC.jar JBC Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Application backout with Java

15 App Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class.module CIL 1.0.0.0.module CIL 1.0.0.1....NET Upgrade

16 Imports System.Windows.Forms Public Class Door...... Sub lock() Sub lock() MessageBox.Show(...); MessageBox.Show(...); End Sub End Sub...... Sub unlock() Sub unlock() MessageBox.Show(...); MessageBox.Show(...); End Sub End Sub End Class App Imports System.Windows.Forms Public Class Door...... Sub lock() Sub lock() MessageBox.Show(...); MessageBox.Show(...); End Sub End Sub...... Sub unlock() Sub unlock() MessageBox.Show(...); MessageBox.Show(...); End Sub End Sub End Class.module CIL Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class Imports System.Windows.Forms Public Class Door... Sub lock() MessageBox.Show(...); End Sub... Sub unlock() MessageBox.Show(...); End Sub End Class.module CIL 1.0.0.0 1.0.0.1.NET Upgrade backout...

17 App 1.0.0.0... App... 1.0.0.1 1.1.0.0 1.1.0.1 2.0.0.0 2.1.0.0 GAC Global Assembly Cache

18 public interface java.awt.event.MouseListener { public void mouseClicked (MouseEvent e); public void mousePressed (MouseEvent e); public void mouseReleased (MouseEvent e); public void mouseEntered (MouseEvent e); public void mouseExited (MouseEvent e); }  Java events are represented by method names grouped into listener interfaces Java Events

19 class JButton {... public void addMouseListener(MouseListener added); public void removeMouseListener(MouseListener removed);... } Java Event Sources  Java event sources call event methods on registered listeners

20 class MouseAdapter implements MouseListener { public void mouseClicked (MouseEvent e) {} public void mousePressed (MouseEvent e) {} public void mouseReleased (MouseEvent e) {} public void mouseEntered (MouseEvent e) {} public void mouseExited (MouseEvent e) {} } Java Adapters  Adapter classes allow you to ignore events you're not interested in

21 class Example {... class OnMousePressedHandler extends MouseAdapter { public void mousePressed(MouseEvent e) {... }... } Java Event Handlers  Declare a handler class that extends the adapter and override the event methods of interest

22 class Example {... public void init() {... ok.addMouseListener(new OnMousePressedHandler()); } private class OnMousePressedHandler... {... } private JButton ok; }  Create an instance of the handler class and add it to the event source Java Event Example

23 class Button {... public event EventHandler Click; public event MouseEventHandler MouseDown; public event MouseEventHandler MouseUp; public event EventHandler Enter; public event EventHandler Leave;... }  Event source names their events directly  Every event has a type.NET Events

24 delegate void EventHandler( object sender, EventArgs sent ); delegate void MouseEventHandler( object sender, MouseEventArgs sent );.NET Event Types  An event type is a method signature  The delegate keyword declares a type

25 class Example { void OnMouseDown( object sender, MouseEventArgs sent) {... } delegate void MouseEventHandler( object sender, MouseEventArgs sent );  Declare an event handling method matching the event delegate signature.NET Event Handlers

26 class Example { public Example() {... ok.MouseDown += new MouseEventHandler(OnMouseDown); } private void OnMouseDown(object sender, MouseEventArgs sent){... } private Button ok; }.NET Event Example  Create an event delegate instance using the name of the handler method and add it to the event source

27  Make calls between JVMs  Remote object implements a defined remote interface type used by the client  Pass primitive types and objects  Pass-by-value using Java serialization  Pass-by-reference for remote object references  Different transports available  Proprietary, TCP-based protocol (JRMP)  CORBA-compliant IIOP under J2EE  Firewall tunnelling options Distributed Applications RMI/IIOP

28  Remote objects registered in registry or JNDI  Client looks up remote object and uses it  Download stub class if required  Two lifecycle options  Server instantiates remote objects and registers them (server is no longer required)  Objects are activated when methods are invoked  RMI also used to communicate with EJBs RMI Lifecycle

29  Make calls between application domains  Remoting server links clients to objects  Creates a channel for a given port/protocol  Use TCP or HTTP transports  Pass objects by reference or by value  Remote objects must extend MarshalByRefObject  Objects by value must be Serializable  Need to handle network-related exceptions.NET Remoting

30  Use application config file to change settings File-based configuration

31 Remoting Server Request Create Use Dispose Remote Object Remoting Client Client activation

32 Remoting Server Request Create Use Dispose Remote Object Remoting Client Server activation – Single Call

33 Remoting Server Request Create Use Dispose Remote Object Remoting Client Server activation – Singleton Remoting Client Request Use

34 Advanced.NET Remoting  Client-activated object lifetime  Specified lifetime based on a lease  Server-activated object lifetime  Single call lasts for method duration  Singleton has a specified lifetime based on a lease  Asynchronous calls  Create delegates in the usual way  Pass them to use as callbacks  Wrap remote delegate in AsyncDelegate  Register to be notified of method completion

35 What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications  GUI applications, event handling  Distributed applications, remoting  Java on.NET  Visual J#.NET  Java Language Conversion Assistant

36 Visual J#.NET  The Java language in Visual Studio.NET  Easy transition for Java developer into.NET  Primarily developed to migrate Visual J++ application to.NET  Enables full use of… .NET Framework  XML Web Services in ASP.NET  ADO.NET  Windows Forms  Full cross language integration

37 What is the JLCA?  Java Language Conversion Assistant  Visual Studio.NET addon  Java language and classes converted to C# and.NET classes  Migrated application will only run on.NET Framework  Numbers right now…  99% of language converted  87% of classes  JBIMP.EXE converts Java bytecode into MSIL

38 What have we covered?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications  GUI applications, event handling  Distributed applications, remoting  Java on.NET  Visual J#.NET  Java Language Conversion Assistant

39 What have we missed?  A bunch of things…  EJB and Serviced Components  Threading and synchronization  Networking  XML processing  Security and Cryptography  Reflection  Database connectivity  Graphics  …

40 More information  Microsoft and other  http://msdn.microsoft.com  http://www.gotdotnet.com  http://www.theserverside.com  MS Press  C# for Java developers  ISBN: 0-7356-1779-1 .NET Remoting  ISBN: 0-7356-1778-3

41

42 Definitions  GUIGraphical User Interface  CILCommon Intermediate Language  DLLDynamic Link Library  GACGlobal Assembly Cache  JLCAJava Language Conversion Assistant  JARJava ARchive  JBCJava Byte Code  JRMPJava Remote Method Protocol  JNDIJava Naming and Directory Interface  ISBNInternational Standard Book Number


Download ppt "Java vs C# Johan Lindfors Microsoft AB. What are we to cover?  Java vs C#  Similarities and differencies  Specific issues  Deployment of applications."

Similar presentations


Ads by Google