1 / 51

Java vs. .Net Livslang Uddannelse August 20 th , 2004

Java vs. .Net Livslang Uddannelse August 20 th , 2004. Bent Thomsen PhD, DIC, Cand.Scient, EurIng, CEng, FBCS, MACM, MIEEE bt@cs.auc.dk Department of Computer Science Aalborg University. Services on Demand Vision. Customer– driven Service enhanced customization. Business Web Modular

taji
Download Presentation

Java vs. .Net Livslang Uddannelse August 20 th , 2004

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java vs. .NetLivslangUddannelseAugust 20th, 2004 Bent Thomsen PhD, DIC, Cand.Scient, EurIng, CEng, FBCS, MACM, MIEEE bt@cs.auc.dk Department of Computer Science Aalborg University

  2. Services on Demand Vision • Customer–driven • Serviceenhanced customization Business Web • Modular • Loosely coupled Industrial age corp. • Vertical • Integrated • Supply-driven • Mass • production • Physical • Scarce • Digital knowledge • Abundance Wireless and pervasive Internet- enabled Mobile dev. PC Client-server EDI Virtual Corporation • Hub & spoke • Tightly coupled Value creation Mainframe Dumb Resources

  3. The Services on Demand Vision The Virtual Enterprise Company A Company B Mobile Employees Mobile Employees Consumers, Partners Consumers, Partners Customers Partners Suppliers Slide from Microsoft .Net presentation

  4. Services on Demand Vision Converged Networks / Broadcast Array of Access Devices Cheap, Faster, Global Networking via Internet Cheap, Faster Processing + interactivity = Revolutionary new business methods Unlimited choice Individual is King Interactive Digital Content But how to build this vision?

  5. The Answer is: Web Services • A Web service is like a Web site without a user interface, that serves programs instead of people. • Instead of getting requests from browsers and returning web pages in response, a web service: • receives a request formatted in XML from an application, • performs a task, • and returns an XML-formatted response. • Web Services are delivered using open industry standards • Services to be described in WSDL • Services to located via UDDI • Data to be exchanged via XML • Protocols are HTTP and SOAP • BUT Back-end systems still need to be developed! • And the smart clients still ned to be developed!

  6. The basic problem ... • If you have software components ... • ... and they shall work together in the same transaction • ... and they shall have the same security boundaries • ... and they shall share the same session state • ... and they shall be remotely accessible • ... and they shall not suffer from code overload • Then you must have ... • ... an infrastructure that hosts such components for secure remote and local access • ... an infrastructure that manages transactions • ... an infrastructure that hides infrastructure code • The answer is: • Applications on Application Servers • Implemented in an Enterprise Solution Framework

  7. Sun One Architecture Support major standards initiatives such as XML, SOAP, UDDI, WDSL and … to make it ready for developers who want to take advantage of the Services on Demand vision

  8. Microsoft’s .NET Support major standards initiatives such as XML, SOAP, UDDI, WDSL and … to make it ready for developers who want to take advantage of the Services on Demand vision

  9. A typical.NET Enterprise Solution IIS on W2k Server SQL Server Browser .NET managed component ASP .NET Windows Client

  10. A typical J2EE Enterprise Solution Java App Server DB Server Browser Servlet JSP EJB Java Client

  11. The rest of this talk • What is Java? • J2SE • J2EE • J2ME • What is .Net? • CLR • CTS • VS.Net • C# • Java vs. .Net how do they compare? • The future

  12. What is Java? • A programming language • Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high performance, multithreaded, dynamic language. From: Java: An Overview James Gosling, Sun Microsystems, February 1995.

  13. What Else is Java? • According to Gosling: • “An environment” • “A platform” • “A way of thinking” • …ok, whatever • Java is a phenomenon • Took the world by storm in 1995 when introduced with the HotJava web Browser • Quickly integrated with Netscape browser

  14. Some History • 1993 Oak project at Sun • small, robust, architecture independent, Object-Oriented, language to control interactive TV. • didn’t go anywhere • 1995 Oak becomes Java • Focus on the web • 1996 Java 1.0 available • 1997 (March) Java 1.1 - some language changes, much larger library, new event handling model • 1997 (September) Java 1.2 beta – huge increase in libraries including Swing, new collection classes, J2EE • 1998 (October) Java 1.2 final (Java2!) • 2000 (April) Java 1.3 final • 2001 Java 1.4 final (assert) • 2004 Java 1.5 (parameterized types, enum, …) • 2005 J2EE 1.5

  15. Java Design Goals • Support secure, high-performance, robust applications running as-is on multiple platforms and over networks • “Architecture-neutral”, portable, allow dynamic updates and adapt to new environments • Look enough like C++ for programmer comfort • Support object-oriented programming • Support concurrency (multithreading) • Simplicity • In some ways, Java is not new • Strongly influenced by the Simula language developed in Norway 35 years ago • Syntax from C, bytecode from SmallTalk

  16. Basic Java Components 3 parts; known as “The Platform” • The Language • Syntax • Compiler • The API’s • Standard set of prewritten packages • The Virtual Machine (VM) • An intermediate layer between Java and the underlying OS • Now comes in many different flavours

  17. Java Advantages • Simplicity • Unlike C++, which inherits much C hocus-pocus, Java was designed to be developer-friendly from the start. • Built-In Features • Memory management: no “memory leaks” • Automatic array-bound checking • “Soft landings”. Errors are handled gracefully, with stack-rollback traces (even line-numbered!). No more core dumps.

  18. Hello World in Java public class HelloWorld { public static void main (String [ ] args) { System.out.println(“Hello World”); } }

  19. It’s all about objects • Java is a purely object-oriented language • (well, almost) • Fundamental unit of a program is a class • Instances of classes are objects • May be helpful to think of objects receiving messages and replying to them instead of calling methods and returning values

  20. object-oriented class Point { int x,y; draw(Graphics g) { g.putPixel(x,y);}} class ColorPoint extends Point { Color c; draw(Graphics g) { g.setColor(c); super.draw(g);}} • encapsulation • overriding • reuse • dynamic dispatch(virtual call) Point p;p.draw(g);

  21. Other Bonuses • Built-in GUI package: the AWT • Single Standard for API documentation • JavaDoc: Generates professional-looking API for any homegrown classes • Jar: “Tar”-like compression and bundling, works on any platform • Runtime Representation • Can determine the class of any object at runtime

  22. Java Advantages • Guaranteed Behavior • “Write once, run anywhere” • By nature of the VM • Platform-independent standards • An int is a 32-bit 2’s-comp. signed integer • A double is a 64-bit IEEE-754 F.P. quantity • It’s Free! • The entire Java development environment (the “JDK”) is free for download from Sun • Windows, Solaris, Linux, Mac OS versions • Huge base of freely-available Java code

  23. Some Standard Library Packages • java.lang – core classes (Math, String, System, Integer, Character, etc.) • Imported automatically • java.util – collections, date/time, random numbers • java.io – input/output streams, files • java.net – network I/O, sockets, URLs • java.awt – basic (original) graphical user interface • java.awt.event – GUI event handling • javax.swing – sophisticated newer GUI built on top of AWT

  24. Java Add-Ons • Java Beans • Component-based Java • JDBC • A Java interface to relational DBs via SQL • JNI (Java Native Interface) • Java interface to non-Java native apps • Applets • Small client-side Java applications running in a web browser • Servlets • Server-based programs for request processing • Midlets • Small Java applications for mobile phones

  25. Java Applets • Applets: • Small embeddable application • A Java applet is a compiled Java program, consisting of classes just like any other Java program • Applets are autonomous programs confined within the walls of the browser or applet viewer. Can interact with user and communicate with the host over the network

  26. Sample Applet • //create a file called HelloWeb.java • public class HelloWeb extends java.applet.Applet • { • public void paint( java.awt.Graphics gc) • { • gc.drawString (“Hello World, Welcome to Java”, 125, 95); • } • } • Compile the java source file (using JDK): javac HelloWeb.java • Create an html file that embeds the applet using the <applet> tag • Load the html page into a java supported browser

  27. Sample HTML Document • <html> • <head> • </head> • <body> • <applet code=HelloWeb width=300 height=200 </applet> • </body> • </html> • Save it as HelloWeb.html • Open HelloWeb.html using the browser

  28. ByteCode: Food for the VM • For most languages, compilation produces machine code • Java compilation produces “bytecode” • Intermediate code readable by the VM • Transferable across the Internet as applets • VM interprets BC into instructions • Partly responsible for performance lag • ByteCode produced on any platform may be executed on any other platform which supports a VM

  29. execution model of Java JIT compiler compiled code compiler source (text) bytecode (aka. class file) JVML dynamic loading virtual machine verifier bytecode interpreter CPU

  30. The JIT • Just-In-Time compiler • Translates bytecode into machine code at runtime • 1-time overhead when run initiated • Performance increase 10-30 times • Now the default for most JVM’s • Can be turned off if desired • JIT can apply statistical optimizations based on runtime usage profile

  31. Not just one JVM, but a whole family • JVM (J2EE & J2SE) • Well-known Java Virtual Machine. • CVM, KVM (J2ME) • Small devices. • Reduces some VM features to fit resource-constrained devices. • JCVM (Java Card) • Smart cards. • It has least VM features. • And there are also lots of other JVMs

  32. Java vs. C

  33. Java 1.5 Standard Edition • new Java Language Features • Autoboxing/unboxing • Static Import • Meta data • Variable Arguments (“Varargs”) • Enhanced for loop • Generics • Typesafe enums • Minimal changes to JVM • Default compilation does not require new JVM • If you use new Java 1.5 features: • Will not run on older JVMs • Must tell javac compiler to run with prior version of compiler: • -source or –target keywords • New Java keywords kept to a minimum

  34. Autoboxing • Up through Java 1.4, primitive types cannot be used where an object is required • They had to be wrapped, or boxed, for instance:myStack.push(new Integer(25)); • Primitive types still cannot be used where an object is required… • …But Java 1.5 now does this conversion automatically: • Now you can say myStack.push(25); • What happens at runtime is still the same • It’s just that the compiler does the conversion for you

  35. Auto-unboxing • Just as you could not use primitive types where an Object was required, you could not use an Object where a primitive type was required • You had to do your own unwrapping, or un-boxing • For instance, you had to write code such as:int result = ((Integer)myStack.pop()).intValue(); • Now you can just write:int result = myStack.pop(); • Even more striking,myStack.push(new Integer(((Integer)myStack.pop()).intValue() + ((Integer)myStack.pop()).intValue()));becomesmyStack.push(myStack.pop() + myStack.pop());

  36. printf()method example • System.out method call to printf(): System.out.printf(“%d %.2f %.2e\n", 78, 1.23456, 1.23456); • will print: 78 1.23 1.23e+00

  37. Generic types • Up through Java 1.4, collections hold arbitrary Objects • If you wanted, say, a Vector of Employees, you had two basic choices: • Use a Vector • Adding anEmployee is easy (but so is adding any otherObject, however inappropriate) • Getting an Employee from the Vector usually requires a cast, which may result in a runtime error • Extend Vector with an EmployeeVector class • Checking is done at compile time (which is better than runtime) • It’s a lot of extra work • Generic types do the second of these automatically for you • Syntax: Vector<Employee> employees = new Vector<Employee>();

  38. An example • Instead of: • ArrayList list = new ArrayList();list.add(0, new Integer(42));int total = ((Integer)list.get(0)).intValue(); • You can say: • ArrayList<Integer> list = new ArrayList<Integer>();list.add(0, new Integer(42));int total = list.get(0).intValue(); • Advantages: • Less work to create specialized data structures • Checking done at compile time rather than runtime • For C++ programmers, the syntax is familiar • Disadvantage: • Yet more ugly syntax to learn

  39. Java Platform & VM & Devices

  40. J2EE – Enterprise Java • J2EE: Java 2 Enterprise Edition • Superset of Java 2 Standard Edition (J2SE) • Adds enterprise features to Java Libraries • Defined through the Java Community Process (JCP) • plus whatever Sun sees fit, Sun has last word • Sun writes almost all specs and other contribute • Submitters essentially surrender all rights to Sun • Wholly owned property of Sun Microsystems • Licensing controlled by Sun, by Sun's rules • JCP Broadens Sun's architect's base

  41. Enterprise Java • J2EE (1.4+) is an infrastructure specification for: • Components ("Beans") • Data Source Connectivity • XML and Messaging • Web Pages and Web Services • Implemented by: Sun, IBM, BEA, Oracle, etc. • IBM WebSphere (37% market share 2002/33% 2000) • BEA WebLogic (29% MS 2002/59% 2000) • SUN iPlanet (4% MS 2002/3% 2000) • Oracle Application Server 9i • Fujitsu Interstage • … • All vendors implement core specification, but: • Some areas in J2EE are (intentionally) not specified • The more specific a functionality the more proprietary the implementation gets Numbers from the web, allegedly originally from Gartner DataQuest

  42. J2EE 1.5 • J2EE (1.5) preview of 26.4.2004 • Focus on ease of development • Generics and metadata as in J2SE 1.5 • Java Studio Creator tool (in beta from April 2004) • Timeframe • To be discussed at JavaOne in June • Finalized in approximately one year

  43. Java 2 Platform Architecture

  44. Java 2 Micro Edition “Java 2 Platform, Micro Edition (J2ME) is a Java based Programming language that lets you build client side Applications (called MIDlets) optimized for mobile devices that have limited resources.”

  45. J2ME Executive Committee BEA Systems Cisco Systems Ericsson IBM Insignia Matsushita (Panasonic) Motorola Nokia Palm Philips Research In Motion Siemens Sony Sun Microsystems Texas Instruments Zucotto Wireless

  46. Java 2 Micro Edition Applications Portability APIs Midlet Foundation Profile MIDP Libraries CDC JVM Mobile phone CLDC KVM Java 2 Micro Edition

  47. Typical J2ME Technology Stack Your MIDlet Yellow Pages, train schedules and ticketing, games… Mobile Information Device Profile UI, HTTP networking... J2ME core APIs CLDC = KVM + J2ME Core APIs in this example Threads, no Floats… KVM 32-bit RISC, 256K ROM, 256K Flash, 64K RAM DSP chip(e.g., ARM)

  48. MIDP Application Lifecycle Pause pauseApp startApp Active destroyApp destroyApp Destroyed • MIDP applications are known as “MIDlets” • MIDlets move from state to state in the lifecycle, as indicated. • Start – acquire resources and start executing • Pause – release resources and become quiescent (wait) • Destroy – release all resources, destroy threads, and end all activity • Managed by the JavaTM Application Manager (JAM) • A software app that comes with MIDP implementation that controls the installation, execution and removal of MIDLets • Provides an execution environment for a MIDLet • Handles all errors that occurs during installation and execution of app without crashing the system

  49. Tour of CLDC/MIDP • Packages • Javax.microedition.io • Javax.microedition.lcdui • Javax.microedition.midlet • Javax.microedtion.rms • Contains user interface widgets • Form, TextField, TextBox, DateField, List, Image, Gauge, Alert, Canvas, Graphics, Display • Event handling classes – Command and CommandListener • Two APIs, high and low • High level for GUI widgets, scrolling, etc. • Low level for graphics and fine-grained UI control

  50. Sample Code import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class HiMIDlet extends MIDlet { private TextBox textbox; public HiMIDlet() { textbox = new TextBox ("", "Hello World!", 20, 0); } public void startApp() { Display.getDisplay(this).setCurrent(textbox); } public void pauseApp() {} public void destroyApp(boolean unconditional) {} }

More Related