Basic Java Interview Question and Answers

69. What is a Socket?
  A socket is one end point of a two way communication link between two programs running on the network. 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 that implement the client side of the connection and the server side of the connection, respectively.
 
Your Name Your Email-ID
Your Answer
70. Explain the terms ObjectInput, ObjectInputStream, ObjectOutput and ObjectOutputStream?
 
  • ObjectInput – ObjectInput is an interface that extends the DataInput interface. It supports object serialization and defines the readobject() method to deserialize an object. All the methods defined in this interface throw an IOException.
  • ObjectInputStream – It is a class that extends the InputStream class and implements ObjectInput Interface. It is responsible for reading objects from a stream. The constructor of this class is
    ObjectInputStream( InputStream inStream) throws IOException, streamCorruptedException.
  • ObjectOutput – The ObjectOutput is an interface that extends the DataOutput interface and supports object serialization. It defines the writeObject () method to serialize an object.
  • ObjectOutputStream – The ObjectOutputStream class extends the OutputStream class and implements the ObjectOutput interface. It is responsible for writing objects to a stream. The constructor of this class is
    ObjectOutputStream( OutputStream outstream) throws IOException.
  • The argument outStream is the output stream to which serialized objects will be written.
 
Your Name Your Email-ID
Your Answer
71. Which class should use to obtain design information about an object?
  The Class is used to obtain information about an object’s design.
 
Your Name Your Email-ID
Your Answer
72. Can a top level class be private or protected?
  No. A top level class cannot be private or protected. It can have either "public" or no modifier. If it does not have a modifier it is supposed to have a default access. If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class cannot be private. Same is the case with Protected.
 
Your Name Your Email-ID
Your Answer