BindException in Java

java.net.BindException

Signals that an error occurred while attempting to bind a socket to a local address and port. Typically, the port is in use, or the requested local address could not be assigned.

Declaration

public class BindException extends SocketException {
    @java.io.Serial
    private static final long serialVersionUID =
-5945005768251722951L;

    public BindException(String msg) {
        super(msg);
    }

    public BindException() {
    }
}


Methods

1. BindException()

java.net.BindException.BindException()

This method constructs a new BindException with no detailed message.

Approach

Java

package com.BindException;

import java.net.BindException;

public class BindException1 {
    public static void main(String[] args) {
        BindException bindException = new BindException();

        System.out.println(bindException);
    }
}

Output:

java.net.BindException


2. BindException(String msg)

java.net.BindException.BindException(String msg)

Constructs a new BindException with the specified detailed message as to why the bind error occurred. A detail message is a String that gives a specific description of this error.

Parameters: msg the detailed message

Approach

Java

package com.BindException;

import java.net.BindException;

public class BindException2 {
    public static void main(String[] args) {
        String msg = "message";
        BindException bindException = new BindException(msg);

        System.out.println(bindException);
    }
}

Output:

java.net.BindException: message


Some other classes/interfaces of java.net

AuthenticatorThe class Authenticator represents an object that knows how to obtain authentication for a network connection.

BindExceptionSignals that an error occurred while attempting to bind a socket to a local address and port. 

CacheRequestRepresents channels for storing resources in the ResponseCache.

CacheResponseRepresent channels for retrieving resources from the ResponseCache.

ConnectExceptionSignals that an error occurred while attempting to connect a socket to a remote address and port.

ContentHandlerThe abstract class ContentHandler is the superclass of all classes that read an Object from a URLConnection.

ContentHandlerFactoryThis interface defines a factory for content handlers. Implementing this interface should map a MIME type into an instance of ContentHandler.

CookieHandlerA CookieHandler object provides a callback mechanism to hook up an HTTP state management policy implementation into the HTTP protocol handler.

CookieManagerCookieManager provides a concrete implementation of CookieHandler, which separates the storage of cookies from the policy surrounding accepting and rejecting cookies. 

CookiePolicyCookiePolicy implementations decide which cookies should be accepted and which should be rejected.

CookieStoreA CookieStore object represents storage for cookies. Can store and retrieve cookies.

DatagramPacketThis class represents a datagram packet.

No comments:

Post a Comment