R4R
Right Place For Right Person TM
 
R4R Java Advancejava Packages Networking FAQs Networking Subjective Questions and Answers

 


Tolal:95 Click: 1 2 3 4 5
Previous Home Next

SUB Interview Questions And Answers

Page 1

Ques: 1 What is the difference between URL instance and URLConnection instance?

Ans:
A URL bassically stands for UNIFORM RESOURCE LOCATOR . Its instance represents the location of a resource, and a URL Connection instance represents a link for accessing or communicating with the resource at the location.

Ques: 2 How do I make a connection to URL?

Ans:
Firstly We have a URL instance and then invoke open Connection on it. URLConnection is a bassically abstract class, which means we 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 our URL. Eg. URL url ; URLConnection connection; try { url = new URL(���); connection = url.openConnection(); } catch (MalFormedURLException e) { }

Ques: 3 What Is a Socket in Java Networking and RMI?

Ans:
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 is bassicaly a type of class, Which is 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.

Ques: 4 What information is needed to create a TCP Socket?

Ans:
Some information is needed to create a TCP Socket Which is following here : > The Local System's IP Address and Port Number. And > The Remote System�s IPAddress and Port Number.

Ques: 5 What are the two important TCP Socket classes?

Ans:
The Two important Socket classes are there : > ServerSocket : ServerSocket is used for normal two-way socket communication. > Socket : Socket class allows us to read and write through the sockets. * getInputStream() and * getOutputStream() are the two methods available in Socket class.

Ans:
The Two important TCP Socket classes are 1. Socket Class 2. ServerSocket Class

Ques: 6 When Mal formed URL Exception and Unknown Host Exception throws?

Ans:
When the specified URL is not connected then the URL throw MalformedURLException thorows that time when specified URL is not connected and In the case of UnknownHostException throws when If InetAddress's methods getByName and getLocalHost are unable to resolve the host name .

Ques: 7 What is the RMI?

Ans:
RMI is basscially stands for Remote Method Invocation. RMI is a the mainly use for set the APIs that allows to build distributed applications. RMI uses interfaces to define remote objects to turn local method invocations into remote method invocations.

Ques: 8 What is the difference between the File and RandomAccessFile classes?

Ans:
The RandomAccessFile class bassically provides the methods which is needed to directly access data contained in any part of a file. The File class encapsulates the files and directories of the local file system.

Ans:
The File class is used to perform the operations on files and directories of the file system of an operating system. This operating system is the platform for the java application that uses the File class objects. The contents of the files cannot be read or write. The RandomAccessFile class has methods that perform the direct access to data of any part of the file. RandomAccessFile class also provides the facilities to read and write data from a single file without closing the streams for each read or write. It provides the facilities to write primitive data to the files.

Ans:
The File class is used to perform the operations on files and directories of the file system of an operating system. This operating system is the platform for the java application that uses the File class objects. The contents of the files cannot be read or write. The RandomAccessFile class has methods that perform the direct access to data of any part of the file. RandomAccessFile class also provides the facilities to read and write data from a single file without closing the streams for each read or write. It provides the facilities to write primitive data to the files.

Ques: 9 What interface must an object implement before it can be written to a stream as an object?

Ans:
Two type of object which is interface must on object implement before it can be written to a stream as an object : > The Serializable or > Externalizable interface

Ques: 10 What is the Sockets?

Ans:
Socket is the bassically defined as : > A socket is a mainly use for the transmission of data b/w two hosts It is reliable connection for the transmission. > Sockets isolate programmers from the details of packet encodings, lost and retransmitted packets, and packets that arrive out of order. > There are limits. Sockets are more likely to throw IOExceptions than files.

Ques: 11 What are the Socket Operations?

Ans:
Socket have a four fundamental operations , Which is following as : > Connect to a remote machine > Send data > Receive data > Close the connection

Ques: 12 What is the use of The java.net.Socket class?

Ans:
The java.net.Socket is mainly a class, which is very usefull class, this is defined as : > We can connect to remote machines; > We can send data; > We can receive data; > We can close the connection. > The java.net.Socket class allows us to create socket objects that perform all four fundamental socket operation. > Each Socket object is associated with exactly one remote host. To connect to a different host, We must create a new Socket object.

Ques: 13 How can i connect to the Socket with the help of constructor?

Ans:
Sockets connection is accomplished with the help of constructors. public Socket(String host, int port) throws UnknownHostException, IOException public Socket(InetAddress address, int port) throws IOException public Socket(String host, int port, InetAddress localAddr, int localPort) throws IOException public Socket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException

Ques: 14 How can we open the Sockets?

Ans:
Opening Sockets : > All the constructors throw an IOException if the connection can't be made for any reason. > The Socket() constructors do not just create a Socket object. They also help to connect the underlying socket to the remote server.

Ques: 15 HOw can we choose the host and the port?

Ans:
Choosing the Host and the Port : > We must at least specify the remote host and port to connect to. > The host may be specified as either a string like "utopia.poly.edu" or as an InetAddress object. > The port should be an int between 1 and 65535. Socket webMetalab = new Socket("metalab.unc.edu", 80); > We cannot just connect to any port on any host. The remote host must actually be listening for connections on that port. > We can use the constructors to determine which ports on a host are listening for connections.

Ques: 16 How can we pick the IP Address?

Ans:
Picking an IP address : > The last two constructors also specify the host and port you're connecting from. > On a system with multiple IP addresses, like many web servers, this allows you to pick your network interface and IP address.

Ques: 17 How can we choose the local port?

Ans:
Choosing a Local Port : > We can also specify a local port number, > Setting the port to 0 tells the system to randomly choose an available port. > If we need to know the port we're connecting from, we can always get it with getLocalPort(). Socket webMetalab = new Socket("metalab.unc.edu", 80, "calzone.oit.unc.edu", 0);

Ques: 18 How can i Send and Receive the Data in Socket?

Ans:
Sending and Receiving the Data : >Data is sent and received with output and input streams. > There are methods to get an input stream for a socket and an output stream for the socket. public InputStream getInputStream() throws IOException public OutputStream getOutputStream() throws IOException > There's also a method to close a socket: public synchronized void close() throws IOException

Ques: 19 How can i read Input from a Socket?

Ans:
Reading Input from a Socket : > The getInputStream() method returns an InputStream which reads data from the socket. > We can use all the normal methods of the InputStream class to read this data. > Most of the time we'll chain the input stream to some other input stream or reader object to more easily handle the data.

Ques: 20 How can we write o/p to a Socket?

Ans:
Writing Output to a Socket : > The getOutputStream() method returns an output stream which writes data to the socket. > Most of the time you'll chain the raw output stream to some other output stream or writer class to more easily handle the data.


Goto Page:

1 2 3 4 5
Share |

SUB Objective

SUB Objective Questions And Answers

SUB Interview Questions And Answers

SUB Interview Questions And Answers

SUB Interview Questions And Answers

SUB Subjective Questions And Answers

R4R,SUB Objective, SUB Subjective, SUB Interview Questions And Answers,SUB,SUB Interview,SUB Questions ,SUB Answers

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R