Beruflich Dokumente
Kultur Dokumente
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
This is intended to be an objective
comparisons of the two platforms
Interoperability issues
Agenda
Motivation Comparison
Visions: Sun ONE and .NET Layer-by-Layer comparison of the infrastructures
Summary Literature
Web Frameworks
Core elements of Web Frameworks
Web Service User/Provider
Mainframe Backend Server Legacy Integration Layer
Micro/Macro Services
Frontend Layer
(Web Server)
Core Services (Calendar, Preferences, Transactions, ...) Service Context (Who, Where, When, Why, ....)
Clients
Markus Voelter/Michael Stal Comparing J2EE with .NET Folie 4
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
Web Services
Smart Process
(ebXML, XAML)
Smart Policy
(LDAP, Kerberos, PKI, OASIS Security))
(SQL, JDBC, XML, XSLT, XP, JMS, RMI, J2EE Connectors, ...)
Service Integration
Process Management
Service Container
Service Interface
Service Platform
Smart Delivery (XML, HTML, XHTML, WML, VoiceXML, XSLT, HTTP, SSL, XP, SOAP, WSDL, UDDI, ebXML, ...)
Layer-By-Layer Comparison
Layers
Runtime System Object model Base classes
Enterprise
-
- Reflection,
Component model Database access XML Server Pages Remoting Web Services More Enterprise APIs
.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, ...
Compiler
Java
CLASSFiles
Garbage Collection, Security Manager Call-in+Call-out, Multithreading, ...
Classloader/ Verifier
JIT
Interpreter Hotspot
Native Code
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
Enumerations
Delegates
Boxed Values
User-Defined
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
Classes
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
Structs
(value types):
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 doesnt.
Differences
Metainformation
Java and .NET provide a reflection API
to load and instantiate classes and inspect classes (introspection).
.NET Examples
Using an Atttribute
[AuthorIs(Michael)] class MyClass { ... }
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
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 }
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.
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 dont know you); break; }
Markus Voelter/Michael Stal Comparing J2EE with .NET Folie 29
Statements (contd)
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 (contd)
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; } }
Statements (contd)
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 (contd)
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; } }
Statements (contd)
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);
Statements (contd)
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 (contd)
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) { }
.NET
GUI Kommunikation Windows.Forms Web.Forms System.Net: Connection, HttpWebRequest, ...
Java
SWING, AWT Java.net: Sockets, URL, ...
Container
Multithreading
Multithreading in .NET
.NET uses delegates for multithreading
The ThreadStart in the example below
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(); 40 1 Folie t.join();
Differences:
In Java, synchronization is better integrated into the Java language Java provides better synchronization and thread communication (wait, notify, ...).
Deployment
Assemblies in .NET
Assembly=Set of Types
name version
Custom Attributes
Sharedname Hash
Files
Types
Manifest
Metadata Module 1
Resources
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!!
They contain
types resources optionally, metadata in manifest files.
There is no versioning!
Markus Voelter/Michael Stal Comparing J2EE with .NET Folie 45
Differences:
Much better versioning support in .NET (side-byside execution)
Component Models
EJB Jar
new
4 ejbCreate ejb...
EnterpriseBean
Client
4) remove 3) Use bean
Remote Bean Interface
EJB Object
Bean Instance
bean-methods
Markus Voelter/Michael Stal Comparing J2EE with .NET EJB Server (Container) Application Run-time Folie 50
Differences:
EJB are a more mature and proven model Special APIs to connect to legacy systems (Java Connector API)
Command
DataSetCommand
DataReader
Connection
Managed Provider
Data Source
Markus Voelter/Michael Stal Comparing J2EE with .NET Folie 53
.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!!
ODBC Driver
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();
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.
XML
However, Javas libraries have not been designed with XML as a basis (Javas 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)
Remoting
Remoting in .NET
Application Domain A Application Domain B
Client
Servant
Network
Channels Formatters
(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
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 Stub/Skeleton-Layer Remote Reference Manager Transport Layer
Markus Voelter/Michael Stal Comparing J2EE with .NET Folie 68
Server Skeleton
Unterschiede:
.NET Remoting can be extended more flexibly Java provides Interop with CORBA Asynchronous invocations are not easily possible with Java
Web
Client
(4) HTTP file
(2) process
.NET Assembly
.NET Engine
Other Assemblies
(3) result
Database
ASP.NET Example
Client
(5) HTTP file
Web Server
(2) process
JSP
Other Components
Impl.
(4) result
Servlet
Database
JVM
Java Example
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>
Differences:
BUT:
Microsoft does not provide ebXML compliance Currently they can only be used with MS server
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
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
Legacy-Integration
In .NET using the Microsoft Host
Integration Server. In Java using the Connector API
Interoperability
Java provides access to C/C++ using
JNI (Java Native Interface). Relatively complex call-in, call-out.
Interoperability contd
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
JavaCard
.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
.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; }
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
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
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.* Swing/AWT Java JVM JNI CORBA, JMS JCA
The End