Computer Science

Java Packages-2

FontSize

Networking Concepts

    1) The API doesn't list any constructors for InetAddress- How do I create an InetAddress instance?

        ANSWER : In case of InetAddress the three methods getLocalHost, getByName, getByAllName can be used to create instances.

        E.g.

        InetAddress add1;

        InetAddress add2;

        try{

        add1 = InetAddress.getByName("java.sun.com");

        add2 = InetAddress.getByName("199.22.22.22");

        }catch(UnknownHostException e){}

    2) Is it possible to get the Local host IP?

        ANSWER : Yes. Use InetAddress's getLocalHost method.

    3) What's the Factory Method?

        ANSWER : Factory methods are merely a convention whereby static methods in a class return an instance of that class. The InetAddress class has no visible constructors. To create an InetAddress object, you have to use one of the available factory methods. In InetAddress the three methods getLocalHost, getByName, getByAllName can be used to create instances of InetAddress.

    4) What’s the difference between TCP and UDP?

        ANSWER : These two protocols differ in the way they carry out the action of communicating. A TCP protocol establishes a two way connection between a pair of computers, while the UDP protocol is a one-way message sender. The common analogy is that TCP is like making a phone call and carrying on a two-way communication, while UDP is like mailing a letter.

    5) What is the Proxy Server?

        ANSWER : A proxy server speaks the client side of a protocol to another server. This is often required when clients have certain restrictions on which servers they can connect to. And when several users are hitting a popular web site, a proxy server can get the contents of the web server's popular pages once, saving expensive internetwork transfers while providing faster access to those pages to the clients.

        Also, we can get multiple connections for a single server.

    6) What are the seven layers of OSI model?

        ANSWER : Application, Presentation, Session, Transport, Network, DataLink, Physical Layer.

    7) What Transport Layer does?

        ANSWER : It ensures that the mail gets to its destination. If a packet fails to get its destination, it handles the process of notifying the sender and requesting that another packet be sent.

    8) What is DHCP?

        ANSWER : Dynamic Host Configuration Protocol, a piece of the TCP/IP protocol suite that handles the automatic assignment of IP addresses to clients.

    9) What is SMTP?

        ANSWER : Simple Mail Transmission Protocol, the TCP/IP Standard for Internet mails. SMTP exchanges mail between servers; contrast this with POP, which transmits mail between a server and a client.

    10) In OSI N/w architecture, the dialogue control and token management are responsibilities of...

        a) Network b) Session c) Application d) DataLink

        ANSWER : b) Session Layer.

    11) In OSI N/W Architecture, the routing is performed by ______

        a) Network b) Session c) Application d) DataLink

        Answer : Network Layer.

  Networking

 1) What is the difference between URL instance and URLConnection instance?

        ANSWER : A URL instance represents the location of a resource, and a URLConnection instance represents a link for accessing or communicating with the resource at the location.

    2) How do I make a connection to URL?

        ANSWER : You obtain a URL instance and then invoke openConnection on it.

        URLConnection is an abstract class, which means you can't directly create instances of it using a constructor. We have to invoke openConnection method on a URL instance, to get the right kind of connection for your URL.

        Eg. URL url;

        URLConnection connection;

        try{ url = new URL("...");

        conection = url.openConnection();

        }catch (MalFormedURLException e) { }

    3) What Is a Socket?

        A socket is one end-point of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.Socket classes are used to represent the connection between a client program and a server program. The java.net package provides two classes--Socket and ServerSocket--which implement the client side of the connection and the server side of the connection, respectively.

    4) What information is needed to create a TCP Socket?

        ANSWER : The Local System’s IP Address and Port Number. And the Remote System's IPAddress and Port Number.

    5) What are the two important TCP Socket classes?

        ANSWER : Socket and ServerSocket.

        ServerSocket is used for normal two-way socket communication. Socket class allows us to read and write through the sockets. getInputStream() and getOutputStream() are the two methods available in Socket class.

    6) When MalformedURLException and UnknownHostException throws?

        ANSWER : When the specified URL is not connected then the URL throw MalformedURLException and If InetAddress’ methods getByName and getLocalHost are unabletoresolve the host name they throwan UnknownHostException. 

Servlets

    1) What is the servlet?

        ANSWER : Servlets are modules that extend request/response-oriented servers, such as Java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company's order database.

        Servlets are to servers what applets are to browsers. Unlike applets, however, servlets have no graphical user interface.

    2) Whats the advantages using servlets than using CGI?

        ANSWER : Servlets provide a way to generate dynamic documents that is both easier to write and faster to run. Servlets also address the problem of doing server-side programming with platform-specific APIs: they are developed with the Java Servlet API, a standard Java extension.

    3) What are the uses of Servlets?

        ANSWER : A servlet can handle multiple requests concurrently, and can synchronize requests. This allows servlets to support systems such as on-line conferencing.

        Servlets can forward requests to other servers and servlets.Thus servlets can be used to balance load among several servers that mirror the same content, and to partition a single logical service over several servers, according to task type or organizational boundaries.

    4) Which pakage provides interfaces and classes for writing servlets?

        ANSWER : javax

    5) Whats the Servlet Interfcae?

        ANSWER : The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet.

        Servlets-->Generic Servlet-->HttpServlet-->MyServlet.

        The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. Servlet writers provide some or all of these methods when developing a servlet.

    6) When a servlet accepts a call from a client, it receives two objects- What are they?

        ANSWER : ServeltRequest: Which encapsulates the communication from the client to the server. ServletResponse: Whcih encapsulates the communication from the servlet back to the client. ServletRequest and ServletResponse are interfaces defined by the javax.servlet package.

    7) What information that the ServletRequest interface allows the servlet access to?

        ANSWER : Information such as the names of the parameters passed in by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received it.

        The input stream, ServletInputStream.Servlets use the input stream to get data from clients that use application protocols such as the HTTP POST and PUT methods.

    8) What information that the ServletResponse interface gives the servlet methods for replying to the client?

        ANSWER : It Allows the servlet to set the content length and MIME type of the reply.

        Provides an output stream, ServletOutputStream and a Writer through which the servlet can send the reply data.

    9) What is the servlet Lifecycle?

        ANSWER : Each servlet has the same life cycle:

        A server loads and initializes the servlet (init())

        The servlet handles zero or more client requests (service())

        The server removes the servlet (destroy())

        (some servers do this step only when they shut down)

    10) How HTTP Servlet handles client requests?

        ANSWER : An HTTP Servlet handles client requests through its service method. The service method supports standard HTTP client requests by dispatching each request to a method designed to handle that request.
 


Please Donate






RSS Feeds

SiteTranslation



Copyright © 2024 ashkerala.com. All Rights Reserved.
Google+ Click to listen highlighted text! Powered By GSpeech