World's most popular travel blog for travel bloggers.

What is proxy server? Explain URL class and its methods in java.

, , No Comments

 

StringStringBuffer
String is slow and consumes more memory when you concat too many strings because every time it creates new instance.StringBuffer is fast and consumes less memory when you concat strings.
String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method.StringBuffer class doesn’t override the equals() method of Object class.

Q8. a) What is proxy server? Explain URL class and its methods in java.

Answer : – A proxy server is basically another computer which serves as a hub through which internet requests are processed. By connecting through one of these servers, your computer sends your requests to the server which then processes your request and returns what you were wanting. In this way it serves as an intermediary between your home machine and the rest of the computers on the internet.

Proxies are used for a number of reasons such as :

  • Control internet usage in corporate networks
  • Bandwidth savings for large networks
  • Monitoring and Filtering
  • Privacy (hide your IP address, location, and other information)
  • Security

Constructors of Java URL class

URL(String spec)
Creates an instance of a URL from the String representation.

URL(String protocol, String host, int port, String file)
Creates an instance of a URL from the given protocol, host, port number, and file.

URL(String protocol, String host, int port, String file, URLStreamHandler handler)
Creates an instance of a URL from the given protocol, host, port number, file, and handler.

URL(String protocol, String host, String file)
Creates an instance of a URL from the given protocol name, host name, and file name.

URL(URL context, String spec)
Creates an instance of a URL by parsing the given spec within a specified context.

URL(URL context, String spec, URLStreamHandler handler)
Creates an instance of a URL by parsing the given spec with the specified handler within a given context.

Commonly used methods of Java URL class

The java.net.URL class provides many methods. The important methods of URL class are given below.

MethodDescription
public String getProtocol( )it returns the protocol of the URL.
public String getHost( )it returns the host name of the URL.
public String getPort( )it returns the Port Number of the URL.
public String getFile( )it returns the file name of the URL.
public String getAuthority( )it returns the authority of the URL.
public String toString( )it returns the string representation of the URL.
public String getQuery( )it returns the query string of the URL.
public String getDefaultPort( )it returns the default port of the URL.
public URLConnection openConnection( )it returns the instance of URLConnection i.e. associated with this URL.
public Object getContent( )it returns the content of the URL.

0 comments:

Post a Comment

Let us know your responses and feedback