Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The Common Language Infrastructure CLI and Microsoft .NET Framework languages like C# and VB share various similarities with Sun Microsystemss JVM and Java. These are virtual machine models which conceal the computer hardware details on which their programs run. The other similarity is that both of these frameworks make use of their own intermediate byte-code. Microsoft naming theirs Common Intermediate Language and Sun naming theirs as Java bytecode.
G53ELC
> hello.exe
assembly
Bytecode
G53ELC Bytecode, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter.
Bytecodes are compact numeric codes, constants, and references which encode the result of parsing and semantic analysis of things like type, scope, and nesting depths of program objects.
They therefore allow much better performance than direct interpretation of source code.
Cont..
G53ELC
The generic add instruction would require an interpreter to track the data type of the top of stack element, which
Control transfer
Method invocation and return
The Bytecode and MSIL is interpreted by virtual machines JVM for Java Bytecode CLR for MSIL
Interpreter
Java Runtime
JVM Architecture
G53ELC
A Bytecode Example
public class X {
public static void main(String[] args) { add(1, 2); } public static int add(int a, int b) { return a+b; }
}
G53ELC public static void main(java.lang.String[]); Code: 0: iconst_1 1: iconst_2 //Method add:(II)I 2: invokestatic #2; 5: pop 6: return
their code
G53ELC
Managed Code consists of instructions written in a pseudo-machine language called common intermediate language, or IL.
IL instructions are just-in-time (JIT) compiled into native machine code at run time
JIT Compiler
G53ELC
Architecture
G53ELC
Programming model
G53ELC Source Code Compiler CIL & Metadata
Class Lib
Execution
C# Code
using System; namespace Swapping { class Swap { int a, b, c; public void Get() { Console.WriteLine("Enter 2 no"); this.a = Convert.ToInt32(Console.ReadLine()); this.b = Convert.ToInt32(Console.ReadLine()); } public void Show() { this.c = this.a; this.a = this.b; this.b = this.c; Console.WriteLine("After Swapping a={0} b={1}", this.a, this.b); } } }
G53ELC
G53ELC
G53ELC
G53ELC
CLR vs JVM
C#
VB .Net Managed Lots of other C/C++ Languages
G53ELC
MSIL
CLR CTS GC Security Runtime Services Windows OS
Both are middle layers between an intermediate language & the underlying OS
25
G53ELC
C++, VB, C#, (J#) APL, COBOL, Eiffel, Forth, Fortran, Haskel, SML, Mercury, Mondrian, Oberon, Pascal, Perl,
G53ELC
programming
development
language
research
during
Impressive extensions for generics and support for functional languages underway
Managed execution environment Garbage Collection Metadata and Byte code Platform-abstraction class library Runtime-level security Runs across hardware platforms
JVM X
X X X X X
CLR X
X X X X ?
28
ASP .NET
Windows Client
SQL Server
29
Browser
DB Server
Java Client
30
Web services
G53ELC Web services are typically application programming interfaces (API) or Web APIs that are accessed via Hypertext Transfer Protocol (HTTP) and executed on a remote system hosting the requested services.
Can use Web Services to integrate across departments, agencies, to companies, etc.
Java Web services: Suns Web service implementation for the Java community. Comes bundled in a complete Java Web services Development Pack (JWSDP Ver 1.3) including Tomcat web server.
Apache Axis: Initially developed by IBM and donated to the Apache group. One of the earliest and stable Web service implementation. Runs on Apache Web servers.
HTTP Server
Servlet engine (e.g. Apache Tomcat)
Any class Any class processing Any class processing Any class the incoming processing the incoming processing requests the incoming requests the logic (businessincoming requests (business logic requests (business logic (business logic
hello/HelloWorld.java
package hello; public interface HelloWorld { String getHelloMessage(); void setHelloMessage (String newHello); } G53ELC
hello/HelloWorldService.java
package hello; public class HelloWorldService implements HelloWorld { String message = "Hello, world!"; public String getHelloMessage() { return message; } public void setHelloMessage (String newMessage) { message = newMessage; } }
import org.apache.axis.client.*; public class HelloWorldClient { public static void main (String [] args) { try { G53ELC // prepare the call (the same for all called methods) Call call = (Call) new Service().createCall(); call.setTargetEndpointAddress (new java.net.URL("http://localhost:8080/axis/services/Hello")); // call "get message" if (args.length == 0) { call.setOperationName ("getHelloMessage"); String result = (String) call.invoke ( new Object [] {} ); System.out.println (result); System.exit (0); } // call "set message" and afterwards "get message" call.setMaintainSession (true); // TRY also without this line... call.setOperationName ("setHelloMessage"); call.invoke ( new Object [] { args[0] } ); call.setOperationName ("getHelloMessage"); System.out.println (call.invoke ( new Object [] {} )); } catch (Exception e) { System.err.println ("ERROR:\n" + e.toString()); } }
HelloWorldClient.java
G53ELC
HelloWorldServiceLocator
getHello()
HelloWorld
implements
HelloSoapBindingStub
HelloWorldClientFromStubs.java
public class HelloWorldClientFromStubs { public static void main (String [] args) { try { // prepare the calls (the same for all called methods) hello.generated.HelloWorldService service = new hello.generated.HelloWorldServiceLocator(); hello.generated.HelloWorld myHelloProxy = service.getHello(); // call "get message" if (args.length == 0) { String result = myHelloProxy.getHelloMessage() System.out.println (result); System.exit (0); } // call "set message" and afterwards "get message myHelloProxy.setHelloMessage (args[0]); System.out.println (myHelloProxy.getHelloMessage());
G53ELC
43
G53ELC
Java
.Net
J2SE, J2EE
Defined by Sun and the Java Community Process Not bound to any operating system Defined as packages and interfaces
Class Libraries
G53ELC
Source: http://java.sun.com/j2ee/blueprints Illustrates best coding practices for J2EE Ships as a sample application in IBM Websphere, Oracle Application Server 9i, Sun iPlanet, and BEA WebLogic
47
G53ELC The .NET Petshop is a port of the J2EE Java Pet Store to .NET Source: http://www.gotdotnet.com/compare Implements the same functionality as Java Pet Store Illustrates best coding practices for .NET Framework
In the TMC Petshop Performance Case Study, The Middleware Company implemented both the Java Pet Store and the .Net Petshop. The J2EE version ran on two different application servers All versions used the same hardware and OS
The Storefront presents the main user interfaceG53ELC in a Web front-end. Customers use the Storefront to place orders for pets.
The Order Processing Center (OPC) receives orders from the Storefront.
The Supplier fulfills orders from the OPC from inventory and invoices the OPC. The Admin presents the administrator interface in a JFC/Swing front-end. Administrators use the Admin to examine pending orders and approve or deny them.
49
50
G53ELC
11500
5,891
5,404
User Interface
Middle Tier
Data Tier
Configuration
52
53
G53ELC
Browser Apps
Local Apps
Other Apps
GUI Services
Transaction Services
Web Scripting
Data Access
More
Browser Apps
Local Apps
Other Apps
Windows Forms
Enterprise Services
ASP.NET
ADO.NET
More
Browser Apps
Local Apps
Other Apps
Swing
Enterprise JavaBeans
JavaServer Pages
JDBC
More
Standard Java Packages Java Virtual Machine (VM) Windows, Solaris, Linux, others
But!
G53ELC .NET IS COMPELLING! It has everything an enterprise architecture needs It is fast It is simpler to use than J2EE to develop It has features that J2EE does not
eg web forms
Runtime Statistics
.NET ran 28 times faster that J2EE Supported 7.6 times more concurrent users Used the CPU cycles for the same load Do not believe these statistics!
G53ELC
Picked to show MS in best possible light But it .NET is probably more efficient
Reference
G53ELC
G53ELC
63