URL url = new URL("https://www.example.com"); String protocol = url.getProtocol(); System.out.println(protocol); // Output: https
String urlString = "ftp://ftp.example.com"; URL url = new URL(urlString); String protocol = url.getProtocol(); System.out.println(protocol); // Output: ftpThis example creates a URL object for an FTP server and retrieves the protocol (FTP) using the getProtocol() method. These examples use the java.net package library.