Professional Documents
Culture Documents
.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
Goal
Interoperability issues
Motivation
Comparison
• Visions: Sun ONE and .NET
• Layer-by-Layer comparison of the
infrastructures
Summary
Literature
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 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
Sun ONE (Open Net
Environment)
Service Creation and Assembly
(JB, JSP, EJB)
Web Services
Smart Process Smart Policy
(ebXML, XAML) (LDAP, Kerberos, PKI,
OASIS Security))
Service
Service
Integration
Process Container
(SQL, JDBC, XML,
(J2EE, EJB, JSP, Service Interface
XSLT, XP, JMS, Management
J2SE, J2ME,
RMI, J2EE Connectors,
MIDP, Java Card)
...)
Smart Delivery
(XML, HTML, XHTML,
Smart Management WML, VoiceXML,
(SNMP, CIM, WBEM, JMX) Service Platform XSLT, HTTP, SSL,
XP, SOAP, WSDL,
UDDI, ebXML, ...)
In C# and Java:
using System;
namespace MyNameSpace {
public class MyClass {
public static void Main(String [] args) {
Console.WriteLine(„Hello, C#!“);
}
}
}
package MyPackage;
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
VB.NET
MSIL + Loader/
Metadata JIT
Verifier
C++
Garbage
Collection, Managed
Perl Security, Execution
Multithreading,
Code
...
Garbage
Collection, Interpreter
Security Manager
Call-in+Call-out,
Multithreading, Native
...
Hotspot Code
Markus Voelter/Michael Stal – Comparing J2EE with .NET
Folie 12
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
Enumerations
Classes Arrays
User-Defined
Arrays Interfaces
Classes
class AnotherClass {
...
public delegate void LightTurnedOn(int which);
public event LightTurnedOn OnLightTurnedOn;
...
OnLightTurnedOn+= new
LightTurnedOn(MyClass.somebodyTurnedOnTheLight);
}
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;}
}
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});
}
}
}
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:
• 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 { ... } }
}
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; }
}
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; }
}
Differences:
• .NET supports operator overloading!
...
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; }
...
}
Exceptions in .NET
• Exceptions are not declared
.NET Java
GUI Windows.Forms SWING, AWT
Web.Forms
Kommunikation System.Net: Java.net: Sockets, URL,
Connection, ...
HttpWebRequest, ...
Assembly=Set of Types
name Sharedname Files Types
Type 1
IL-Code Metadata
Type 2
IL-Code Module 1
Type 3
IL-Code
Resources
Markus Voelter/Michael Stal – Comparing J2EE with .NET
Folie 43
Assemblies in .NET
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-by-side execution)
EJB
EJB
2) create bean Context EJB
Home
2”) find bean Jar
Remote Bean
Home Interface
new
4
Client
EnterpriseBean
ejbCreate Bean
EJB ejb...
4) remove Instance
Object
3) Use bean Remote Bean bean-methods
Interface
DataSet
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”]);
}
Statement
Prepared
Resultset Connection Driver Manager
Statement
Callable JDBC/
Statement ODBC Bridge
ODBC Driver
ODBC
DB
Markus Voelter/Michael Stal – Comparing J2EE with .NET
Folie 56
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();
Somebody knows
a nice picture
here?
Client Servant
Transparent Proxy
Object Context Sinks
Real Proxy
Server Context Sinks
Envoy Sinks
Channels Channels
Network
Formatters Formatters
Transport Layer
Database
JVM
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!!
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