JavaRush /Java Blog /Random EN /Level 32. Answers to interview questions on the level top...
DefNeo
Level 36

Level 32. Answers to interview questions on the level topic

Published in the Random EN group
Level 32. Answers to interview questions on the topic of level - 1
  1. Why is it needed RandomAccessFile?

    RandomAccessFileis a class in the Java IO API package, it allows you to navigate, read from, or write to a file as you please. You can also replace existing parts of a file; we are talking about updating the contents of a file, or more precisely about updating a fragment of a file. This cannot be done with FileInputStreamor FileOutputStream, but RandomAccessFilewill give you this ability.

    Link: RandomAccessFile and its capabilities

  2. What happens if the file from which it reads RandomAccessFiledoes not exist?

    WillFileNotFoundException

  3. What happens if the file where it writes RandomAccessFiledoes not exist?

    It will create a new one and write it to it.

  4. Why do we need a class StringReader?

    The Java.io.StringReader class is a character stream whose source is a string.

    Represents a stream of characters whose source is called a string

  5. Why do we need a class StringWriter?

    public class StringWriter
    extends Writer

    A character stream that collects its output in a string buffer, which can then be used to construct a string.

    Closing a StringWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

    A stream of characters that collects its stream into a buffer of strings, which can then be used to create a string.

  6. Why do we need a class ByteArrayStream?

    So, ByteArrayInputStreamand ByteArrayOutputStream.

    These classes are essentially similar to StringReaderand < code="">. It only StringReaderread characters (char) from a string (String), but ByteArrayInputStreamreads bytes from a byte array (ByteArray). <>

    StringWriterwrote characters (char) into a string, but ByteArrayOutputStreamwrites bytes into a byte array inside it. When writing to StringWriterit, the string inside it lengthened, and when writing to ByteArrayOutputStreamits internal array, the byte also dynamically expanded.

  7. Why do we need a class PrintStream? Name the places where it is used?

    The class PrintStreamwas invented to display information in a readable manner. It almost entirely consists of methods printand println.

  8. Why is it needed DynamicProxy?

    Java has a special class (java.lang.reflect.Proxy) with which you can actually construct an object at runtime (dynamically) without creating a separate class for it.

  9. How does RMI work?

    RMI stands for Remote Method Invokation. Or in other words, RMI is a mechanism that allows an object in one Java machine to call methods of an object in another Java machine, even if they are on different computers, in different countries, on different sides of the globe.

    The traditional approach to executing code on other machines across a network can be confusing due to its tedious and error-prone implementation. The best way to think about this problem is to assume that some objects are located on another machine, and that you can send messages to these remote objects and receive the result as if they were located on your local machine. This simplification is exactly what Remote Method Invocation (RMI) allows you to do in Java.

    Here's an article on creating your own RMI implementation: Remote Method Invocation (RMI)

  10. What types of objects can be transferred via RMI?

    Objects must implement an interfaceSerializable

    Remote method Invocation is a mechanism that allows you to call a method on a remote object. According to it, all operations for preparing and transmitting data are encapsulated in a called method of the client stub object. The method call itself is no different from calling a method on a regular local object, with a few exceptions:

    • local objects are passed by value (copies);
    • when transferring a remote ( Remote) object, if it is exported, the stub of this object is transferred;
    • passed objects must be Serializable;
    • in addition to all other exceptional situations, when calling a remote method, an exception may be raised RemoteException(marshalization/unmarshalization errors, data transfer errors and other possible protocol errors);

    It should also be noted that when calling a method, we work with a remote interface, and not with a remote class.

Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION