The Java platform is extremely preferable to write an application program require to communicate with the resources on network. Java, mainly focuses on the networking relating the description of the networking capabilities of the Java platform and second one is describes a brief summary of networking in a very simple manner that how to use URLs, sockets, and datagrams.
In Java, there is a java.net package provides the network support. All the classes for making a network program are define in the java.net package. Through TCP we can communicate over the network.
Getting Hands-on Java Networking example
Find Your Host Name/IP Address
In this section you will learn about the getLocalHost() method to print the Host name as well as the IP Address of the local system. For do for the same we have to call InetAddress class then we need to create a object, in which we store the local host information.
Find Your Host Name
Here we are going to explore a method to retrieve the host name of the local system in a very simple example. Here we are just call the InetAddress class and after made a object of that class we call a getLocalHost() method and pass it in the object.
Getting list of Local Interfaces on a machine
Here we are going to explain the method to find out the total no of list of local interfaces available on a machine. Here we are give a complete example named URLDemo.java.
Getting the Local port
In this section you will learn that how a user can access the Local port. Here we are going to make it easier to understand the step be step process by the complete example on this topic.
Find the Host name in reverse of given IP address
In this section you will learn to retrieve the information about the local host name using the getHostName() method. Here is an example that provides the usage of the getHostName() method in more detail.
How to retrieve URL information
Here we are going to explain a method for retrieve all the network information for a given URL. In the given below example we use the URL class and make a object.
Convert URI to URL
Here we are going to explain the method to change Uniform Resource Identifier (URI) reference to uniform resource locator (URL). Here we are give a complete example named "ConvertURItoURL.java".
To retrieve the IP address from Host Name, vice-versa
Here we are going to explain the method to find out the IP address from host name and to vice verse. Here we are give a complete example named HostLookup.java. In which we call a InetAddress and make a object and pass the input value in it.
Construct a DatagramPacket to receive data
In this section we provide a complete code of a example based on the method DatagramPacket(buffer, buffer.length) for constructs a DatagramPacket for receiving packets of length length in more generic way.
Construct a DatagramSocket on an unspecified port
In this section we are going to explain the process to construct a DatagramPacket object in more generic way. Here we provide a complete example based on the method for creating the DatagramSocket object via DatagramSocket().
Return the MIME Header
In this section you will learn about the method to retrieve the MIME header. MIME is stands for Multipurpose Internet Mail Extensions which is an Internet Standard that extends the format of e-mail to support. A container for MimeHeader objects, which represent the MIME headers that is present in a MIME part of data.
Open a URLConnection to specific website address
Here we are going to establish a connection to a specific web address via a complete example. In the example we create a class getURLConnection and initialize a variable of url to URL and ucon of URLConnection.
Print the URL of a URLConnection
In this section we are going to describe, how to retrieve the value of the URL assign to the url object. Here is the complete code of the program in which first of all we establish a connection then display it.
Getting Image from a URL
This example shows how to get an image from the given URL.
Here we are going to explain the method to find out the URL information. This program defines the IOException for the exception handling. This exception is thrown to indicate an I/O problem.
In this section, you will learn how to get content-length, content- type, and last-modify date of a file. Here we provide a complete example that uses getHeaderFieldKey() method.
This is a simple program of java network and supports the java.net package. Here, we have defined the class named EncoderTest.java. This class contains static methods for converting a String to the application-urlencoded MIME format.
In this section, we are going to explain the method to find out the hostname port number of a local machine. This program defines the IOException for the exception handling.
Client Socket Information
In this section, you will learn how to get client socket information. This is a very simple program of java network. Here, we have used the class named ClientSocketInformation.java that implement the constructor of the Socket class passing two arguments as hostName and TIME_PORT.
In this section, you will show the used of several method for different output massage. Here, we provide a complete example based on the method for creating the Socket() method.
Here, we are going to explore a method to retrieve the IPAddress of the local system in a very simple example. For do for the same we have to call InetAddress class then we need to create a object, in which we store the local host information.
Local Port Scanner
This is a simple program of java network. Here, we are going to define class named "LocalPortScanner" in which we use ServerSocket class of java.net package which takes local port number as argument.
Low port Scanner
In this section, you will learn how to get local port number of the local machine. Here, we define the name of program LowPortScanner. In this we check the argument and create a socket object.
URL Connection Reader
In this section, you will learn about the url connection reader. Here, first of all we are going to define class named "URLConnectionReader". After that we make a URL object passing a url "http://www.javajazzup.com" as string in its constructor.
This is a simple program of java network. In this section, you will learn how to read HTML file. Here, we create a URL object and pass a url. After that, we call the URL?s openStream() method to get a stream from which the contents of the URL can be read.
RMI Client And RMI Server Implementation
The RMI application comprises of the two separate programs, a server and a client. A typical server program creates some remote objects, makes references to these objects accessible, and waits for clients to invoke methods on these objects.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.