Java Developers
Group for Java developers and programmers. Ask questions and get answers related to Java programming
270 Members
Join this group to post and comment.
Archana Priyadarshini
Archana Priyadarshini
Computer Science
08 Feb 2019

Networking in java

Java supports networking. Java Networking is a concept of connecting two or more computing devices together so that we can share resources.

There are two types of classes in Java to support networking i.e. low-level and high-level. These classes control the network applications programming. As Java is platform independent in nature, Java networking is also platform independent.

The classes to support Java networking are –

Low-level – These classes support socket programming like DataramSocket, Socket, and ServerSocket classes.

High-level – These classes provide support for URLEncoder, web programming URL, and URL connection.

AdhikariHarika Reshma
AdhikariHarika Reshma
Computer Science
3mos ago

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.

Advantages of Java Networking:

1.Sharing resources.

2.Centralize software management.

Java  Networking terminology:The widely used java networking terminologies are:

1.Ip Address:It is a unique number assigned to a node if a network e.g. 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 portocol:In connection-oriented protocol, acknowledgment is sent by the reciever.So it is reliable but slow.The example of connection-oriented protocol is TCP.

But in connection-less protocol acknowledgment 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.

Vijay Khatri
Vijay Khatri
Computer Science
3mos ago

Java has a reasonably easy-to-use builtin networking API which makes it easy to communicate via TCP/IP sockets or UDP sockets over the internet. 

Even though the Java Networking APIs enable you to open and close network connections via sockets, all communication happens via the Java IO classes InputStream and OutputStream.

Alternatively, you can use the networking classes in the Java NIO API. These classes are similar to the classes found in the Java Networking API, except the Java NIO API can work in non-blocking mode. The non-blocking mode may give a performance boost in some situations.

Java TCP Networking Basics

Typically a client opens a TCP/IP connection to a server. The client then starts to communicate with the server. When the client is finished it closes the connection again. Here is an illustration of that:

A client may send more than one request through an open connection. In fact, a client can send as much data as the server is ready to receive. The server can also close the connection if it wants to.

Java Socket's and ServerSocket's

When a client wants to open a TCP/IP connection to a server, it does so use a Java Socket.    The socket is told what IP address and TCP port to connect to and the rest is done by Java.

If you want to start a server that listens for incoming connections from clients on some TCP port,    you have to use a Java ServerSocket. When a client connects via a client socket to a server's    ServerSocket, a Socket is assigned on the server to that connection. The client and server now communicate Socket-to-Socket.

Socket's and ServerSocket's are covered in more detail in later texts.

Java UDP Networking Basics

UDP works a bit differently from TCP. Using UDP there is no connection between the client and the server. A client may send data to the server, and the server may (or may not) receive this data. The client will never know if the data was received at the other end. The same is true for the data sent the other way from the server to the client.

Because there is no guarantee of data delivery, the UDP protocol has less protocol overhead.

There are several situations in which the connectionless UDP model is preferable over TCP. These are covered in more detail in the text on Java's UDP datagram sockets.

3mos ago

@Vijay Khatri - It'd have been better if instead of copying all the content from other websites, you had taken some time to write on your own. 

Vijay Khatri
Vijay Khatri
Computer Science
3mos ago

@Kaustubh Katdare: I am not copying all time only when I think it is useful or required for the user or your audience, You can check my all the post, As I think you are the owner of this website, Tried a lot of time real time of example or real experience,Check Digital Marketing Forums, As I think you also like my some of the posts. Every time I want to deliver a really good content my audience, If I am copying a complete article or post then it means it is really useful for them. Most of the time I faced a problem while posting a link.

Kaustubh Katdare | CrazyEngineers