INTRO To Advance Java
INTRO To Advance Java
JAVA
Platform
Reference Book:
1. Complete Reference J2EE by James Keogh mcgraw publication
2. Black Book “ Java server programming” J2EE, 1st ed., Dream Tech Publishers, 2008.
Kathy walrath ”
3. Professional Java Server Programming by Subrahmanyam Allamaraju, Cedric Buest
Wiley Publication
https://www.computernetworkingnotes.com/ccna-study-guide/similarities-and-differences-between-osi-and-tcp-ip-model.html
https://www.researchgate.net/figure/The-logical-mapping-between-OSI-basic-reference-model-and-the-TCP-IP-stack_fig2_327483011
InetAddress
import java.net.*
URL
URLConnection
ServerSocket
TCP
Socket
DatagramPacket
UDP DatagramSocket
Server Client
Response
socket socket
Request
Waits
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Reference: isinotes/javatut/net
Server
Client 1
Reference: isinotes/javatut/net
Example
InetAddress ip
=InetAddress.getByName("www.ldce.ac.in");
System.out.println(“ip:“+ ip);
Output:
ip: www.ldce.ac.in/166.62.10.189
Example
InetAddress ip
=InetAddress.getByName("www.ldce.ac.in");
System.out.println(“ip:“+ ip);
Output:
ip: www.ldce.ac.in/166.62.10.189
Example
InetAddress ip=InetAddress.getLocalHost();
System.out.println(“LocalHost:“+ip);
Output:
LocalHost:Pragnesh-PC/192.168.20.18
Example
InetAddress ip=InetAddress.getByName(“www.ldce.ac.in");
System.out.println(“Hostname:”+ip.getHostName());
Output:
Hostname:www.ldce.ac.in
Example
InetAddress ip=InetAddress.getByName("www.ldce.ac.in");
System.out.println(“HostAddress:”+ip.getHostAddress());
Output:
HostAddress:166.62.10.189
System.out.println("IP : "+ip);
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
System.out.println("Hostname:"+ip.getHostName());
System.out.println("HostAddress: "+ip.getHostAddress());
InetAddress ip1=InetAddress.getLocalHost();
System.out.println("LocalHost: "+ip1);
}catch(Exception e){System.out.println(e);}
}
}
Unit-1 JAVA NETWORKING 30
InetAddress: Program
Output:
IP : www.ldce.ac.in/166.62.10.189
Host Name: www.ldce.ac.in
IP Address: 166.62.10.189
Hostname:www.ldce.ac.in
HostAddress: 166.62.10.189
LocalHost: Pragnesh-PC/192.168.20.18
InetAddress
URL
URLConnection This class implements Server sockets
ServerSocket
TCP
Socket This class implements Client sockets.
DatagramPacket
DatagramSocket
MulticastSocket
Constructor
ServerSocket(int port) Creates a server socket, bound to the specified
port.
Method
Example
ServerSocket ss=new ServerSocket(1111);
socket
Example
Socket s;
s=new Socket("localhost",1111);
Output
message= Hello Server
InetAddress
URL
URLConnection
ServerSocket This class represents a
datagram packet.
Socket
DatagramPacket
Represents a socket for
UDP DatagramSocket sending and receiving
datagram packets.
Constructor
DatagramPacket(byte[] barr, int length) It creates a datagram packet. This
constructor is used to receive the packets.
DatagramPacket(byte[] barr, int length, It creates a datagram packet. This
InetAddress address, int port) constructor is used to send the packets.
import java.net.*;
public class DReceiver{
public static void main(String[] args) throws Exception
{
DatagramSocket ds = new DatagramSocket(3000);
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, 1024);
ds.receive(dp);
String str = new String(dp.getData(), 0,dp.getLength());
System.out.println(str);
ds.close();
}
}
Output
Message sent by Datagram socket
ds.send(dp); System.out.println(str);
ds.close(); ds.close();
}
} }
}
Output
Message sent by Datagram socket
Example
URL url=new URL("http://www.ldce.ac.in");
Method
public URLConnection openConnection() This method of URL class returns the
throws IOException object of URLConnection class
Example
URLConnection urlcon=url.openConnection();
public InputStream getInputStream() Returns an input stream that reads from this
throws IOException open connection.
public OutputStream getOutputStream()
openConnection()
Returns an output stream that writes to this
connect()
throws IOException connection.
Manipulate parameters that affect the Interact with the resource; query header fields
connection to the remote resource. and contents.
Web Reference
• https://docs.oracle.com/javase/7/docs/api/
• https://www.tutorialspoint.com