how to get hostname from ip address in java?

The java.net.InetAddress class represents an IP address. It provides the methods to work with IP and host name. Get hostname from ip address in java package com.w3schools; import java.net.InetAddress; public class NetworkTest { public static void main(String args[]){ try { InetAddress host = InetAddress.getByName(“107.180.2.128”); System.out.println(host.getHostName()); } catch(Exception e) { e.printStackTrace(); } } } Output ip-107-180-2-128.ip.secureserver.net … Read more

Shallow copy and deep copy in java

Before discussing differences between shallow copy and deep copy let’s discuss what a copy is? We can have two types of copies: Reference copy: It creates a copy of a reference variable pointing to an object. Object copy: It creates a copy of the object itself. Shallow copy Shallow means having little depth. Shallow copy … Read more

java array interview programs

Java arrays are group of homogeneous elements. Homogeneous means – of the same kind i.e. Java arrays contains the elements of same type. Syntax datatype[] array_name; or datatype array_name[]; List of java array interview programs Java program to find duplicate elements in an array. Java program to find second largest element in an array of … Read more

Java interview programs

Java interview questions programs on Basics, OOPs, Methods, Overloading, Overriding, Inheritance, Polymorphism, Interfaces, Packages, Abstract classes, String handling, Exception handling, IO, Collections, Multithreading, Serialization and more. List of java interview programs Program to print alphabets in java. Java Arithmetic Operators Example. Armstrong number program in java. Even odd program in java. Factorial program in java … Read more