Connecting two or more computing devices so that we can share resources is the idea behind Java networking.
The Java socket programming language offers the ability to transfer data among many computing systems.
The application layer is where all network communications for Java programs take place. The J2SE APIs’ java.net package contains a number of classes and interfaces that execute the low-level communication features, allowing the user to create programs that are specifically focused on fixing the issue.
Inet Address contains both the domain name and the IP address in one package. Both IPv4 and IPv6 addresses are supported by Inet addresses. Inet Address class has no visible Constructor. It is necessary to use Factory methods in order to generate an inet Address object.
There are three popular Inet Address factory methods.
import java.net.*;
class Coderz
{
public static void main(String[] args) throws UnknownHostException
{
InetAddress address = InetAddress.getLocalHost();
System.out.println(address);
address = InetAddress.getByName("www.coderzpy.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]);
}
}
}
compiler-deployment-7cf697c54b-kd2bj/10.8.0.19
www.coderzpy.com/46.17.172.15
www.google.com/173.194.74.99
www.google.com/173.194.74.104
www.google.com/173.194.74.147
www.google.com/173.194.74.106
www.google.com/173.194.74.103
www.google.com/173.194.74.105
Modern networking is built on sockets, which enable a single computer to serve multiple clients simultaneously. A port, which is a numbered socket on a specific system, is how a socket creates a connection. A protocol underlies socket communication. TCP-based sockets offer a means of communication between two machines. TCP sockets come in two varieties in Java. Both are for clients and servers, respectively.
The Java URL Class in the java.net package deals with URLs (Uniform Resource Locators), which are used to locate or identify resources on the internet uniquely.
import java.net.*;
class Coderz
{
public static void main(String[] arg) throws MalformedURLException
{
URL hp = new URL("https://coderzpy.com/category/c/");
System.out.println(hp.getProtocol());
System.out.println(hp.getFile());
}
}
https
/category/c/
Note: also read about the Serialization and Deserialization in Java
If you like my post, please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…