WWW Jet Infosystems
,
1.
2. , WWW
3. Java, Joe, NEO
4. Java -
4.1. Java
4.1.1. Java
4.1.2.
4.1.3.
4.1.4.
4.1.5.
4.1.6.
4.2. Java
4.2.1. Java-
4.2.2. Java-
4.2.3. Java
4.2.4. Java WorkShop
4.3. Java :
4.3.1.
4.3.2. ( )
4.3.3.
4.3.4.
4.3.5. Component,
5. Joe - Java- -
-
6.
Java,
" ". , , -
( -
" ") . -
- -
(. 1).
. 1. Java (
).
-
. , -
, , . -
WWW- Java -
. , -
, , -
" " -
.
,
?
,
Java .
. -
" " -
. , ,
, -
. ,
, Java.
, ?
. ,
.
. -
-
,
. . ,
, , ,
.
- .
,
. -
.
, -
, . -
, ,
, (. 2).
. 2.
, , -
. .
, , ,
, .
. -
, , -
, .
, -
.
,
- ,
. ,
, -
, .
, 10
,
, -
, , , -
. -
- (. 3).
. 3.
.
-
,
,
,
(. 4).
. 4.
.
, -
, -
, Web- -
(. 5).
. 5. Web-
(, ,
, ) ,
, -
, ,
"".
-
, -
, .
Web, , -
. -
, -
. -
,
.
, Web- Web- -
" ". Web - -
, --
.
, Web- ,
HTTP-. -,
-
WWW- (,
, WWW-).
-, Web- .
HTTP, ,
. -
. , ,
. , -
, , -
.
-, Web- -
,
.
15 . .
Java- .
- .
Web-, ,
.
, Java.
Java - - ,
C++, -
. Java - -
, Web--
, , Web-
--
, Java- ,
.
, -
Web-, .
- Java-,
() Java-. -
, -
Java-. Java-
. , --
Java--
; , Java, .
- , Java--
Web-
, , -
( , WWW-).
, -
.
, -
.
, ( -
) .
, -
, , , Java--
. -
, . , ,
- , -
.
Java- -
Web-. -
.
, -
, Java.
, -
, .
-
. ,
Java-, WWW-,
( , ) .
Java. -
.
, WWW-
Java- -
Java- (, , Java
, , , C++). , ,
, ,
. ,
" " -
Java-, Java
.
, ,
Web- , -
, ,
, (, ),
-
.
WWW,
,
, . ,
, Java,
(. 6).
. 6. Java- -
.
?
-
Java .
Sun Microsystems -
- NEO (NEtworked Objects, ).
NEO CORBA (Common Object Request
Broker Architecture), .
NEO -
,
, -
(. 7).
. 7.
.
,
Java- NEO-. ,
-
( Java , -
C/C++, ),
, Java
"" MS-Windows. 1996 -
SunSoft
Joe,
Java- ,
NEO (. 8).
. 8. Java, Joe NEO.
,
-.
Java.
, Joe.
Java , , -
, C++.
- -
, :
-
-
- .
Java
.
Java C++ .
; -
. ,
( -
Java-).
1 class Point extends Object {
2 private double x;
3 private double y;
4 Point (double x, double y) {
5 this.x = x;
6 this.y = y;
7 }
8 Point () {
9 this (0.0, 0.0);
10 }
11 public void setX (double x) {
12 this.x = x;
13 }
14 public void setY (double y) {
15 this.y = y;
16 }
. . .
17 }
Java ()
. class
. , -
.
extends ( 1). Object - -
. Java -"": ,
Object, . -
.
(private, protected, public)
, C++, .
, ,
(. ).
9
.
- . Java .
, ( -
).
, ,
finalize. -
, .
this (., , 5 9)
. -
super:
1 class ThreePoint extends Point {
2 protected double z;
3 ThreePoint () {
4 super ();
5 z = 0.0;
6 }
7 ThreePoint (double x, double y, double z) {
8 super (x, y);
9 this.z = z;
10 }
11 }
4 8 .
, Java, C++,
, -
.
C++, static
,
. ( , , -
, Java .)
java.lang.
1 public final
2 class Character extends Object {
3 public static final int MAX_RADIX = 36;
4 static char downCase[];
5 static {
6 char down[] = new char[256];
7 for (int i = 0 ; i < 256 ; i++) {
8 down[i] = (char) i;
9 }
10 for (int lower = 'a' ; lower <= 'z' ; lower++) {
11 int upper = (lower + ('A' - 'a'));
12 down[upper] = (char)lower;
13 }
14 for (int lower = 0xE0; lower <= 0xFE; lower++) {
15 if (lower != 0xF7) { // multiply and divide
16 int upper = (lower + ('A' - 'a'));
17 down[upper] = (char)lower;
18 }
19 }
20 downCase = down;
21 }
22 public static boolean isLowerCase(char ch) {
23 return (upCase[ch] != ch);
24 }
25 }
Java C++.
5 21
,
Java-.
Character.
1 3 final. 1
Character. 3 const
C++.
final , -
-.
C++, Java ,
. , -
, . -
( ) abstract.
.
Java , -
java.lang. . 9
.
. 9. Java.
Class. -
Class (,
). Class
getClass, -
Object.
Class -
"" .
Class, , :
1 public native String getName();
2 public native Class getSuperclass();
3 public static native Class forName(String className)
throws ClassNotFoundException;
forName .
native ,
, Java- (, -
C).
Java -
C++. -, Java .
-, -
( final
). -, Java -
C++ .
. :
public interface Verbose {
public void drawOn (Graphics g);
public void printOn (OutputStream os);
}
public class Star extends Polygon implements Verbose {
public void drawOn (Graphics g) {
//
}
public void printOn (OutputStream os) {
//
}
}
public class Text extends StringBuffer implements Verbose {
public void drawOn (Graphics g) {
//
}
public void printOn (OutputStream os) {
//
}
}
public class Blackboard extends Canvas {
public void drawVerbose (Verbose d) {
Graphics g = getGraphics ();
d.drawOn (g);
}
}
Verbose .
, -
.
Star
(Polygon). ,
(Blackboard) .
Text
.
Blackboard - Canvas, -
. ,
, -
( Object).
, -
.
, -
.
new. -
.
- new . .
Point myPoint = new Point ();
( new)
Java .
, (
-
). .
, , -
.
,
( ). .
Point p = new Point (100.0, 100.0);
. . .
p = new Point (1.0, 1.0);
// (100, 100)
{
String s = new String ("Local string");
System.out.println (s);
}
// "Local string"
finalize. - , -
, finalize .
Java ,
. .
Java , ,
.
- :
- - byte - 8 ,
- - short - 16 ,
- - int - 32 ,
- - long - 64 .
, unsigned .
- :
- - float - 32 ,
- - double - 64 .
IEEE 754.
- char
char 16- (
0-65535). Unicode. -
Java-.
- boolean
true false, -
.
Java, , . -
.
Point myPoints[];
myPoints Point.
myPoints = new Point[10];
null.
-
:
howMany = myPoints.length;
( ) Java
, , .. Java -
.
, String
( ) StringBuffer ( ).
,
String hello = "Hello world!";
Java . ,
, -
, ,
private
protected.
. " "
Java .
package my_packages.pack1:
package
Java-. .
-
import. ,
import java.util;
import java.util.HashTable;
import java.util.*;
import
util :
util.Vector
util.HashTable
. . .
HashTable,
,
util.
import -
util.
Java , -
( ,
). .
test:
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (i > 3) {
break test;
}
}
}
break,
continue ( ).
goto Java .
, -
, Java try/
catch/finally. try ,
.
catch
. , finally -
,
try. try-
(break, return
..) finally .
- Throwable. ,
ArrayIndexOutOfBoundsException -
, OutOfMemoryException - -
, ClassCastException
- ,
InterruptedException -
.. String,
.
getMessage .
-
. , InterruptedIOException
, , -
.
messages. -
,
. (,
).
try {
for (int i = 0; i < 100; i++) {
System.out.println (messages[i]);
}
}
catch (ArrayOutOfBoundException e) {
System.out.println ("No more messages");
}
catch (Exception e) {
System.out.println ("Unexpected exception");
System.out.println (e.getMessage());
}
finally {
System.out.println ("Work done");
}
-
throw new MyException ("Something's wrong");
Java
. ( Error) -
, (
Java-). ( Exception) -
, -
. -
,
try/catch/finally,
throws Exception1, Exception2, ...
.
class Foo extends Object {
. . .
public void readFromFile (String fn) throws InvalidFormatException {
FileInputStream fis;
try {
fis = new FileInputStream (fn);
// .
. . .
// ,
// :
throw new InvalidFormatException ("Wrong format");
. . .
}
catch (FileNotFoundException e) {
//
}
finaly {
if (fis != null )
fis.close(); // ,
}
}
. . .
}
readFromFile -
. , -
.
readFromFile. ,
.
.
-
. -
, , -
.
, Java
.
Java Thread, -
Runnable, synchronized
Object wait notify.
4.1.6.1. Thread Runnable
(thread)
. , ,
, .
start()
Thread. , -
, run(). , run() -
;
, .
run(), Thread
stop() destroy().
.
-
suspend(), sleep() yeild().
, suspend, -
resume().
sleep()
.
yeild()
; -
.
Java- . -
, Java- .
, -
. , -
. ,
, , -
- -
suspend(), sleep() yeild().
. 10 .
. 10. .
-
"/". -
, Mark Tillotson -
comp.lang.java.
class my_producer extends Thread
{
int items_to_do ;
my_buffer the_buffer ;
my_producer (my_buffer buf, int count)
{ super() ;
the_buffer = buf ;
items_to_do = count ;
}
public void run ()
{
while (items_to_do > 0)
{ System.out.println ("producer to_do = " + items_to_do) ;
Integer item = new Integer (items_to_do*items_to_do) ;
the_buffer.insert (item) ;
items_to_do-- ;
}
System.out.println ("producer exiting") ;
}
}
.
my_producer -
Thread, -
, run(). ,
, - -
,
Runnable. -
- run(). .
1 class SomethingToRun extends BaseRunner implements Runnable {
2 private Thread aThread;
3 public void run () {
//
. . .
4 }
5 SomethingToRun () {
6 aThread = new Thread (this);
7 aTread.start ();
8 }
9 }
6 . -
SomethingToRun, , ,
run()
. start() 7
.
,
Java
. "-
/".
, ,
Java, , -
70- -.
Java- ,
synchronized. -
, synchronized
() .
( )
synchronized () ;
.
-
.
.
wait() ,
-
, - -
notify() notifyAll(). -
.
class my_buffer
{
Object [] vec = new Object [8] ;
int ip = 0 ;
int ep = 0 ;
synchronized void insert (Object item)
{
do
{
if (ip-ep < 8)
{ vec [(ip++) & 7] = item ;
if (ip-ep == 1) notify () ; // ,
return ;
}
try wait () ; catch (InterruptedException e) ;
} while (true) ;
}
synchronized Object extract ()
{
do
{
if (ip > ep)
{ Object result = vec [(ep++) & 7] ;
if (ip-ep == 7) notify(); // ,
return result ;
}
try wait () ; catch (InterruptedException e) ;
} while (true) ;
}
}
class my_producer extends Thread
{
int items_to_do ;
my_buffer the_buffer ;
my_producer (my_buffer buf, int count)
{ super() ;
the_buffer = buf ;
items_to_do = count ;
}
public void run ()
{
while (items_to_do > 0)
{ System.out.println ("producer to_do = " + items_to_do) ;
Integer item = new Integer (items_to_do*items_to_do) ;
the_buffer.insert (item) ;
items_to_do-- ;
}
System.out.println (" ") ;
}
}
class my_consumer extends Thread
{
int items_to_do ;
my_buffer the_buffer ;
my_consumer (my_buffer buf, int count)
{ super() ;
the_buffer = buf ;
items_to_do = count ;
}
public void run ()
{
while (items_to_do > 0)
{ System.out.println ("consumer to_do = " + items_to_do) ;
Object item = the_buffer.extract () ;
System.out.println ("consumer got " + item) ;
items_to_do-- ;
}
System.out.println (" ") ;
synchronized (this){
notify () ; //
// (. con.wait() main())
}
}
}
public class threaded3
{
public static void main (String [] args) throws InterruptedException
{
my_buffer the_buffer = new my_buffer () ;
my_producer prod = new my_producer (the_buffer, 40) ;
my_consumer con = new my_consumer (the_buffer, 40) ;
Thread.currentThread().setPriority (5) ;
prod.setPriority (4) ; //
con.setPriority (3) ; //
prod.start() ;
con.start() ;
synchronized (con)
{
con.wait() ; //
//
}
System.out.println (" ") ;
}
}
, .
. insert()
extract() my_buffer wait() -
. , notify() -
. ""
, . , ""
insert(), -
,
. , insert() .
, , , -
, ,
Java- ,
, - -
-
(. xxx).
. xxx. Java-
, , Java-
-
, ,
WWW-.
,
.
public static void main (String args[]);
public-,
, Java-.
args - .
: ,
public class myTop {
public static void main (String args[]){
int argc = args.length;
for (int i = 0; i < argc; i++)
System.out.println (argc[i]);
}
}
Applet:
public void init () ;
public void start (); ;
public void stop (); , Web-;
public void destroy ();
; , ;
stop();
.
:
1 import java.awt.Graphics;
2 import java.applet.Applet;
3 class SimpleApplet extends Applet {
4 public void paint (Graphics g) {
5 g.drawString ("Hello world!", 10, 10);
6 }
7 }
public void paint (Graphics g) ( 4-6) ,
, -
WWW- .
WWW- .
HTML 2.0