1 / 98

Comparing J2EE with .NET - ACCU 2002 -

Comparing J2EE with .NET - ACCU 2002 -. Markus Voelter, CTO, MATHEMA AG voelter@acm.org http://www.voelter.de. Slides (mostly ) by Michael Stal, Senior Principal Engineer SIEMENS AG, Dept. CT SE 2 E-Mail: mailto:Michael.Stal@mchp.siemens.de Web: http://www.stal.de. Goal.

jana
Télécharger la présentation

Comparing J2EE with .NET - ACCU 2002 -

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Comparing J2EE with .NET - ACCU 2002 - Markus Voelter, CTO, MATHEMA AG voelter@acm.org http://www.voelter.de Slides (mostly ) by Michael Stal, Senior Principal Engineer SIEMENS AG, Dept. CT SE 2 E-Mail: mailto:Michael.Stal@mchp.siemens.de Web: http://www.stal.de

  2. Goal • This is intended to be an objective comparisons of the two platforms • It will contain criteria to base a decision which platform to use • Interoperability issues Markus Voelter/Michael Stal – Comparing J2EE with .NET

  3. Agenda • Motivation • Comparison • Visions: Sun ONE and .NET • Layer-by-Layer comparison of the infrastructures • Summary • Literature Markus Voelter/Michael Stal – Comparing J2EE with .NET

  4. Web Frameworks Core elements of Web Frameworks Web Service User/Provider Mainframe Integration Layer Micro/Macro Services Frontend Layer (Web Server) Backend Server Virtual Machine Legacy Workflow Engine Core Services (Calendar, Preferences, Transactions, ...) Service Context (Who, Where, When, Why, ....) Service Description (WSDL) Service Description, Discovery, Integration (UDDI) Web-based and -related Protocols (HTTP, SMTP, ...) Clients Markus Voelter/Michael Stal – Comparing J2EE with .NET

  5. .NET – The Microsoft Way of Life .NET Foundation Services (Hailstorm) Passport, Calendar, Directory & Search, Notification & Messaging, Personalization, Web-Store/XML, Dynamic Delivery of Software and Services .NET Framework & Tools Windows Forms (Controls, Drawing, Windows Application Services) ASP.NET (Web Services, Web Forms, ASP.NET Application Services) Base Classes (ADO.NET, XML, Threading, IO, ....) Common Language Runtime (Memory Management, Common Type System, Lifecycle Monitor) .NET Servers SQL Server, Biztalk, Commerce, Exchange, Mobile Information, Host Integration, Application Center .NET Devices TabletPC, PocketPC, .... Markus Voelter/Michael Stal – Comparing J2EE with .NET

  6. Sun ONE (Open Net Environment) Service Creation and Assembly (JB, JSP, EJB) Web Services Smart Process (ebXML, XAML) Smart Policy (LDAP, Kerberos, PKI, OASIS Security)) Service Interface Process Management Service Integration (SQL, JDBC, XML, XSLT, XP, JMS, RMI, J2EE Connectors, ...) Service Container (J2EE, EJB, JSP, J2SE, J2ME, MIDP, Java Card) Smart Delivery (XML, HTML, XHTML, WML, VoiceXML, XSLT, HTTP, SSL, XP, SOAP, WSDL, UDDI, ebXML, ...) Smart Management (SNMP, CIM, WBEM, JMX) Service Platform Markus Voelter/Michael Stal – Comparing J2EE with .NET

  7. Layer-By-Layer Comparison Markus Voelter/Michael Stal – Comparing J2EE with .NET

  8. Hello World Example • In C# and Java: using System; namespace MyNameSpace { public class MyClass { public static void Main(String [] args) { Console.WriteLine(„Hello, C#!“); } } } package MyPackage; public class MyClass { public static void main(String [] args) { System.out.println(„Hello, Java!“); } } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  9. Layers • Runtime System • Object model • Base classes • Reflection, • Enterprise • Component model • Database access • XML • Server Pages • Remoting • Web Services • More Enterprise APIs Markus Voelter/Michael Stal – Comparing J2EE with .NET

  10. The Runtime System Markus Voelter/Michael Stal – Comparing J2EE with .NET

  11. .NET Runtime • It is called the Common Language Runtime (CLR) • It is intended for any language compiled to the MSIL • Provides integration for several languages • Provides support for non-OO languages (e.g. tail recursion) C# Compiler VB.NET MSIL + Metadata Loader/ Verifier JIT C++ Garbage Collection, Security, Multithreading, ... Managed Code Execution Perl Markus Voelter/Michael Stal – Comparing J2EE with .NET

  12. Java Virtual Machine • The JVM is intended for Java and interprets Java Byte Code. • Other languages can be compiled to Java bytecode, however (e.g. Ada) • Just-in-Time compilers exist for different environments and OSs Compiler CLASS- Files Classloader/ Verifier JIT Java Interpreter Garbage Collection, Security Manager Call-in+Call-out, Multithreading, ... Hotspot Native Code Markus Voelter/Michael Stal – Comparing J2EE with .NET

  13. Commonalities and Differences • Commonalities: • Basic concepts are similar • Differences: • Java is intended for interpretation (e.g. type-dependent primitives i_add, ...) • Java allows for custom class loaders and security managers • .NET CLR provides a command set that also supports functional languages Markus Voelter/Michael Stal – Comparing J2EE with .NET

  14. The Object Model Markus Voelter/Michael Stal – Comparing J2EE with .NET

  15. Object Model (.NET) • In .NET, everything is an object Types Value Types Reference Types Pointers Interfaces System Value Types User Value Types Self-describing Types Enumerations Classes Arrays Delegates Boxed Values User-Defined Markus Voelter/Michael Stal – Comparing J2EE with .NET

  16. System.Object • The „mother of all .NET classes“ public class Object { public virtual int GetHashCode(); public virtual bool Equals(); public virtual String ToString(); public static bool Equals(object a, object b); public static bool ReferenceEquals(object a, object b); public Type GetType(); protected object MemberWiseClone(); protected virtual Finalize()´; } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  17. Object Model (.NET) • .NET distinguishes between values types and reference types: • value types reside on the stack • reference types reside on the heap • In C#, there is no difference between primitive types and classes • Automatic boxing/unboxing provides transparency • Special strongly-typed function references • called delegates • and events) Markus Voelter/Michael Stal – Comparing J2EE with .NET

  18. Object Model (Java) • Java has primitive types and classes. • No automatic boxing/unboxing Types Primitive Types Reference Types Arrays Interfaces Classes Markus Voelter/Michael Stal – Comparing J2EE with .NET

  19. java.lang.Object • The „Mother of all Java classes“ public class Object { public Object(); public boolean equals(Object obj); public final Class getClass(); public int hashCode(); public final void notify(); public final void notifyAll(); public String toString(); public final void wait() throws InterruptedException; public final void wait(long timeout) throws InterruptedException; public final void wait(long timeout, int nanos) throws InterruptedException; protected Object clone() throws CloneNotSupportedException; protected void finalize() throws Throwable; } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  20. Object Model (Java) • Primitive types cannot be transparently used as an object. Special Holder classes are necessary. • There are no special function references. Java uses Observer Pattern with callback interfaces and inner classes Integer i_ref = new Integer(7); List l = ... l.add( i_ref ); Markus Voelter/Michael Stal – Comparing J2EE with .NET

  21. .NET-Types that are not available in Java • Delegates & Events: class MyClass { ... public void somebodyTurnedOnTheLight( int which ) { ... } } class AnotherClass { ... public delegate void LightTurnedOn(int which); public event LightTurnedOn OnLightTurnedOn; ... OnLightTurnedOn+= new LightTurnedOn(MyClass.somebodyTurnedOnTheLight); } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  22. .NET-Types that are not available in Java cont‘d • Enumerations (value type): • Jagged and unjagged Arrays: • Structs (value types): • Structs are implicitly sealed • they do not support inheritance enum Color : byte { RED = 1, BLUE = 2, GREEN = 3 }; int [2][] a; a[0] = new int[]{1}; a[1] = new int[]{1,2}; int [,] a = new int[2,2]; public struct Name { public String First; public String Last; } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  23. Commonalities and Differences • Commonalities: • Interfaces are „completely abstract classes“ • Support single inheritance for classes (implementation inheritance) and multiple interface inheritance • Default-Initialization of Variables • Namespace-Concept (Java-Package and .NET-Namespace) • Similar visibility attributes (public, private, ...) • Future: Generic types in .NET and Java (Generics) • Class Constructors (static initializer in Java) • Differences • In .NET there is no difference between primitive types and classes. • Multiple languages support in .NET • In Java all methods are implicitly virtual. In .NET this has to be made explicit virtual, override, new). • Java maps packages to directories. .NET doesn‘t. Markus Voelter/Michael Stal – Comparing J2EE with .NET

  24. Metainformation • Java and .NET provide a reflection API • to load and instantiate classes • and inspect classes (introspection). • In addition, .NET allows to annotate many aspects of a system (classes, members, operations) with so-called Attributes Markus Voelter/Michael Stal – Comparing J2EE with .NET

  25. .NET Examples • Using an Atttribute • There are several predefined attributes (WebService, WebMethod, ...) • Defining an Attribute [AuthorIs(„Michael“)] class MyClass { ... } [AttributeUsage(AttributeTargets.All)] public class AuthorIsAttribute : Attribute { private string m_Name; public AuthorIsAttribute(string name) { m_Name = name;} } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  26. .NET Examples cont‘d • Accessing and using Type information using System; using System.Reflection; namespace ComponentClient { class Client { static void Main(string[] args) { Assembly a = Assembly.LoadFrom("Component.dll"); Type [] allTypes = a.GetTypes(); Type t = allTypes[0]; object o = Activator.CreateInstance(t); MethodInfo mi = t.GetMethod("algorithm"); double d = (double) mi.Invoke(o, new object[]{21.0}); } } } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  27. Java Example • Accessing and using Type information: • Note that packages are not the same as assemblies!! import java.lang.reflect.*; try { Class c = Class.forName(„MyPrintComponent“); Object o = c.newInstance(); Method m = c.getMethod(„print“, new Class[]{ String.class }); m.invoke(o, new Object[]{„Hallo, Java!“}); } catch (Exception e) { // handle it here } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  28. Commonalities and Differences • Commonalities: • Very similar APIs • Differences: • .NET allows additional, user-defined meta information with attributes • Java Reflection is sometimes a bit more clumsy (because of primitive types and classes) • .NET allows to actually create new artifacts at runtime and instantiate them or store them in assemblies. Markus Voelter/Michael Stal – Comparing J2EE with .NET

  29. Statements • Both platforms support basically the same statements • Differences: • switch-Statement allows Strings, but no fallthrough: string name = address.name; switch (name) { case “Maier”: Console.WriteLine(“Nice to meet you, Hans!”); break; case “Mueller”, case “Huber”: Console.WriteLine(“You owe me some money!”); break; default: Console.WriteLine(“I don’t know you”); break; } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  30. Statements (cont‘d) • Differences: • Iterators in .NET: • Note that these are still no „internal iterators“ as in Smalltalk, for example! foreach (Elem i in MyContainer) { Console.WriteLine(i); } ... class MyContainer : IEnumerable, IEnumerator { public IEnumerator GetEnumerator() { return (IEnumerator)this; } publicvoid Reset() { ... } public bool MoveNext() { ... } public object Current { get { ... } } } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  31. Statements (cont‘d) • Differences: • Iterators in Java: for (Iterator i = MyContainer.iterator(); i.hasNext();) doSomething(i.next()); ... class MyContainer implements Iterator { public boolean hasNext() {…} public Object next() {...} public void remove() {...} public Iterator iterator() { return this; } } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  32. Statements (cont‘d) • Differences: • Properties in .NET, where Java uses Coding conventions Class MyClass { ... public double x { set { if (x < 0) throw new ArgumentException (“< 0”); m_x = value; } get { return m_x; } } ... // User: MyClass m = new MyClass(); m.x = 22; Markus Voelter/Michael Stal – Comparing J2EE with .NET

  33. Statements (cont‘d) • Differences: • .NET supports Indexers, Java does not. • Indexers also work with non-integer keys, such as strings object[17] = 22; // In class: Int [] m_a; public double this[int pos] { get { return m_a[pos]; } set { m_a[pos] = value; } } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  34. Statements (cont‘d) • Differences: • .NET supports operator overloading! public static Point operator+(Point op1, Point op2) { return new Point(op1.x+op2.x,op1.y+op2.y); } ... Point p = new Point(1,2) + new Point(2,3); Markus Voelter/Michael Stal – Comparing J2EE with .NET

  35. Statements (cont‘d) • Differences: • .NET allows pass-by-reference of method arguments class Test { public void Print(int i) { Console.WriteLine(i); } public void Inc(ref int i) { i++; } public int SetInitial(out int i) { i = 42; } ... } Test t = ...; int i; t.SetInitial(out i); t.Inc(ref i); t.Print(); Markus Voelter/Michael Stal – Comparing J2EE with .NET

  36. Statements (cont‘d) • Exceptions in Java • Exceptions have to be declared in the throws-clause • Exceptions in .NET • Exceptions are not declared public int insert(int i) throws OverLimitException; { … } // only way to tell you about // OverLimitException thrown below public int insert(int i) { … } Markus Voelter/Michael Stal – Comparing J2EE with .NET

  37. Important Base Classes No big conceptual differences here. Markus Voelter/Michael Stal – Comparing J2EE with .NET

  38. Multithreading Markus Voelter/Michael Stal – Comparing J2EE with .NET

  39. Multithreading in .NET • .NET uses delegates for multithreading • The „ThreadStart“ in the example below • There are monitors for synchronization • The “lock” in the example below class GlobalData { int m_Value; public int Value { set { lock(this) { m_Value = value; } } } } class Worker { GlobalData m_Global; public Worker(GlobalData global) {m_Global = global; } public void loop() { m_global.Value = 42; Thread.Sleep(100); } } // somewhere else: GlobalData g = new GlobalData(); Thread t = new Thread(new ThreadStart(new Worker().loop)); t.Start(); t.Join(); 1 Markus Voelter/Michael Stal – Comparing J2EE with .NET

  40. Multithreading in Java • In Java there is also a class „Thread“ • For synchronization there is the synchronized keyword class GlobalData { int m_Value; public synchronized int setValue { return m_Value; } } class Worker implements Runnable { GlobalData m_Global; public Worker(GlobalData global) { m_Global = global; } public void run() { m_Global.setValue(42); Thread.sleep(100); } } // somewhere else: GlobalData g = new GlobalData(); Thread t = new Thread(new Worker()); t.start(); t.join(); 1 Markus Voelter/Michael Stal – Comparing J2EE with .NET

  41. Commonalities and Differences • Commonalities: • Threading is very similar! • Both use some forms of monitor for synchronization • Differences: • In Java, synchronization is better integrated into the Java language • Java provides better synchronization and thread communication (wait, notify, ...). Markus Voelter/Michael Stal – Comparing J2EE with .NET

  42. Deployment Markus Voelter/Michael Stal – Comparing J2EE with .NET

  43. Assemblies in .NET • Assembly=Set of Types Manifest name Sharedname Files Types version Hash Referenced Assemblies Security Custom Attributes Product Information Module 1 Type 1 IL-Code Metadata Type 2 IL-Code Type 3 IL-Code Resources Markus Voelter/Michael Stal – Comparing J2EE with .NET

  44. Assemblies in .NET • Private Assemblies are typically only useful by the owning application • Shared Assemblies are stored in a common cache and can be used by several applications. • They are signed by a key • They are versioned!! • Runtime uses Application Domains as an abstraction for (potentially remote) processes. Markus Voelter/Michael Stal – Comparing J2EE with .NET

  45. Java JAR files • .jar files are similar to .NET‘s assemblies • They can be shared or private • They can be signed • They contain • types • resources • optionally, metadata in manifest files. • There is no versioning! Markus Voelter/Michael Stal – Comparing J2EE with .NET

  46. Commonalities and Differences • Commonalities: • Assemblies and JAR files provide „deployment“ components • Differences: • Much better versioning support in .NET (side-by-side execution) Markus Voelter/Michael Stal – Comparing J2EE with .NET

  47. Component Models Markus Voelter/Michael Stal – Comparing J2EE with .NET

  48. Server-Side Components in .NET • Now Component is used like in EJB/COM+ • To use container-provided services like synchronisation or transactions COM+ services can be used • COM+-Interop provides these features. Markus Voelter/Michael Stal – Comparing J2EE with .NET

  49. Java Component Models • Client Components and Server Components • JavaBeans are Client Components • normal Java classes following some conventions • optionally providing metainformation (BeanInfo class) public class MyJavaBean { private int color; public void setColor(int v) { color = v; } public int getColor() { return color; } // a lot of more ... } // BeanInfo class not shown here! Markus Voelter/Michael Stal – Comparing J2EE with .NET

  50. JNDI Naming Service Deployment Descriptor 1) lookup home EJB Context EJB Home EJB Jar 2) create bean 2”) find bean Remote Bean Home Interface new 4 Client EnterpriseBean ejbCreate ejb... Bean Instance EJB Object 4) remove bean-methods 3) Use bean Remote Bean Interface EJB Run-time Application Server (Container) Server Components in Java • Enterprise JavaBeans (EJBs) always reside in a Container that provides technical aspects (sep. of concerns) Markus Voelter/Michael Stal – Comparing J2EE with .NET

More Related