Online Java Compiler By
JavaTpoint.com
import java.net.URL; import java.util.Scanner; public class URLgetHostExample1{ public static void main(String args[])throws Exception { //passing url in constructor URL url1=new URL("https://www.javatpoint.com/java-threadpoolexecutor"); // Fetching Host name from given url System.out.println("The given url is : "+url1); System.out.println("Host name in given url is : "+url1.getHost()); } }
Output