Title: UMass Lowell Computer Science 91.460 Java and Distributed Computing Prof. Karen Daniels Fall, 2000
1UMass Lowell Computer Science 91.460 Java and
Distributed Computing Prof. Karen Daniels Fall,
2000
- Lecture 4
- HW1 Electronic Submission of Part 2
- Jini Overview (continued)
- C Diagnostic Results
- Java Fundamentals
- Wed. 9/13/00
2Electronic Submission of Homework 1, Part 2
- Mon, 9/18 Hello World programming
- (application and applet)
- Note If you want to use Swing on HW1 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 HW2.
Homework is due at the start of lecture on the
due date.
3Electronic 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 - Youll submit 5 files for HW1, part 2 2 for
application, 3 for applet - Submission deadline is 930 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 Mondays lecture
Homework is due at the start of lecture on the
due date.
4Jini Overview (continued)
5Requirements for Service, Client
- Participate in discovery to find a Lookup Service
- Communicate with a Lookup Service to receive
service proxy
To be a Jini Service
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
6Hello World in a Jini Setting...
7Who 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
8Further 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, OSullivan,
Scheifler, Waldo, and Wollrath - Gartner Advisory
- Java Jini A Killer-App Enabler for Network
Computing? http//gartner.jmu.edu/research/ras/830
00/83044/83044.html
portions of this slide contributed by Ayal Spitz
9C 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
10Java 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
11Syllabus for Part 1 of the Course
Part 1
Closed book Worth 15 of grade
12Why 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/OriginalJavaWhitepa
per.pdf
13C to C to Java At a Glance
C
Java
C
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 Mul
tiple Inheritance Polymorphism Templates
Primitive Data Types Arrays Operators Expressi
ons Control Statements Dynamic Memory
Mgt File I/O Exception Handling Classes,
Interfaces Inheritance Polymorphism Su
pport for DBs, networks, GUIs, events, graphics,
threads, libraries
u
u
Procedural/OO, Compiled Language
Procedural, Compiled Language
OO, Interpreted Language
14Introduction 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
15Introduction 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
ltHTMLgt ltAPPLET codeWelcome1Applet.class
width150 height100gt lt/APPLETgt lt/HTMLgt
16Introduction to Java Applets (continued)
- Order of (a subset of) applet method invocations
- init( )
- start( )
- paint( )
17Java 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
18Java Primitive Data Types
19Java 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 int24
- int c new int2 // allocate rows
for non-rectangular array - c0 new int3 // allocate columns for
row 0 - c1 new int4 // allocate columns for
row 1 - Knows its own length! (e.g. c.length)
- Bounds are checked for you!
20Java 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
21Some Java Operators Deitel, p. 271 complete
list is in Appendix C
Precedence Operator higher up the chart is
evaluated before operator lower down the chart
Associativity Order of evaluation for operators
of equal precedence
22Expressions
- 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., (ab)c))
- Includes literals (numbers or strings)
23Java 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/ Enseignem
ent/analyseinfo/BNFweb.html
24Statements
- 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
25Java 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
26Java 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