Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Comparing J2EE with .NET - ACCU 2002 Markus Voelter, CTO, MATHEMA AG [email protected] http://www.voelter.de Slides (mostly ) by Michael Stal, Senior Principal Engineer SIEMENS AG, Dept. CT SE 2 E-Mail: mailto:[email protected] Web: http://www.stal.de 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 Folie 2 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 Folie 3 Web Frameworks Core elements of Web Frameworks Web Service User/Provider Mainframe Backend Server Legacy Micro/Macro Services Integration Layer Frontend Layer Virtual Machine Workflow Engine (Web Server) 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 Folie 4 .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 ASP.NET Windows Forms (Web Services, Web Forms, ASP.NET Application Services) (Controls, Drawing, Windows 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 Markus Voelter/Michael Stal – Comparing J2EE with .NET TabletPC, PocketPC, .... Folie 5 Sun ONE (Open Net Environment) Service Creation and Assembly (JB, JSP, EJB) Web Services Smart Policy Smart Process (LDAP, Kerberos, PKI, OASIS Security)) (ebXML, XAML) Service Integration (SQL, JDBC, XML, XSLT, XP, JMS, RMI, J2EE Connectors, ...) Process Management Smart Management (SNMP, CIM, WBEM, JMX) Service Container (J2EE, EJB, JSP, J2SE, J2ME, MIDP, Java Card) Service Platform Service Interface Smart Delivery (XML, HTML, XHTML, WML, VoiceXML, XSLT, HTTP, SSL, XP, SOAP, WSDL, UDDI, ebXML, ...) Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 6 Layer-By-Layer Comparison Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 7 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 Folie 8 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 Folie 9 The Runtime System Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 10 .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# VB.NET C++ Perl Compiler MSIL + Metadata Garbage Collection, Security, Multithreading, ... Loader/ Verifier Execution Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 11 JIT Managed Code 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 Java Compiler CLASSFiles Garbage Collection, Security Manager Call-in+Call-out, Multithreading, ... Classloader/ Verifier JIT Interpreter Hotspot Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 12 Native Code Commonalities and Differences Commonalities: • Basic concepts are similar Differences: • Java is intended for interpretation (e.g. typedependent 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 Folie 13 The Object Model Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 14 Object Model (.NET) In .NET, everything is an object Types Value Types Reference Types Pointers System Value Types Interfaces User Value Types Self-describing Types Enumerations Classes Delegates Arrays Boxed Values User-Defined Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 15 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 Folie 16 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 Folie 17 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 Folie 18 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 Folie 19 Object Model (Java) Primitive types cannot be transparently used as an object. Special Holder classes are necessary. Integer i_ref = new Integer(7); List l = ... l.add( i_ref ); There are no special function references. Java uses Observer Pattern with callback interfaces and inner classes Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 20 .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 Folie 21 .NET-Types that are not available in Java cont‘d Enumerations (value type): enum Color : byte { RED = 1, BLUE = 2, GREEN = 3 }; Jagged and unjagged Arrays: int [2][] a; a[0] = new int[]{1}; a[1] = new int[]{1,2}; int [,] a = new int[2,2]; Structs (value types): • Structs are implicitly sealed • they do not support inheritance public struct Name { public String First; public String Last; } Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 22 Commonalities and Differences Commonalities: Differences • 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) • 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 Folie 23 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 Folie 24 .NET Examples Using an Atttribute [AuthorIs(„Michael“)] class MyClass { ... } • There are several predefined attributes (WebService, WebMethod, ...) Defining an Attribute [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 Folie 25 .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 Folie 26 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 Folie 27 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 Folie 28 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 Folie 29 Statements (cont‘d) Differences: • Iterators in .NET: foreach (Elem i in MyContainer) { Console.WriteLine(i); } ... class MyContainer : IEnumerable, IEnumerator { public IEnumerator GetEnumerator() { return (IEnumerator)this; } public void Reset() { ... } public bool MoveNext() { ... } public object Current { get { ... } } } • Note that these are still no „internal iterators“ as in Smalltalk, for example! Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 30 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 Folie 31 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 Folie 32 Statements (cont‘d) Differences: • .NET supports Indexers, Java does not. object[17] = 22; // In class: Int [] m_a; public double this[int pos] { get { return m_a[pos]; } set { m_a[pos] = value; } } • Indexers also work with non-integer keys, such as strings Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 33 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 Folie 34 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 Folie 35 Statements (cont‘d) Exceptions in Java • Exceptions have to be declared in the throws-clause public int insert(int i) throws OverLimitException; { … } Exceptions in .NET • Exceptions are not declared // only way to tell you about // OverLimitException thrown below public int insert(int i) { … } Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 36 Important Base Classes No big conceptual differences here. .NET Java GUI Windows.Forms Web.Forms SWING, AWT Kommunikation System.Net: Connection, HttpWebRequest, ... Java.net: Sockets, URL, ... Container System.Collections: ArrayList, BitArray, Maps, Queue, List, Stack java.util: Lists, Maps, Sets, Trees, Vectors Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 37 Multithreading Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 38 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 tMarkus = new Thread(new Worker().loop)); Voelter/Michael Stal –ThreadStart(new Comparing J2EE with .NET t.Start(); t.Join(); 1 Folie 39 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 tMarkus = new Thread(new Voelter/Michael Stal –Worker()); Comparing J2EE with .NET t.start(); t.join(); 1 Folie 40 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 Folie 41 Deployment Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 42 Assemblies in .NET Assembly=Set of Types name Sharedname version Hash Files Manifest Custom Attributes Type 1 IL-Code Type 2 IL-Code Type 3 IL-Code Referenced Security Assemblies Product Information Metadata Module 1 Resources Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 43 Types 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 Folie 44 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 Folie 45 Commonalities and Differences Commonalities: • Assemblies and JAR files provide „deployment“ components Differences: • Much better versioning support in .NET (side-byside execution) Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 46 Component Models Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 47 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 Folie 48 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 Folie 49 Server Components in Java Enterprise JavaBeans (EJBs) always reside in a Container that provides technical aspects (sep. of concerns) JNDI Naming Service 1) lookup home 2) create bean 2”) find bean Deployment Descriptor EJB Home Remote Bean Home Interface EJB Context EJB Jar new 4 Client EnterpriseBean EJB Object 4) remove 3) Use bean Remote Bean Interface ejbCreate ejb... Bean Instance bean-methods Markus Voelter/Michael Stal – Comparing J2EE with .NET EJB Run-time Application Server (Container) Folie 50 Server Components in Java cont‘d 4 Types of Beans • • • • Stateless Session-Beans (Service Components) Stateful Session Beans (Session Components) Entity-Beans (Entity Components) Message-Driven Beans (asynch. Service Components) A bean is (theoretically) portable across containers (Application Servers) from different vendors. Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 51 Commonalities and Differences Commonalities: • Server Components are available (Assemblies + COM+, EJB). • Interop with legacy components in .NET using COM+, in Java using CORBA) Differences: • EJB are a more mature and proven model • Special APIs to connect to legacy systems (Java Connector API) Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 52 Database Access in .NET In .NET there is ADO.NET • “connectionless” Client DataSet Command DataSetCommand Connection Data Source Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 53 DataReader Managed Provider .NET-Beispiel using System; using System.Data; using System.Data.SqlClient; string myConnection = “server=myserver;uid=sa;pwd=;database=StockTickerDB”; string myCommand = “SELECT * from StockTable”; SqlDataSetCommand datasetCommand = new SqlDataSetCommand(myCommand, myConnection); DataSet myDataSet = new DataSet(); datasetCommand.FillDataSet(myDataSet, “StockTable”); DataTable myTable =ds.Tables[“StockTable”]; foreach (DataRow row in myTable.Rows) { Console.WriteLine(“Value of {0} is {1}”, row[“LongName”], row[“Value”]); } Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 54 ADO.NET ADO.NET is XML based (XML Infoset) • DataSet dynamically builds an XML schema inside to store the data • Relational data and XML data can be handled in a similar way!! ADO.NET works offline once the data is fetched • Updating is partly automatic using DataSets Currently there are two Managed Providers: • SQL Server • ADO Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 55 Database Access in Java Java provides JDBC to access relational data Application Statement Resultset Prepared Statement Connection Callable Statement Driver Manager JDBC/ ODBC Bridge ODBC Driver Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 56 ODBC DB Java Example import java.sql.*; // without error handling: Class.forName(„sun.jdbc.odbc.JdbcOdbcDriver“); Connection con=DriverManager.getConnection(„jdbc:odbc:stocks,““,““); Statement stmt = con.CreateStatement(); ResultSet rs = stmt.executeQuery(„SELECT * from stocks“); while (rs.next()) { System.out.println(rs.getString(„COMPANYNAME“)); } rs.close(); stmt.close(); con.close(); Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 57 Database Access in Java There are several other APIs: • Embedded SQL in the form of SQLJ (uses JDBC internally) • Proprietary ODBMS APIs • Standardized JDO API to provide (more or less transparent) persistence for Java Objects • XML is handled differently! • Java Connector API provides access to other „connection oriented“ legacy systems (such as SAP R3) Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 58 Commonalities and Differences Commonalities: • Decoupling of the concrete data model and the user (using DataSets and ResultSets) Differences: • ADO.NET uses XML extensively, JDBC has a more relational flavor • JDBC is connection oriented, ADO.NET always works non-connected, or offline • .NET DataSets are a kind of In-Memory-DatabaseCache. Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 59 XML Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 60 XML and .NET .NET is very XML-centric • • • • Web Services (SOAP) Configuration Files Result sets of a database access (ADO.NET) XML processing itself Note that formally, many .NET features are based on the XML infoset („XML semantics“) and do not necessarily require megabytes of text data!! Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 61 XML and .NET cont‘d The System.Xml Namespace provides a whole lot of classes • DOM processing using XmlNode & Sons • XPath and XslTransform • XmlTextReader und XmlTextWriter similar to SAX in that they are both stream-based, but .NET uses a Pull-Model Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 62 XML und Java There are several standards and tools available However, Java‘s libraries have not been designed with XML as a basis (Java‘s too old ) JAXP (Java API for XML Parsing) supports DOM and SAX. Currently under development • • • • • • • • DOM, SAX Xerces/Xalan, JDOM JAX{M,B,R,RPC} Castor JAXM (Java API for XML Messaging) JAXB (Java API for XML Data Binding) JAXR (Java API for XML Registries) JAX/RPC (Java API for XML based RPC) Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 63 Remoting Somebody knows a nice picture here? Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 64 Remoting in .NET Application Domain A Application Domain B Client Servant Transparent Proxy Real Proxy Object Context Sinks Server Context Sinks Envoy Sinks Channels Formatters Network Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 65 Channels Formatters Remoting in .NET (cont‘d) .NET Remoting provides pluggable transports and formatters • currently TCP and HTTP transport and • binary and SOAP formatters Contexts are automatically propagated (very neat feature!!) Only very simple lifecycle management options for servants (compared to EJB or CORBA) • Singleton (one object for all calls) • SingleCall (new instance for each call) • Client-Activated based on leases Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 66 Remoting in .NET (cont‘d) Objects can be marshalled by value (Serializable) Asynchronous invocations are easily possible without touching the servant Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 67 Remoting in Java Several possibilities: RMI/CORBA • RMI can use JRMP or IIOP as a transport protocol • Not pluggable – changes in the code are necessary Client Stub Server Stub/Skeleton-Layer Remote Reference Manager Transport Layer Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 68 Skeleton Commonalities and Differences Commonalities: • Relatively easy to use Unterschiede: • .NET Remoting can be extended more flexibly • Java provides Interop with CORBA • Asynchronous invocations are not easily possible with Java Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 69 Web Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 70 ASP.NET (Server-Side Scripting) ASP.NET Architecture: (1) get a.apx Client (4) HTTP file IIS 5 Web Server (2) process (3) result .NET Assembly Other Assemblies .NET Engine Database Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 71 ASP.NET Example A simple login screen: Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 72 ASP.NET Example (cont‘d) <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="LoginPage.WebForm1" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <body> <form id="Form1" method="post" runat="server"> <asp:Label id="TitleLabel" runat="server">Please specify your name and password</asp:Label> <br> <asp:Label id="LoginLabel" runat="server">Login</asp:Label> <br> <asp:TextBox id="LoginText" runat="server"></asp:TextBox> <asp:RequiredFieldValidator id="RequiredFieldValidator" runat="server" ErrorMessage="You need to specify your name" ControlToValidate="LoginText"></asp:RequiredFieldValidator> <br> <asp:Label id="PasswordLabel" runat="server">Password</asp:Label> <br> <asp:TextBox id="PasswordText" runat="server" TextMode="Password"></asp:TextBox> <br> <asp:Button id="EnterButton" runat="server" Text="Open the entrance" ToolTip="Press this after you have specified login and password"></asp:Button> <br> <asp:Label id="MessageText" runat="server"></asp:Label> </form> </body> Markus Voelter/Michael Stal – Comparing J2EE with .NET </HTML> Folie 73 ASP.NET Example (cont‘d) // lot of details omitted namespace LoginPage { public class WebForm1 : System.Web.UI.Page { protected TextBox PasswordText, LoginText; protected Button EnterButton; protected Label MessageLabel; private void InitializeComponent() { this.EnterButton.Click += new System.EventHandler(this.EnterButton_Click); this.Load += new System.EventHandler(this.Page_Load); } private void EnterButton_Click(object sender, System.EventArgs e) { if (!(LoginText.Text.Equals("aladdin") && PasswordText.Text.Equals("sesam"))) { MessageLabel.Text = " Wrong name or password!"; } else { Session["user"] = "aladdin"; Response.Redirect("UserArea.aspx"); } } } Markus Voelter/Michael Stal – Comparing J2EE with .NET } Folie 74 Java Server Pages and Servlets Java also allows for server-side scripting • JSPs are based on Servlets (1) get a.jsp Client (5) HTTP file Web Server (2) process Other Components JSP (3) gen. Servlet Servlet Impl. (4) result Servlet JVM Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 75 Database Java Example Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 76 Java Example Bean und JSP-Seite: // Datei MyPerson.java package MyPackage; import java.lang.*; public class MyPerson { public String getFirstName() { return "Michael"; } public String getLastName() { return "Stal"; } } // Datei MyTest.jsp: <HTML> <BODY> <jsp:useBean id="person" scope="session" class="MyPackage.MyPerson"/> Your name is: <br> <jsp:getProperty name="person" property="firstName"/> <br> <jsp:getProperty name="person" property="lastName"/> Markus Voelter/Michael Stal – Comparing J2EE with .NET </BODY> Folie </HTML> 77 Commonalities and Differences Commonalities: • Pages are precompiled to accelerate access • Similar syntax and concepts • ASP.NET provides „GUI components“ using Webcontrols, Java provides Taglibs. Differences: • All .NET languages can be used for ASP.NET scripting • Servlets/JSP are available for a wide range of webservers • Many open source implementations, frameworks and tools for Java Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 78 Web Services in .NET .NET provides a very comfortable and well-integrated way to build them: namespace WebService1 { public class Service1 : System.Web.Services.WebService { // lot of stuff omitted [WebMethod] public double DM_to_Euro(double value) { return value / 1.95583; } [WebMethod] public double Euro_to_DM(double value) { return value * 1.95583; } } } Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 79 Web Services in .NET (forts.) Using it is also simple • Some steps have been ommitted localhost.Service1 s1 = new localhost.Service1(); double result = s1.Euro_to_DM(200); Webservices are „just a special way of remoting“ BUT: • Microsoft does not provide ebXML compliance • Currently they can only be used with MS server Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 80 Web Services in Java Sun ONE will provide a Web Service API for Java, completely ebXML compliant Currently there are many proprietary solutions • Some specific SOAP toolkits: - Apache SOAP - IBM Web Services Toolkit - GLUE • Some integrated with the major application servers - Silverstream IONA Weblogic ... Sun works at standard APIs • JAXM Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 81 Commonalities and Differences Commonalities: • Both.NET and Java try to be standards-compliant (SOAP, WSDL, UDDI). • Handling very similar: WSDLbased generators that create proxies Differences: • For Java there are different solutions, whereas .NET provides only one, natively • Currently, standards are interpreted differently, so Interop Java-.NET is only limited. But this will hopefully change!! Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 82 More Enterprise APIs Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 83 Enterprise APIs Naming: • JNDI in Java (as an interface to CORBANaming, LDAP, ...) • Active Directory in .NET (Windows-specific) Message-orientierte Middleware: • JMS in Java • JAXM is on the horizon (XML based messaging) • .NET can use MSMQ, and remoting can be used asynchronously Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 84 Legacy-Integration In .NET using the Microsoft Host Integration Server. In Java using the Connector API Comparison: Java provides a much simpler way. Connectors can be implemented relatively straight forward. Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 85 Interoperability Java provides access to C/C++ using JNI (Java Native Interface). Relatively complex call-in, call-out. .NET provides PInvoke: class PInvokeTest { [DllImport("user32.dll")] static extern int MessageBoxA(int hWnd, string m, string c, int t); static void Main(string[] args) { MessageBoxA(0, "Hello DLL", "My Window", 0); } } Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 86 Interoperability cont‘d In .NET there is a way to interop with COM+ and COM+ Services. Java provides CORBA interop JMS provides integration with MoMs In .NET, the interop between .NET languages is almost perfect and easy • Use the same assemblies, class libraries… • Languages had to be adapted a little bit (e.g. Managed C++ does not provide multiple inheritance) Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 87 Mobile and Embedded Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 88 Profiles and devices There are the following variants of Java • J2SE (Java 2 Platform Standard Edition) • J2EE (Java 2 Platform Enterprise Edition) • J2ME (Java 2 Platform Micro Edition) - Configurations, - and Profiles • JavaCard Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 89 Profiles and devices cont‘d .NET Universe • .NET: Framework for Standard und Enterprise • .NET Compact Framework for Windows CE (and other embedded OS) - Design Goals: > Resource saving > Adaptability regarding device properties > Compatibility with the standard IDEs > Easy integration > Seamless connectivity - No ASP.NET, Reflection.Emit, Optimized JIT - Depending on machine stack - Simplified versioning and security, but similar formats Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 90 Profiles and devices cont‘d .NET Mobile Web SDK • • • • • Abstraction for the developer Several markup languages (WML, HTML, ...) Configurable and extendible ASP.NET can be used Emulators for devices are available for testing and debugging purposes • Extends ASP.NET with special controls Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 91 Selecting one of the two Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 92 .NET and/or Java ? .NET is a product, Java and J2EE is a specification Both adress the web (among other things) For „real big systems“ J2EE is better suited The rule-of-thumb „Java is platform- independent,´.NET is language independent“ must be considered carefully: • ECMA works on the standardization of C# and parts of .NET • Other languages can be compiled to the JVM Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 93 .NET and/or Java ? .NET language independence is not for free and not completely transparent #pragma once using namespace System; // .NET mit C++ namespace CPPBase { public __gc class CPPBaseClass { public: virtual System::String __gc* Echo(System::String __gc *s); }; } System::String __gc * CPPBase::CPPBaseClass::Echo(System::String __gc *s) { return s; } In a real project you might want to use only one language • But sometimes... Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 94 .NET and/or Java ? Windows Applications are probably better done with .NET than Java (maybe IBMs SWT changes this ?) Java should be used when platform (or vendor) independence is necessary Java is more mature There will also be Java for .NET (Rational) • But syntax is not the issue! Both can be used for web services - .NET is „nicer“, J2EE is more scalable Analysts proclaim a fifty/fifty situation for Java and .NET Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 95 Management Summary - 1 .NET Java Controller/Owner Microsoft Sun + JCP-Partner Status Product Line Specification and many implementations Languages C#, C++, Eiffel#, VB, .... Java Communication middleware (RPC, Messaging, Web) .NET Remoting, MSMQ, Web Services (no ebXML) RMI/CORBA, JMS, Web Services (standard compliant) Server Components COM+ Enterprise JavaBeans XML-Support Consistent Currently not yet completely integrated Server Pages ASP.NET JSP/Servlets Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 96 + possibly others Management Summary - 2 .NET Java Database access ADO.NET (ADO) JDBC / SQLJ and others Base libraries Many many classes on System.* Many many classes on java.* GUI-Libs Windows.Forms Web.Forms Swing/AWT Runtime .NET CLR Java JVM Interop (call-in/call-out) PInvoke JNI InteropMiddleware COM/COM+ (COM Interop) CORBA, JMS Legacy Integration Host Integration Server JCA Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 97 The End Thank you very much!! Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 98