Free Data Structures and Algorithms Course

Subscribe below and get all best seller courses for free !!!


Subscribe to all free courses

How to use Class for Java Networking ?.

Program to demonstrate working of URL class and the methods of the URL class for Java Networking

package com.hubberspot.networking.example;


public class URLExample
  public static void main(String args[]) 
    throws MalformedURLException

    URL url = new URL ("" +

    System.out.println("Protocol is:" + url.getProtocol()); 
    System.out.println("Port is:" + url.getPort()); 
    System.out.println("Host is:" + url.getHost()); 
    System.out.println("File is:" + url.getFile()); 

Output of the program :

© 2021 Learn Java by Examples Template by Hubberspot