Chapter 11 Java Network

buninnateΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

131 εμφανίσεις

Chapter 11 Java Network
Programming 1

About

Java

Programming

Language
:



An object
-
oriented programming
language, much easier to learn than C++;


“Write once, run everywhere”


Java code is organised into
class
..


Java is typed.

When running a Java program, it’s
first compiled to

byte
-
codes
.
Byte
-
codes are very similar to
machine instructions, however,
byte
-
codes are not specific to a
particular machine, so Java
programs can be executed on lots of
different computers without
recompiling the programs.

Java

source

programs

are

compiled

to

class

file
,

which

contains

the

byte
-
codes

representation

of

the

program
.

They

can

run

any

platform

that

supports

Java
.


The

Java

system

also

provides

an

extensive

library

of

classes

that

provides

access

to

the

underlying

operating

system
.

A

complete

set

of

hyperlinked

API

documentation

for

these

libraries,

listed

below
:

»
Java
.
lang



»
Java
.
util



»
Java
.
io



»
Java
.
net



»
Java
.
awt



»
Java
.
applet


Java Library of Classes

Topics in this chapter


The client side of networking with
TCP


Multithreading & concurrent server


The server side of networking with
TCP

The client side of networking with
TCP


IP address, which are used to address the
remote target of TCP connections, are
provided by the
InetAddress

class.


TCP connections are created using the
Socket

class.


Examples of coding.

Multithreading & Concurrent Servers


The concept
-

Multithreading


The threads may execute in the same data
space


The Java provides a Thread class for
handling threads


Variable scope in threads


Synchronization and Semaphores

Class Thread


Constructor


Static methods


Instance methods


Interface Runnable


Thread subclass


Examples of Coding

The Server Side of Networking with
TCP


A server picks a port number and listens
for connections; whenever a client
connects, the server receives a Socket
through which to communicate with the
client.


Class
ServerSocket


Example: Building an echo server