Back Contents Next


  
  FAQ
  Java Tutorial
  Questions by Topic
  Sample test
  Other Certification sites
  Certification Tips
  Exam Objectives
  Java jobs
  Java News
  About Java Prepare
   Books
  Certification Books
  SCEA Books
  Online Books
   Tutorial Topics
  Language Fundamentals
  Operator and Assignments
  Declaration and Access Control
  Classes in Java
  AWT
  Event classes
  Threads
  Layout Managers
  Collections
  Files
   Advertisements
cover
   Feedback
  Please let us know your feedback
 
StoreBusters Marketing
javaprepare.com
your tool for Java Certification
home | tutorial | questions | test 1

5.3 Miscellaneous Classes

5.3.1 InetAddress Class

public final class InetAddress extends Object implements Serializable

 

Object

  InetAddress

Interfaces

Serializable

 

An InetAddress object represents an IP address. The InetAddress class provides no public constructors. An InetAddress object is obtained from one of the static InetAddress object creation methods in this class.

Static InetAddress Object Creation Methods

Method

Syntax

getAllByName()

public static InetAddress[] getAllByName
       
(String hostName)
  throws UnknownHostException

getByName()

public static InetAddress getByName(String hostName)
  throws UnknownHostException

getLocalHost()

public static InetAddress getLocalHost()
  throws UnknownHostException

 

getAllByName() returns an array of InetAddress objects containing all of the IP addresses corresponding to the specified host name. The specified host name can either be a machine name, like "www.wrox.com", or an IP address such as "204.148.170.3".

 

getByName() returns an InetAddress object representing the primary IP address corresponding to the specified host name.

 

getLocalHost() returns an InetAddress object containing the IP address of the local host machine.

equals() Method

Method

Syntax

equals()

public boolean equals(Object obj)

 

equals() overrides the equals() method from the Object class and returns true if Object obj is an InetAddress and contains the same IP address as the invoking InetAddress object.

hashCode() Method

Method

Syntax

hashCode()

public int hashCode()

 

hashCode() overrides the hashCode() method from the Object class and returns a hash code for the invoking InetAddress object.

Methods to Return InetAddress Properties

Method

Syntax

getAddress()

public byte[] getAddress()

getHostAddress()

public String getHostAddress()

getHostName()

public String getHostName()

isMulticastAddress()

public boolean isMulticastAddress()

 

getAddress() returns a byte array containing the IP address of the invoking InetAddress object.

 

getHostAddress() returns a String representation of the IP address of the invoking InetAddress object.

 

getHostName() method attempts to return the host name associated with the IP address contained by the invoking InetAddress object. This method returns a String representation of the IP address if it cannot determine the host name.

 

isMulticastAddress() returns true if the invoking InetAddress object represents a multicast IP address.

toString() Method

Method

Syntax

toString()

public String toString()

 

toString() overrides the toString() method from the Object class and returns a String representation of the IP address associated with the invoking InetAddress object.

 

Example: Using InetAddress

 

See the ClientCLP class from example Using the Connectionless Protocol on page 8.

 

 


BackContentsNext
©1999 Wrox Press Limited, US and UK.
home | tutorial | questions | test 1