Sun, Sun Microsystems, the Sun Logo, the Java programming language, J2SE
5.0, and ... Surprisingly, the market in Java network programming texts is a much
...
LiveLab is a programming course assessment and management system. Students can .... B MySQL Tutorial. C Oracle Tutorial.
problem-driven complete revision new problems early console input hand trace box multidimensional arrays. Sudoku problem
source code files, solutions to exercises, or answers to quizzes, but it does have
external links to these ... 2.1 The Basic Java Application . ..... 5.5.2 Inheritance
and Class Hierarchy . ..... 10 Generic Programming and Collection Classes. 473.
... the author. The web site for this book is: http://math.hws.edu/javanotes ......
programming exercises at the end of each chapter, except for Chapter 1. For
each ...
This is a PDF version of a free on-line book that is available at http://math.hws.
edu/javanotes/. The PDF ... be used in Acrobat Reader and some other PDF
reader programs. Page 2. ii c 1996–2014, David J. Eck. David J. Eck (eck@hws.
edu).
Introduction to Programming in Java An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Princeton University O N L I N E P R E V I E W ...
This is a PDF version of an on-line book that is available at ... sa/2.5/ or send a
letter to Creative Commons, 543 Howard Street, 5th ... 1.1 Machine Language .
like perhaps a Mars rover, or a better cell phone, or... you name it, then you couldn't possibly do it ...... If it is not in your dock, you can find it under Ap- plications.
Java Network Programming. 1. Java Network Programming. Reader 1. Learning
Java Programming By Examples. Dr. Wanlei Zhou ...
It covers most, if not all, aspects of Java network programming facilities. First, the
lower level Java networking is overviewed which includes communication with ...
Introduction to Java Programming. 24. Practice Program 1. 8What sequence of
println statements will generate the following output? This program prints the first
...
Addison-Wesley. 75 ARLINGTON STREET, SUITE 300. BOSTON, MA 02116 rs@
cs.princeton.edu [email protected]. Dear Colleague,. Are all of the ...
dynamically allocated with the new keyword. ...... build a real threaded program
visit this. URL: http://www.mcs.drexel.edu/~bmitchel/course/mcs720/java.pdf ...
file name underneath an image brings up a window showing the Java source file
that .... Java 3D is an interactive 3D graphics Application Programming.
Department of Mathematics and Computer Science. Block IQ 1. Part I:
Fundamentals of programming. 1. Introduction to Java. 2. Primitive Data Types
and ...
Introduction. • Swing – A set of GUI classes. – Part of the Java's standard library.
– Much better than the previous library: AWT. • Abstract Window Toolkit.
Objective This course is intended to teach the basics of programming, the ...
Required Textbooks Java: Introduction to Problem Solving and Programming.
1.1.2 Finding the Example Java Programs on the Web site . . . . . . . . . . . . . . 11 ... 2
Your First Java Program. 17 ...... Schaums:OuTlines - Programming with Java.
PDF online, PDF new Introduction to Java Programming: Brief Version, 10th Edition, Online PDF Introduction to Java Progr
Network programming in Java in general much easier than in C... ▫ ...except
some advanced things which are harder ☹. ▫ Setting socket options, no select()-
call.
Introduction to Java Network Programming Jussi Kangasharju
Java Network Programming Network programming in Java in general much easier than in C... ...except some advanced things which are harder Setting But
socket options, no select()-call
threads help with missing select()
Java supports both TCP and UDP sockets Many different ways to read/write sockets Differentiates Often
between text and binary
several correct ways to handle socket
TIMTOWTDI:
There Is More Than One Way To Do It
Using TCP Sockets
Client side: Socket sock = new Socket(host, port);
String host = host to contact, int port = port Host can also be InetAddress instead of String Server side ServerSocket sock = new ServerSocket(port);
Listen for incoming connections Socket client = sock.accept();
Using UDP Sockets
Same for client and server DatagramSocket sock = new DatagramSocket();
For server, give port number as argument Send packets with send() Receive packets with receive() UDP packets implemented in DatagramPacket-class
Reading and Writing TCP Sockets Socket has InputStream and OutputStream Need to wrap other streams around them Some wrappers implement buffers Java has many different I/O Streams See
Java API for others (e.g., reading files)
Relevant for sockets: InputStreamReader, BufferedReader,
OutputStreamWriter
DataInputStream,
BufferedWriter DataOutputStream
Reading from a Socket
Typical code: InputStream is = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr);
Read text by calling br.readLine() Can be used only for reading text!
Writing to a Socket
Typical code OutputStream os = socket.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(os); BufferedWriter bw = new BufferedWriter(osw);
Write by calling one of many write()-functions See
the different classes for different possibilities Strings need to be converted to bytes with getBytes() Can also write directly to OutputStream
BufferedWriter only for text output!
DataInputStream
DataInputStream can read binary data from socket Also can send primitive data types Typical code InputStream is = socket.getInputStream(); DataInputStream dis = new DataInputStream(is);
Read binary data with read() (see API for details) Bonus functionality: Read text with readLine() But
DataInputStream.readLine() is deprecated
DataOutputStream
DataOutputStream can be used to write Typical code: OutputStream os = socket.getOutputStream(); DataOutputStream dos = new DataOutputStream(os);
DataOutputStream can also write text and binary Has
writeBytes()-function
no need for String.getBytes()
Differences Between Output Streams?!?
What is the difference between DataOutputStream and normal OutputStream wrapped with BufferedWriter?
Answer: There is no difference in practice Some subtleties: Possible
problems with conversion between 8-bit and 16-bit characters (e.g., DataInputStream.readLine())
Possible
text/binary data issues
Possible
problems with buffering (use flush())
dos.writeBytes(str)
vs. bw.write(str.getBytes())
No “correct” way, use either as long as it works Be
careful not to get confused!
Assignment Java Network Programming
Assignment Details
1. TCP client and server 2. Simple Web server 3. Web server improvements (+ optionals) http://www.cs.helsinki.fi/u/jakangas/Teaching/CBU/lab1.html