From:
greymatterseo
Views: 129
Comments: 0
In this article, we simplify and explain the importance of Cloud. It also includes a section on J2EE web programming on Cloud explaining why J2EE deserves to be on Cloud along with how Java enunciates its presence in the Cloud.
Slide 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
Slide 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 Folie 2
Slide 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 Folie 3
Slide 4: Web Frameworks
Core elements of Web Frameworks
Web Service User/Provider
Mainframe Backend Server Legacy Integration Layer
Micro/Macro Services
Virtual Machine Workflow Engine
Frontend Layer
(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
Slide 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
ASP.NET Windows Forms
(Web Services, Web Forms, ASP.NET Application Services)
Base Classes (ADO.NET, XML, Threading, IO, ....)
(Controls, Drawing, Windows Application Services)
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 .... TabletPC, PocketPC, J2EE with .NET Folie 5
Slide 6: Sun ONE (Open Net Environment)
Service Creation and Assembly
(JB, JSP, EJB)
Web Services
Smart Process
(ebXML, XAML) (LDAP, Kerberos, PKI, OASIS Security))
Smart Policy
(SQL, JDBC, XML, XSLT, XP, JMS, RMI, J2EE Connectors, ...)
Service Integration
Process Management
(J2EE, EJB, JSP, J2SE, J2ME, MIDP, Java Card)
Service Container
Service Interface
Smart Management (SNMP, CIM, WBEM, JMX)
Service Platform
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
Slide 7: Layer-By-Layer Comparison
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 7
Slide 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 Folie 8
Slide 9: Layers
Runtime System Object model Base classes Enterprise
- Reflection, Component model Database access XML Server Pages Remoting Web Services More Enterprise APIs
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 9
Slide 10: The Runtime System
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 10
Slide 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# VB.NET C++ Perl
Compiler
MSIL + Metadata
Garbage Collection, Security, Multithreading, ...
Loader/ Verifier Execution
JIT Managed Code
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 11
Slide 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
Java
CLASSFiles
Garbage Collection, Security Manager Call-in+Call-out, Multithreading, ...
Classloader/ Verifier
JIT
Interpreter Hotspot
Native Code
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 12
Slide 13: Commonalities and Differences
Commonalities: Differences:
• Basic concepts are similar • 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
Slide 14: The Object Model
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 14
Slide 15: Object Model (.NET)
In .NET, everything is an object
Types Value Types Pointers System Value Types User Value Types Self-describing Types Classes Arrays Reference Types Interfaces
Enumerations
Delegates
Boxed Values
User-Defined
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 15
Slide 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 Folie 16
Slide 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 Folie 17
Slide 18: Object Model (Java)
Java has primitive types and classes.
• No automatic boxing/unboxing
Types Primitive Types Arrays Classes Reference Types Interfaces
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 18
Slide 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 Folie 19
Slide 20: Object Model (Java)
Primitive types cannot be transparently
Integer i_ref = new Integer(7); List l = ... l.add( i_ref );
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
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 20
Slide 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 Folie 21
Slide 22: .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
Slide 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) • 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.
Differences
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 23
Slide 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 Folie 24
Slide 25: .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
Slide 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 Folie 26
Slide 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 Folie 27
Slide 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 Folie 28
Slide 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 Folie 29
Slide 30: 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
Slide 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 Folie 31
Slide 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 Folie 32
Slide 33: Statements (cont‘d)
Differences:
object[17] = 22; // In class: Int [] m_a; public double this[int pos] { get { return m_a[pos]; } set { m_a[pos] = value; } }
• .NET supports Indexers, Java does not.
• Indexers also work with non-integer keys, such as strings
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 33
Slide 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 Folie 34
Slide 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 Folie 35
Slide 36: 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
Slide 37: Important Base Classes
No big conceptual differences here.
.NET
GUI Kommunikation Windows.Forms Web.Forms System.Net: Connection, HttpWebRequest, ... System.Collections: ArrayList, BitArray, Maps, Queue, List, Stack
Java
SWING, AWT Java.net: Sockets, URL, ...
Container
java.util: Lists, Maps, Sets, Trees, Vectors
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 37
Slide 38: Multithreading
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 38
Slide 39: Multithreading in .NET
.NET uses delegates for multithreading
• The „ThreadStart“ in the example below • The “lock” in the example below
There are monitors for synchronization
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 – Comparing J2EE with .NET Markus Voelter/Michael Stal ThreadStart(new Worker().loop)); t.Start(); t.Join(); 1 Folie 39
Slide 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 – Comparing J2EE with .NET Markus Voelter/Michael Stal Worker()); t.start(); t.join(); 1 Folie 40
Slide 41: Commonalities and Differences
Commonalities: Differences:
• Threading is very similar! • Both use some forms of monitor for synchronization • 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
Slide 42: Deployment
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 42
Slide 43: Assemblies in .NET
Assembly=Set of Types
name version
Custom Attributes
Sharedname Hash
Files
Types
Manifest
Referenced Security Assemblies Product Information
Type 1 IL-Code Type 2 IL-Code Type 3 IL-Code
Metadata Module 1
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 43
Resources
Slide 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 Folie 44
Slide 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 Folie 45
Slide 46: Commonalities and Differences
Commonalities: Differences:
• Assemblies and JAR files provide „deployment“ components • Much better versioning support in .NET (side-byside execution)
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 46
Slide 47: Component Models
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 47
Slide 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 Folie 48
Slide 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 Voelter/Michael Stal – Comparing J2EE with .NET Markus class not shown here!
Folie 49
Slide 50: 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 EJB Home
Remote Bean Home Interface
Deployment Descriptor EJB Context
2) create bean 2”) find bean
EJB Jar
Client
4) remove 3) Use bean
Remote Bean Interface
new
4 ejbCreate ejb...
EnterpriseBean
EJB Object
Bean Instance
bean-methods
Markus Voelter/Michael Stal – Comparing J2EE with .NET EJB Server (Container) Application Run-time Folie 50
Slide 51: 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
Slide 52: Commonalities and Differences
Commonalities:
• Server Components are available (Assemblies + COM+, EJB). • Interop with legacy components in .NET using COM+, in Java using CORBA) • EJB are a more mature and proven model • Special APIs to connect to legacy systems (Java Connector API)
Differences:
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 52
Slide 53: Database Access in .NET
In .NET there is ADO.NET
• “connectionless”
Client
DataSet
Command
DataSetCommand
DataReader
Connection
Managed Provider
Data Source
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 53
Slide 54: .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
Slide 55: 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
Currently there are two Managed
Providers:
• SQL Server • ADO
• Updating is partly automatic using DataSets
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 55
Slide 56: Database Access in Java
Java provides JDBC to access relational
data
Application Statement Resultset Prepared Statement Callable Statement Connection Driver Manager JDBC/ ODBC Bridge
ODBC Driver
ODBC DB
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 56
Slide 57: 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
Slide 58: 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
Slide 59: Commonalities and Differences
Commonalities: Differences:
• Decoupling of the concrete data model and the user (using DataSets and ResultSets) • 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
Slide 60: XML
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 60
Slide 61: 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
Slide 62: 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
Slide 63: XML und Java
There are several standards and tools available
• • • • DOM, SAX Xerces/Xalan, JDOM JAX{M,B,R,RPC} Castor
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
• • • • 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
Slide 64: Remoting
Somebody knows a nice picture here?
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 64
Slide 65: Remoting in .NET
Application Domain A Application Domain B
Client
Servant
Transparent Proxy Real Proxy Envoy Sinks Channels Formatters
Object Context Sinks Server Context Sinks
Network
Channels Formatters
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 65
Slide 66: 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
Slide 67: 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
Slide 68: Remoting in Java
Several possibilities: RMI/CORBA
Client Stub Stub/Skeleton-Layer Remote Reference Manager Transport Layer
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 68
• RMI can use JRMP or IIOP as a transport protocol • Not pluggable – changes in the code are necessary
Server Skeleton
Slide 69: Commonalities and Differences
Commonalities: Unterschiede:
• • • • Relatively easy to use .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
Slide 70: Web
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 70
Slide 71: ASP.NET (Server-Side Scripting)
ASP.NET Architecture:
(1) get a.apx
Client
(4) HTTP file
IIS 5 Web Server
(2) process
.NET Assembly .NET Engine
Other Assemblies
(3) result
Database
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 71
Slide 72: ASP.NET Example
A simple login screen:
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 72
Slide 73: 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
Slide 74: 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
Slide 75: 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
JSP
Other Components
(3) gen. Servlet Servlet
Impl.
(4) result
Servlet
Database
JVM
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 75
Slide 76: Java Example
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 76
Slide 77: 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 77 </HTML>
Slide 78: Commonalities and Differences
Commonalities:
• Pages are precompiled to accelerate access • Similar syntax and concepts • ASP.NET provides „GUI components“ using Webcontrols, Java provides Taglibs. • 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
Differences:
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 78
Slide 79: 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
Slide 80: 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
Slide 81: 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 Silverstream IONA Weblogic ...
• Some integrated with the major application servers
Sun works at standard APIs
• JAXM
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 81
Slide 82: Commonalities and Differences
Commonalities:
• Both.NET and Java try to be standards-compliant (SOAP, WSDL, UDDI). • Handling very similar: WSDLbased generators that create proxies • 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!!
Differences:
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 82
Slide 83: More Enterprise APIs
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 83
Slide 84: Enterprise APIs
Naming:
• JNDI in Java (as an interface to CORBANaming, LDAP, ...) • Active Directory in .NET (Windows-specific) • JMS in Java • JAXM is on the horizon (XML based messaging) • .NET can use MSMQ, and remoting can be used asynchronously
Message-orientierte Middleware:
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 84
Slide 85: 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
Slide 86: 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
Slide 87: 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
Slide 88: Mobile and Embedded
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 88
Slide 89: 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
Slide 90: 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:
- 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
> Resource saving > Adaptability regarding device properties > Compatibility with the standard IDEs > Easy integration > Seamless connectivity
Slide 91: 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
Slide 92: Selecting one of the two
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 92
Slide 93: .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 platformindependent,´.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
Slide 94: .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
Slide 95: .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
Slide 96: Management Summary - 1
.NET
Controller/Owner Status Languages Communication middleware (RPC, Messaging, Web) Server Components XML-Support Server Pages Microsoft Product Line C#, C++, Eiffel#, VB, .... .NET Remoting, MSMQ, Web Services (no ebXML) COM+ Consistent ASP.NET
Java
Sun + JCP-Partner Specification and many implementations Java
+ possibly others
RMI/CORBA, JMS, Web Services (standard compliant) Enterprise JavaBeans Currently not yet completely integrated JSP/Servlets
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 96
Slide 97: Management Summary - 2
.NET
Database access Base libraries ADO.NET (ADO) Many many classes on System.* Windows.Forms Web.Forms .NET CLR PInvoke COM/COM+ (COM Interop) Host Integration Server
Java
JDBC / SQLJ and others Many many classes on java.*
GUI-Libs Runtime Interop (call-in/call-out) InteropMiddleware Legacy Integration
Swing/AWT Java JVM JNI CORBA, JMS JCA
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 97
Slide 98: The End
Thank you very much!!
Markus Voelter/Michael Stal – Comparing J2EE with .NET Folie 98