Skip to content
Related Articles

Related Articles Class in Java

View Discussion
Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 16 Nov, 2021
View Discussion
Improve Article
Save Article

ProtocolFamily is a java Interface. The represents a family of communication protocols. implements ProtocolFamily Interface.

public interface ProtocolFamily 

Methods of interface contains only one method:

S.No.         Method                                          Description                                                                    Return Type                                      
1. name() name() method returns the name of the protocol family String

Use of ProtocolFamily Interface

S.No. Package       Modifier and Type Name                                                                                               Description
1. class StandardProtocolFamily StandardProtocolFamily class defines the standard families of communication protocols.
2. java.nio.channels static DatagramChannel family) static method opens a datagram channel.
3. java.nio.channels.spi abstract DatagramChannel SelectorProvider.openDatagramChannel( ProtocolFamily family) SelectorProvider.openDatagramChannel Opens a datagram channel.

Java Program for Better Understanding of the ProtocolFamily Interface


// Java Program to get Protocol
// family for an IP Address
// import Guava library
class GFG {
    public static void main(String[] args)
        try {
            // to get the ip address of
            InetAddress ip
                = InetAddress.getByName("");
            System.out.println("Host Name is "
                               + ip.getHostName());
            // getProtocolFamily() will check and return the
            // protocol family of the given IP
            ProtocolFamily protocolFamily
                = getProtocolFamily(ip);
            System.out.println("Protocol family of the "
                               + ip.getHostName() + " is "
                               + protocolFamily);
        catch (Exception e) {
            System.out.println("Some exception"
                               + e.getMessage());
    public static ProtocolFamily
    getProtocolFamily(InetAddress inetAddress)
        // to check if address is valid or not
        if (InetAddresses.isInetAddress(
                inetAddress.getHostName())) {
            // if address is valid
            // will return the protocol family of the
            // address
            return StandardProtocolFamily.INET;
        else {
            // address is not valid
                "Address " + inetAddress
                + "is invalid hence can't determine the protocol family");
        return StandardProtocolFamily.INET;


Host Name is
Protocol family of the is INET

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!