SlideShare a Scribd company logo
2
Most read
4
Most read
13
Most read
Java Networking
Java Networking
 Java Networking is a concept of connecting two
or more computing devices together so that we
can share resources.
 Java socket programming provides facility to
share data between different computing devices.
Advantage of Java Networking
 sharing resources
 centralize software management
Java Networking Terminology
The widely used java networking terminologies are given below:
 IP Address
 Protocol
 Port Number
 MAC Address
 Connection-oriented and connection-less protocol
 Socket
1) IP Address
IP address is a unique number assigned to a node of a network
e.g. 192.168.0.1 . It is composed of octets that range from 0 to
255.
It is a logical address that can be changed.
2) Protocol
A protocol is a set of rules basically that is followed for
communication. For example:
TCP
FTP
Telnet
SMTP
POP etc.
3) Port Number
The port number is used to uniquely identify different
applications. It acts as a communication endpoint between
applications.
The port number is associated with the IP address for
communication between two applications.
4) MAC Address
MAC (Media Access Control) Address is a unique identifier
of NIC (Network Interface Controller). A network node
can have multiple NIC but each with unique MAC.
5) Connection-oriented and connection-less protocol
In connection-oriented protocol, acknowledgement is sent
by the receiver. So it is reliable but slow. The example of
connection-oriented protocol is TCP.
But, in connection-less protocol, acknowledgement is not
sent by the receiver. So it is not reliable but fast. The
example of connection-less protocol is UDP.
6) Socket
A socket is an endpoint between two way communication.
Visit next page for java socket programming.
import java.net.*;
class Demo
{
public static void main(String[] args) throws
UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
address = InetAddress.getByName("www.facebook.com");
System.out.println(address);
InetAddress sw[] =
InetAddress.getAllByName("www.google.com");
for(int i=0; i< sw.length; i++)
{
System.out.println(sw[i]);
} } }
URL class
 Java URL Class present in java.net package,
deals with URL (Uniform Resource Locator)
which uniquely identify or locate resources on
internet.
Important Methods of URL class
 getProtocol() : Returns protocol of URL
 getHost() : Returns hostname(domain name) of
URL
 getPort() : Returns port number of URL
 getFile() : Returns filename of URL
import java.net.*;
class Demo
{
public static void main(String[] arg) throws
MalformedURLException
{
URL hp = new URL("http://www.kongu.ac.in/");
System.out.println(hp.getProtocol());
System.out.println(hp.getFile());
}
}
Socket class
 A socket is simply an endpoint for
communications between the machines. The
Socket class can be used to create a socket.
1) public InputStream getInputStream()returns the
InputStream attached with this socket.
2) public OutputStream getOutputStream()returns
the OutputStream attached with this socket.
3) public synchronized void close()closes this
socket
ServerSocket class
The ServerSocket class can be used to create a
server socket. This object is used to establish
communication with the clients.
 public Socket accept()returns the socket and
establish a connection between server and client.
 public synchronized void close()closes the server
socket.
URLConnection
 The Java URLConnection class represents a
communication link between the URL and the
application. This class can be used to read and
write data to the specified resource referred by
the URL.
The openConnection() method of URL class returns
the object of URLConnection class. Syntax:
public URLConnection openConnection()throws
IOException{}
DatagramSocket
 Java DatagramSocket class represents a
connection-less socket for sending and receiving
datagram packets.
 A datagram is basically an information but there is
no guarantee of its content, arrival or arrival time.
Constructors of DatagramSocket
class
 DatagramSocket() throws SocketEeption: it
creates a datagram socket and binds it with the
available Port Number on the localhost machine.
 DatagramSocket(int port) throws
SocketEeption: it creates a datagram socket and
binds it with the given Port Number.
 DatagramSocket(int port, InetAddress
address) throws SocketEeption: it creates a
datagram socket and binds it with the specified
port number and host address.
DatagramPacket
Java DatagramPacket is a message that can be
sent or received. If you send multiple packet, it
may arrive in any order. Additionally, packet
delivery is not guaranteed.
Constructors of DatagramPacket class
 DatagramPacket(byte[] barr, int length): it
creates a datagram packet. This constructor is
used to receive the packets.
 DatagramPacket(byte[] barr, int length,
InetAddress address, int port): it creates a
datagram packet. This constructor is used to send
the packets.
Java.net.URI class in Java
URI stands for Uniform Resource Identifier.
• A Uniform Resource Identifier is a sequence of
characters used for identification of a particular
resource.
• It enables for the interaction of the representation
of the resource over the network using specific
protocols.
URI, URL and URN
 A URI can be further classified as a locator, a
name, or both.
 The term “Uniform Resource Locator” (URL)
refers to the subset of URI that identify resources
via a representation of their primary access
mechanism (e.g., their network “location”), rather
than identifying the resource by name or by some
other attribute(s) of that resource.
 The term “Uniform Resource Name” (URN) refers
to the subset of URI that are required to remain
globally unique and persistent even when the
resource ceases to exist or becomes
unavailable.”

More Related Content

What's hot (20)

PDF
Java Programming - 07 java networking
Danairat Thanabodithammachari
 
PPT
Java Networking
Sunil OS
 
PPTX
Socket programming in Java (PPTX)
UC San Diego
 
PPTX
Chapter 4
Ebisa Bekele
 
PPT
java networking
Waheed Warraich
 
PDF
What is Socket Programming in Python | Edureka
Edureka!
 
PPT
Networking in java
shravan kumar upadhayay
 
PPTX
Networking in python by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
PDF
Java networking programs - theory
Mukesh Tekwani
 
PDF
Python network programming
Learnbay Datascience
 
PPT
Java Socket Programming
Vipin Yadav
 
PPTX
Networking in Java
Tushar B Kute
 
PDF
Module 1 networking basics-2
Ankit Dubey
 
PDF
Socket programming-in-python
Yuvaraja Ravi
 
PPTX
Python Sockets
pythontic
 
PDF
Socket programming
NemiRathore
 
PPT
A Short Java Socket Tutorial
Guo Albert
 
PDF
Chapter 2.1 : Data Stream
Ministry of Higher Education
 
PPTX
Networking
Jafar Nesargi
 
Java Programming - 07 java networking
Danairat Thanabodithammachari
 
Java Networking
Sunil OS
 
Socket programming in Java (PPTX)
UC San Diego
 
Chapter 4
Ebisa Bekele
 
java networking
Waheed Warraich
 
What is Socket Programming in Python | Edureka
Edureka!
 
Networking in java
shravan kumar upadhayay
 
Java networking programs - theory
Mukesh Tekwani
 
Python network programming
Learnbay Datascience
 
Java Socket Programming
Vipin Yadav
 
Networking in Java
Tushar B Kute
 
Module 1 networking basics-2
Ankit Dubey
 
Socket programming-in-python
Yuvaraja Ravi
 
Python Sockets
pythontic
 
Socket programming
NemiRathore
 
A Short Java Socket Tutorial
Guo Albert
 
Chapter 2.1 : Data Stream
Ministry of Higher Education
 
Networking
Jafar Nesargi
 

Similar to Java networking (20)

PPTX
Java seminar.pptx
shirindigitel
 
PPTX
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
KuntalVasoya
 
PDF
28 networking
Ravindra Rathore
 
PPT
Md13 networking
Rakesh Madugula
 
PPTX
Java
kasthurimukila
 
PPTX
Java
Subha Selvam
 
DOCX
Unit8 java
mrecedu
 
PPTX
CHAPTER - 3 - JAVA NETWORKING.pptx
DhrumilSheth3
 
PPTX
A.java
JahnaviBhagat
 
PPTX
Network programming in java - PPT
kamal kotecha
 
PPTX
Unit-6-java basic for java programing.pptx
086ChintanPatel1
 
PPTX
5_6278455688045789623.pptx
EliasPetros
 
PDF
Networking Basics1ofjavaprogramming.pptx.pdf
omkarthombare4989
 
PPT
Network programming in Java
Tushar B Kute
 
PPT
Network Programming in Java
Tushar B Kute
 
PPT
Basic Networking in Java
suraj pandey
 
PDF
Unit 6 - Netwohhhhhddddrking in Java.pdf
kassyemariyam21
 
DOC
Socket
Amandeep Kaur
 
PPTX
3160707_AJava_GTU_Study_Material_Presentations_Unit-1_16032021121225PM.pptx
vasishtharishi07
 
PPT
Networking & Socket Programming In Java
Ankur Agrawal
 
Java seminar.pptx
shirindigitel
 
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
KuntalVasoya
 
28 networking
Ravindra Rathore
 
Md13 networking
Rakesh Madugula
 
Unit8 java
mrecedu
 
CHAPTER - 3 - JAVA NETWORKING.pptx
DhrumilSheth3
 
Network programming in java - PPT
kamal kotecha
 
Unit-6-java basic for java programing.pptx
086ChintanPatel1
 
5_6278455688045789623.pptx
EliasPetros
 
Networking Basics1ofjavaprogramming.pptx.pdf
omkarthombare4989
 
Network programming in Java
Tushar B Kute
 
Network Programming in Java
Tushar B Kute
 
Basic Networking in Java
suraj pandey
 
Unit 6 - Netwohhhhhddddrking in Java.pdf
kassyemariyam21
 
3160707_AJava_GTU_Study_Material_Presentations_Unit-1_16032021121225PM.pptx
vasishtharishi07
 
Networking & Socket Programming In Java
Ankur Agrawal
 
Ad

More from ssuser3a47cb (10)

PPTX
BCT.pptx
ssuser3a47cb
 
PPTX
Uunit 5-xml&web security
ssuser3a47cb
 
PPTX
Unit 4-SOA governance
ssuser3a47cb
 
PPTX
Unit 3-SOA Technologies
ssuser3a47cb
 
PPTX
Unit 2 -SOA design
ssuser3a47cb
 
PPTX
Soa 1 7.ppsx
ssuser3a47cb
 
PPTX
Java swing
ssuser3a47cb
 
PPTX
I/O port programming in 8051
ssuser3a47cb
 
PPTX
Interfacing external memory in 8051
ssuser3a47cb
 
PPTX
Interrupt in 8051
ssuser3a47cb
 
BCT.pptx
ssuser3a47cb
 
Uunit 5-xml&web security
ssuser3a47cb
 
Unit 4-SOA governance
ssuser3a47cb
 
Unit 3-SOA Technologies
ssuser3a47cb
 
Unit 2 -SOA design
ssuser3a47cb
 
Soa 1 7.ppsx
ssuser3a47cb
 
Java swing
ssuser3a47cb
 
I/O port programming in 8051
ssuser3a47cb
 
Interfacing external memory in 8051
ssuser3a47cb
 
Interrupt in 8051
ssuser3a47cb
 
Ad

Recently uploaded (20)

PPTX
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PDF
Design Thinking basics for Engineers.pdf
CMR University
 
PPTX
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
PPTX
Day2 B2 Best.pptx
helenjenefa1
 
PDF
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
PPTX
Thermal runway and thermal stability.pptx
godow93766
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Damage of stability of a ship and how its change .pptx
ehamadulhaque
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Design Thinking basics for Engineers.pdf
CMR University
 
原版一样(Acadia毕业证书)加拿大阿卡迪亚大学毕业证办理方法
Taqyea
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
VITEEE 2026 Exam Details , Important Dates
SonaliSingh127098
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
GitOps_Repo_Structure for begeinner(Scaffolindg)
DanialHabibi2
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Worm gear strength and wear calculation as per standard VB Bhandari Databook.
shahveer210504
 
Day2 B2 Best.pptx
helenjenefa1
 
Unified_Cloud_Comm_Presentation anil singh ppt
anilsingh298751
 
Thermal runway and thermal stability.pptx
godow93766
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Set Relation Function Practice session 24.05.2025.pdf
DrStephenStrange4
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 

Java networking

  • 2. Java Networking  Java Networking is a concept of connecting two or more computing devices together so that we can share resources.  Java socket programming provides facility to share data between different computing devices.
  • 3. Advantage of Java Networking  sharing resources  centralize software management Java Networking Terminology The widely used java networking terminologies are given below:  IP Address  Protocol  Port Number  MAC Address  Connection-oriented and connection-less protocol  Socket
  • 4. 1) IP Address IP address is a unique number assigned to a node of a network e.g. 192.168.0.1 . It is composed of octets that range from 0 to 255. It is a logical address that can be changed. 2) Protocol A protocol is a set of rules basically that is followed for communication. For example: TCP FTP Telnet SMTP POP etc. 3) Port Number The port number is used to uniquely identify different applications. It acts as a communication endpoint between applications. The port number is associated with the IP address for communication between two applications.
  • 5. 4) MAC Address MAC (Media Access Control) Address is a unique identifier of NIC (Network Interface Controller). A network node can have multiple NIC but each with unique MAC. 5) Connection-oriented and connection-less protocol In connection-oriented protocol, acknowledgement is sent by the receiver. So it is reliable but slow. The example of connection-oriented protocol is TCP. But, in connection-less protocol, acknowledgement is not sent by the receiver. So it is not reliable but fast. The example of connection-less protocol is UDP. 6) Socket A socket is an endpoint between two way communication. Visit next page for java socket programming.
  • 6. import java.net.*; class Demo { public static void main(String[] args) throws UnknownHostException { InetAddress address = InetAddress.getLocalHost(); System.out.println(address); address = InetAddress.getByName("www.facebook.com"); System.out.println(address); InetAddress sw[] = InetAddress.getAllByName("www.google.com"); for(int i=0; i< sw.length; i++) { System.out.println(sw[i]); } } }
  • 7. URL class  Java URL Class present in java.net package, deals with URL (Uniform Resource Locator) which uniquely identify or locate resources on internet. Important Methods of URL class  getProtocol() : Returns protocol of URL  getHost() : Returns hostname(domain name) of URL  getPort() : Returns port number of URL  getFile() : Returns filename of URL
  • 8. import java.net.*; class Demo { public static void main(String[] arg) throws MalformedURLException { URL hp = new URL("http://www.kongu.ac.in/"); System.out.println(hp.getProtocol()); System.out.println(hp.getFile()); } }
  • 9. Socket class  A socket is simply an endpoint for communications between the machines. The Socket class can be used to create a socket. 1) public InputStream getInputStream()returns the InputStream attached with this socket. 2) public OutputStream getOutputStream()returns the OutputStream attached with this socket. 3) public synchronized void close()closes this socket
  • 10. ServerSocket class The ServerSocket class can be used to create a server socket. This object is used to establish communication with the clients.  public Socket accept()returns the socket and establish a connection between server and client.  public synchronized void close()closes the server socket.
  • 11. URLConnection  The Java URLConnection class represents a communication link between the URL and the application. This class can be used to read and write data to the specified resource referred by the URL. The openConnection() method of URL class returns the object of URLConnection class. Syntax: public URLConnection openConnection()throws IOException{}
  • 12. DatagramSocket  Java DatagramSocket class represents a connection-less socket for sending and receiving datagram packets.  A datagram is basically an information but there is no guarantee of its content, arrival or arrival time.
  • 13. Constructors of DatagramSocket class  DatagramSocket() throws SocketEeption: it creates a datagram socket and binds it with the available Port Number on the localhost machine.  DatagramSocket(int port) throws SocketEeption: it creates a datagram socket and binds it with the given Port Number.  DatagramSocket(int port, InetAddress address) throws SocketEeption: it creates a datagram socket and binds it with the specified port number and host address.
  • 14. DatagramPacket Java DatagramPacket is a message that can be sent or received. If you send multiple packet, it may arrive in any order. Additionally, packet delivery is not guaranteed. Constructors of DatagramPacket class  DatagramPacket(byte[] barr, int length): it creates a datagram packet. This constructor is used to receive the packets.  DatagramPacket(byte[] barr, int length, InetAddress address, int port): it creates a datagram packet. This constructor is used to send the packets.
  • 15. Java.net.URI class in Java URI stands for Uniform Resource Identifier. • A Uniform Resource Identifier is a sequence of characters used for identification of a particular resource. • It enables for the interaction of the representation of the resource over the network using specific protocols.
  • 16. URI, URL and URN  A URI can be further classified as a locator, a name, or both.  The term “Uniform Resource Locator” (URL) refers to the subset of URI that identify resources via a representation of their primary access mechanism (e.g., their network “location”), rather than identifying the resource by name or by some other attribute(s) of that resource.  The term “Uniform Resource Name” (URN) refers to the subset of URI that are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable.”