INTERNET
 :
  |    

/

, . /

Java

TOC \o "1-3" .

1. , WWW .

2. JAVA, JOE, NEO.

3. JAVA - .

Java.

JAVA.

.

. .

.

.

Java.

.

.

.

.

THREAD RUNNABLE

 

Java

.

.

String.

.

.

java.util.

java.io.

java.net.

java.awt.

java.awt.image.

java.awt.peer.

java.applet.

JAVA.

JAVA-.

JAVA-.

, JAVA-.

.

, .

.

JAVA-.

4. JAVA : .

.

( ).

5. JAVA .

.


.

, , . - , Java. , - Internet Web.

. , , Java. , ?

. , . . , . . , , , , .

Java Oak ( C++, ). Oak Internet Java.

Java C++. C++, Java C++, . , , , . , Java .

Java , , . Internet - Pentium PC, Macintosh, Sun . , Intel, , , Microsoft Windows 3.1, Windows 95, Windows NT, OS/2, Solaris, UNIX XWindows. , Web Internet, , . Java, .

, Java, .

Java, Java. .

- (applets). Java, Java, .

, ( Java), - . , , , , , C++. , Java , Internet.

Java HTML, Web. Web . , Web . ( Java) . Web. , Web - CGI ISAPI.

Java " "- Just-In-Time compilation (JIT). , . Java .

Java - . C++, Java , . , , , , , .


1.      , WWW .

- . , . .

c.1. .

, , . , , , .

, , . . , , , , . . , , , . , .

, - , . , , , .

, 10 , , , ,

c. 2. .

, .

- . , , , . .

.3.

.

, , , Web- .

c.4. Web-.

(, , , ) , , , , "". , , .

Web, , . , . , .

, Web- Web- " ". Web - , - .

, Web- , HTTP-. -, WWW-.

-, Web- . HTTP, , . . , , . , - , , .

-, Web- , . , WWW-, . .

Java- . - . Web-, , . , Java.


2.      JAVA, JOE, NEO.

Java - - , C++, . Java - , Web-, , Web- - , Java- , .

, Web-, :

        Java-, () Java-. , . Java- . , - Java-; , Java, .

        , Java- Web- , , ( , WWW-). , .

, . , . , , , , Java-. . , , - , .

Java- Web-. . , , Java. , , . . , Java-, WWW-, ( , ) .

Java. .

, WWW- Java- Java- (, , Java , , , C++). , , , , 1-2 . " " Java-, , , Java .

c. 5. Java-

, Web- , , , , (, ), .

WWW, , , . , , Java, .

?

- Java . Sun Microsystems - NEO (NEtworked Objects, ). NEO OMG (Object Management Group), . NEO , , .

.6. .

, Java- NEO-. , ( Java , C/C++, ), , Java "".

c. 7. Java, Joe Neo.

SunSoft Joe, Java- , NEO.

, -.


3.      JAVA - .

Java.

. , C .

, , - . , . , .

, 16- Windows 32- Windows 95 Windows NT. , , Windows, , . , , , Windows OS/2 X-Windows UNIX. !

, , . , , , . Intel, Alpha - .

, , .

, , Windows NT, Apple Macintosh. PRIVATE "TYPE=PICT;ALT=pic05.gif (3440 bytes)" Windows NT . . Intel Windows NT.

Macintosh, . - Windows NT , Macintosh. , , Macintosh, Windows NT.

Java , Java. -, Java-. , -, Java . , , , , Java.

Java ( ) , . Java , . -, , Java. , Java , . , , - , ?

Java . , , , .

. , , Java, . Windows, , DLL, Java.

, . - , .

, , , , , , . , Windows 3.1 int , , 16 . Windows NT 32 .

, , , . , .

Java , . .

JAVA.

- , :

       

       

        .

Java .

.

class. union, Java . ++ . Java - . . .

Java . . new, , delete ++ Java .

. Java . public.

Java Object, .

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-.

Java () . class . , .

extends ( 1). Object - . Java -"": , Object, .

(private, protected, public) , C++, . , , (. ).

9 .

- . Java . , ( ). , , finalize. , .

1 class Point3D extends Point {

2 protected double z;

3 Point3D () {

4 super ();

5 z = 0.0;

6 }

7 Point3D (double x, double y, double z) {

8 super (x, y);

9 this.z = z;

10 }

11 }

this (., , 5 9) . super. 4 8 .

, Java, C++, , . , . . , ( static), .

static final, .

final, , .

inline.

Java , . , throws.

1 public native String getName();

2 public native Class getSuperclass();

3 public static native Class forName(String className) throws ClassNotFoundException;

C++, static , . (, - , Java .) java.lang.

Java C++.

5 21 , Java-. Character.

1 3 final. 1 Character. 3 const C++.

final , -.

C++, Java , . , , . ( ) abstract. .

Java , java.lang. Class. Class (, ). Class getClass, Object.

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) {

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 }

Class "" . Class, , .

forName . native , , Java- (, C).

. .

Java C++. -, Java . , . , , . super.

( super).

-, ( final ). -, Java C++ . interface , . , - , , , , .

, implements, . , .

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:

PRIVATE

boolean

8

false

byte

8

0

char

16

'x0'

short

16

0

int

32

0

long

64

0

float

32

0.0F

double

64

0.0D

, , , , short 32 . Java , . Java , . , .

, . , :

int nCounter = 0;

int i;

i = 8;

boolean - true false, . , , boolean, , int - .

byte .

char, UNICODE. , , Internet.

byte, short, int long . Java , .

Java , IEEE 754. float , double - .

, . :

int x;

void ChangeX(int x)

{

x = 5;

}

. . .

x = 0;

ChangeX(x);

ChangeX x .

, , .

Java.

Java . .

Point myPoints[];

myPoints Point.

myPoints = new Point[10];

null.

:

howMany = myPoints.length;

, , , :

int nNumbers[];

int[] nAnotherNumbers;

, , .

Java . . , .

, new, :

int[] nAnotherNumbers;

nAnotherNumbers = new int[15];

?

, . , :

int[] nColorRed = {255, 255, 100, 0, 10};

, , :

int nInitialValue = 7;

int[] nAnotherNumbers;

nAnotherNumbers = new int[15];

for(int i = 0; i < 15; i++)

{

nAnotherNumbers[i] = nInitialValue;

}

, . new.

, , .

. , - :

int[][] nDim = new int[5][10];

nDim[0] = new int [4];

nDim[1] = new int [4];

nDim[2] = new int [8];

Java . , .

Java . , length, :

int[] nAnotherNumbers;

nAnotherNumbers = new int[15];

for(int i = 0; i < nAnotherNumbers.length; i++)

{

nAnotherNumbers[i] = nInitialValue;

}

, sizeof , .

( ) 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 , , .

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");

}

, , messages. , . (, ).

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) {

//

}

finally {

if (fis != null )

fis.close(); // ,

}

}

. . .

}

, readFromFile . , . readFromFile. , . .

.

- . , , . , Java .

Java Thread, Runnable, synchronized Object wait notify.

THREAD RUNNABLE

(thread) . , , , .

start() Thread. , , run(). , run() ; , .

run(), Thread stop() destroy(). .

suspend(), sleep() yeild().

, suspend, resume().

sleep() .

yeild() ; .

Java- . , Java- . , . , . , , , - suspend(), sleep() yeild().

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") ;

}

}

"/ ". , Mark Tillotson comp.lang.java.

.

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 }

my_producer Thread, , run(). , , - , Runnable. - run().

6 . SomethingToRun, , , run() . start() 7 .

, Java . "/".

, , Java, , 70- -'.

Java- , synchronized. , synchronized () . ( )

synchronized () ;

.

. .

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 (" "

+" ") ;

}

}

wait() , , - notify() notifyAll(). .

, . insert() extract() my_buffer wait() . , notify() . "" , . , "" insert(), , . , insert() .

Java

, , .

C++ . Java , . Java.

.

Java Object, , , . , . , , java.lang. Java import.

.

, (wrapper classes). , :

PRIVATE

boolean

Boolean

char

Character

int

Integer

long

Long

float

Float

double

Double

, . .

String.

String , . , C. , , , .

Java () , Stirng "+" "+=". , :

System.out.println("x = " + x + '\n');

println , : "x = ", x '\n'. x ( ) "x = ".

.

Math, , , .

, , .

. , ( !) Java.

.

, Java. Java WorkShop , Java.

java.util.

java.util , , , . , (), .

java.io.

java.io , . , , int .

java.net.

Java , . , Java . java.net . , URL, TCP UDP, IP. , .

, Java Internet, Java Color Lines (. 7).

Lines, , Web, . , , .

java.awt.

Java java.awt. AWT - Abstract Window Toolkit ( ).

, java.awt, , , Java. , , , , , , .

java.awt.image.

. Windows GDI. OS/2 X-Windows, , , . , .

Java, , java.awt.image. , GIF. Internet, .

java.awt.peer.

java.awt.peer AWT (, , , , ) , , .

java.applet.

java.applet Java. , Applet, . java.applet .

JAVA. JAVA-.

, , , , Java- , , - .

. 8. 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 (10, 10, "Hello world!");

6 }

7 }

.

paint ( 4-6) , , WWW- .

WWW- . HTML 2.0 <applet> <PARAM>. , . <PARAM> WWW- , .

<applet code=SimpleApplet.class width=200 height=100>

<PARAM NAME=font VALUE="TimesRoman">

<PARAM NAME=size VALUE="12">

<h3> , Java </h3>

</applet>

WWW-.

WWW- , , Java,

, Java

public void init () {

String fontname = getParameter ("name");

String fontSizestring = getParameter ("size");

int theSize = Int.parseInt (fontSizeString);

. . .

}

, <PARAM>, .

JAVA-.

Java- Java- Java-. , Java- , , , - . , Java-.

. P- -; ; -, .

Java , Java- - . , , Java-. Web- Java-, . , , Java- ; . , Java- , . , Java- ( ), () . , Java-, -.

, JAVA-.

Java- :

        byte - ;

        short - ;

        int - ;

        long - ;

        float - IEEE-754;

        double - ;

        char - Unicode.

Java- , . , . , iadd, - dadd.

boolean .

:

        object - ( );

        returnAddress - .

Java- . Sun Microsystems object , - . .

Java- 32-. (long, double) . , ; , - , "" .

.

Java- :

        pc - ; , .

        vars - .

        optop - . Java- , .

        frame - , .

, : , .

, . ( ). .

.

Java- catch, .

, , , , Java- .

, .

, , Java, , Java . , , . Java .

, , , int long, - , . Java , :

//

int nSomeValue;

// , ,

//

void StoreValue(int *pVar, int nNewValue)

{

pVar->nNewValue;

}

. . .

StoreValue(&nSomeValue, 10);

, , .

Java . , , .

, , . , int Integer, long - Long .

, :

Integer nSomeValue;

nSomeValue = new Integer(10);

nSomeValue Integer. .

Integer, . . nSomeValue Integer .

nSomeValue Integer , .

, , . , .

Java , .

.

Java Java , . , .

Java, " ", . , .

, "" Java . . Java , , . , Java-.

JAVA-.

Java- , ( ). :

        . . , dload , , , aload .

        .

        . , newarray , , , . , - , anewarray. Java-.

        . , , , , , .

        . ; .

        (, , , ).

        .

        . , jsr ( ) ; , jsr, . .

        . . , breakpoint, .

        (/ / ).

        . . invokevirtual () . invokenonvirtual - , . invokestatic . , invokeinterface , . , .

        - athrow.

        ( , ).

        ( , ).

, Java Java-. Java- .

4.    JAVA : .

.

Java , , - . , Java . .

( ) , ( ) . - . , .

, - , , . Motif MS-Windows Macintosh. - , - , - ..

, - . , - , , , , , , , . , , " ", " " ..

, - - , .

, , , "" . MFC, OWL, Zink .

Java- AWT Abstract Windowing Toolkit - .

AWT . "" , , , . AWT , , , ; - , , . . 9.

. 9. AWT.

, Peer.

AWT, . - Java.

( ).

, , , . AWT ( Component), . , - , . , .

:

        Button

        Checkbox

        Label

        List

        ScrollBar

        TextArea

        TextField

:

        Dialog

        FileDialog

        Frame

        Panel

        Window

.


5.    JAVA .

, . Java-, Web- . , Java .

, goto "". , ..

. - , , , Java-.

, , , , , , . , ( UNIX, fork exec), , Java-.

, Java- . , Netscape Navigator 2.0 . , JDK 1.0 Sun Microsystems , .

, :

        ;

        // ;

        ;

        , , .

JDK , ~/.hotjava/properties

acl.read=/home/welcome
acl.write=/tmp

-. , , , , , , .. . finally .

, . , , Argus System Group, , "" . , , Java-. , , Java.


.

Java. , Java.

Java, , C++. C++, Java C++, . , , , . , Java . C++, Java.

Java?

, , , Internet. Internet , , Web, .

Java , , . , , - . , . , .

Java Sun Microsystems . , , , Sun Microsystems. Java WorkShop 2.0 Java Studio 1.0. Java WorkShop 2.0 , , Java. Java WorkShop 2.0 Java, , JavaBeans .

Java Studio 1.0, . , . , .

, Java. , . . , .

Internet HTML, .

Java ( Java), Internet.

- , Web, . .

, Java, . Java. - .

, - . , , . Java HTML, Web. Web .

Java Just-In-Time compilation. , . Java .


.

1.                  ., . HTML. -, 1998. 300.

2.                  // . 1997. -3. -.58 - 68.

3.                  // Java . 1998. -2. . 27-34

4.                  .. . - .: , 1993. 256 .

5.                  . Internet. -Network World, 1998. 500 .

6.                  . . - -, 1997. 200 .

7.                  . . Java. 1998. 250 .


Copyright © 2005—2007 «RefStore.Ru»