1 / 26

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000. Lecture 4 HW#1: Electronic Submission of Part 2 Jini Overview (continued) C++ Diagnostic Results Java Fundamentals Wed. 9/13/00. Electronic Submission of Homework #1, Part 2.

Download Presentation

UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000

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. UMass Lowell Computer Science 91.460Java and Distributed ComputingProf. Karen DanielsFall, 2000 Lecture 4 HW#1: Electronic Submission of Part 2 Jini Overview (continued) C++ Diagnostic Results Java Fundamentals Wed. 9/13/00

  2. Electronic Submission of Homework #1, Part 2 Mon, 9/18 “Hello World” programming (application and applet) • Note: If you want to use Swing on HW#1 in UML CS UNIX environment, use the Java version located in: /usr/opt/java122/bin • /usr/opt/java122/bin/javac • /usr/opt/java122/bin/java • Entire class will transition to this Java version starting with HW#2. Homework is due at the start of lecture on the due date.

  3. Electronic Submission of Homework #1, Part 2 Mon, 9/18 “Hello World” programming (application and applet) • To submit your files electronically, use the UNIX submit command • Example for 3 files: • submit kdaniels hw1 filename.java filename.class filename.html • You’ll submit 5 files for HW#1, part 2: 2 for application, 3 for applet • Submission deadline is 9:30 a.m. on Monday, 18 September • I have now set it up to allow multiple submissions before the deadline • Bring a paper printout of your code to give to me at start of Monday’s lecture Homework is due at the start of lecture on the due date.

  4. Jini Overview (continued)

  5. Requirements for Service, Client To be a Jini Service: • Participate in discovery to find a Lookup Service • Communicate with a Lookup Service to receive service proxy To be a Jini Client: • Either you or a delegate must be able to: • Connect to a TCP/IP network ( ) • Participate in discovery to find a Lookup Service • Register with a Lookup Service to provide proxy • Keep leases current Extra “machinery” needed: - http server(s) for each machine to offer up downloadable code - RMI activation daemon

  6. HelloWorldServiceInterface.java HelloWorldService.java HelloWorldClient.java c: corejini chapter5 HelloWorldServiceInterface.class HelloWorldClient$Listener.class HelloWorldClient.class client corejini chapter5 HelloWorldServiceInterface.class HelloWorldServiceProxy.class HelloWorldService$Listener.class HelloWorldService.class service corejini chapter5 service-dl corejini chapter5 HelloWorldServiceProxy.class policy.all policy Hello World in a Jini Setting...

  7. Who Else is in the Game?(other providers of coordination frameworks/connection technologies/service architectures for distributed computing) • HAVi • Sony, Sharp, Toshiba, Philips, RCA, Matsushita, Hitachi, Grundig • Microsoft & HP • ChaiAppliance Plug and Play • eSpeak • Universal Plug and Play • Network protocol level • XML device description • Salutation Framework

  8. Further Information – Jini • Sun web sites • http://www.javasoft.com/jini • http://www.jini.org • Development – Books • “Core Jini” by W. Keith Edwards • “The Jini Specification” by Arnold, O’Sullivan, Scheifler, Waldo, and Wollrath • Gartner Advisory: • Java Jini: A ‘Killer-App Enabler’ for Network Computing? http://gartner.jmu.edu/research/ras/83000/83044/83044.html portions of this slide contributed by Ayal Spitz

  9. C++ Diagnostic Results Number of Students 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 Number of Correct Responses Most students ran out of time… 1 2 3 4 5 6 7 8 9 Question Number

  10. Java Fundamentals • 1: Java fundamentals • applets, applications, data types, control structures, OO programming, files • 2: Advanced Java concepts & Java support for distributed computing • GUI/events, graphics, exceptions, advanced data structures, threads/ multithreading, RMI • 3: Distributed computing using a sample Java-based environment: Jini

  11. Syllabus for Part 1 of the Course Part 1 Closed book; Worth 15% of grade

  12. Why Java & Distributed Computing? • Platform independence helps with heterogeneous hardware, software challenge • Built-in support for: • Multithreading: “concurrent” multiple activities • Client-Server computing: servlets, JDBC • Remote Method Invocation (RMI): method calls across network • Networking: socket-based communication views networking like file I/O For insight into the original Java vision, see the original Java whitepaper by James Gosling at: http://java.sun.com/people/jag/OriginalJavaWhitepaper.pdf

  13. C to C++ to Java: At a Glance C C++ Java Primitive Data Types Arrays Struct, Union, Enum Preprocessor Directives Operators Expressions Control Statements Functions Pointers Dynamic Memory Mgt File I/O Exception Handling Primitive Data Types Arrays Struct, Union, Enum Preprocessor Directives Operators Expressions Control Statements Functions Pointers Dynamic Memory Mgt File I/O Exception Handling Classes Multiple Inheritance Polymorphism Templates Primitive Data Types Arrays Operators Expressions Control Statements Dynamic Memory Mgt File I/O Exception Handling Classes, Interfaces Inheritance Polymorphism Support for DBs, networks, GUIs, events, graphics, threads, libraries u u Procedural/OO, Compiled Language Procedural, Compiled Language OO, Interpreted Language

  14. Introduction to Java Applications • Java application is executed using the Java interpreter (but not inside browser like an applet) • Application begins execution in main( ) • main( ) is static method inside class • no convenient input from command line • System.exit(0); // required to clean up // after GUI/graphics javac Welcome1.java java Welcome1 Welcome1.java // Save this in file Welcome1.java public class Welcome1{ public static void main( String args[] ) { System.out.println( "Java is fun!" ); } } Welcome1.class

  15. Introduction to Java Applets • Java applet is executed inside a WWW browser (or appletviewer) using a Java interpreter that is inside the browser. // Save this file in Welcome1Applet.java import java.applet.*; import java.awt.*; public class Welcome1Applet extends Applet{ public void paint(Graphics g) { g.drawString( "Java is fun!”, 25, 50 ); } } javac Welcome1Applet.java appletviewer Welcome1Applet.html Welcome1Applet.java Welcome1Applet.class Welcome1Applet.html Save this file in Welcome1Applet.html <HTML> <APPLET code=“Welcome1Applet.class” width=150 height=100> </APPLET> </HTML>

  16. Introduction to Java Applets (continued) • Order of (a subset of) applet method invocations: • init( ) • start( ) • paint( )

  17. Java Variables • Two types: • primitive data type variable (a.k.a. variable) • always passed by value • initialized by default to 0 if numeric; false if boolean • except for local variables • value is constant if final keyword is used • reference variable (a.k.a. reference) • refers to memory location of object • always passed by reference • initialized by default to null

  18. Java Primitive Data Types

  19. Java Array Class • Declarations: • One-dimensional: • int c [ ]; c = new int [8]; • int c [ ] = new int [8]; • final int ARRAY_SIZE = 8; int c [ ] = new int [ARRAY_SIZE]; • int c [ ] = { 32, 44, 6, 7, -1, 25, 88, -31 }; • Multi-dimensional (e.g. 2): • int c[ ][ ] = { {32, 44, 6, 7 } , {-1, 25, 88, -31} }; • int c[ ][ ] = new int[2][4]; • int c[ ][ ] = new int[2][ ]; // allocate rows for non-rectangular array • c[0] = new int[3]; // allocate columns for row 0 • c[1] = new int[4]; // allocate columns for row 1 • Knows its own length! (e.g. c.length) • Bounds are checked for you!

  20. Java String Class (basics) • String is a series of characters treated as a single unit • Declarations and Constructors: • String s; // empty string for now -- its length is 0 • s = new String(); // String() is null constructor. It yields an empty // string for now whose length is 0 • s = new String(“hello”); // initializes s to “hello” • String s = “hello”; // initializes s to “hello” • s2 = new String (s1); // copy constructor • String s = “hello” + “ world”; // String concatenation • s1.equals (s2); // tests equality of contents • s1 = = s2 // tests if both refer to same object in memory • Knows its own length! (e.g. s.length) • Array of Strings: String Pets[ ] = {“dog”, “cat”, “fish”};

  21. Some Java Operators [Deitel, p. 271; complete list is in Appendix C] Precedence: Operator higher up the chart is evaluated before operator lower down the chartAssociativity: Order of evaluation for operators of equal precedence

  22. Expressions • Sequence of operators and operands that specifies a computation • May result in a value (e.g., 123, true) • May cause side-effects (e.g., change a value) • Compound expressions (e.g., (a*b)+c)) • Includes literals (numbers or strings)

  23. Java Expression BNF expression ::= numeric_expression | testing_expression | logical_expression | string_expression | bit_expression | casting_expression | creating_expression | literal_expression | "null" | "super" | "this" | identifier | ( "(" expression ")" ) | ( expression ( ( "(" [ arglist ] ")" ) | ( "[" expression "]" ) | ( "." expression ) | ( "," expression ) | ( "instanceof" ( class_name | interface_name ) ) ) ) From http://cuiwww.unige.ch/db-research/ Enseignement/analyseinfo/BNFweb.html

  24. Statements • Smallest “executable” unit • Declaration statements • Control statements • Assignment statements • Method invocation • Compound statement (block) • Semicolon-separated list of statements • Enclosed in “curly” brackets { } • Deitel calls it a ‘block’ only if it has declarations of its own

  25. Java Abstract Windowing Toolkit GUI Components(from java.awt package) • java.awt.Graphics (see list on p. 530-531) • Given an object g of Graphics class: • g.setColor( Color.red ); // Sets current drawing color to red • g.drawString(“hello”, 200, 25); // Draws String starting at (200,25) • g.drawLine(20, 28, 40, 10 ); // Draws line from (20,28) to (40,10) • g.fillRect(100, 5, 20, 15); // Draws filled rectangle whose upper left // corner is at (100, 5). Width = 20. Height = 15 • g.drawOval(60, 9, 20, 13); // Draws oval whose bounding box upper left // corner is at (60, 9). Width = 20. Height = 13 uses current color (0,0) x y hello

  26. Java Swing GUI Components(from javax.swing package) • javax.swing.JOptionPane • Dialog box • message • error • information • warning • question • plain • input • javax.swing.JTextArea • javax.swing.JScrollPane

More Related