-
Why is it needed
RandomAccessFile
?RandomAccessFile
- a class of the Java IO API package, it allows you to navigate through the file, read from it or write to it as you please. You can also replace the existing parts of the file, we are talking about updating the contents of the file, or rather, updating a fragment of the file. This cannot be done withFileInputStream
orFileOutputStream
, butRandomAccessFile
will give you that option.Reference: RandomAccessFile and its features
-
What happens if the file it is reading from
RandomAccessFile
does not exist?Will
FileNotFoundException
-
What happens if the file it writes to
RandomAccessFile
doesn't exist?Create a new one and write to it.
-
Why is a class needed
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
-
Why is a class needed
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.
-
Why is a class needed
ByteArrayStream
?So,
ByteArrayInputStream
andByteArrayOutputStream
.These classes are essentially something similar to
StringReader
and< code="">. Only <>StringReader
read characters (char) from a string (String), butByteArrayInputStream
reads bytes from a byte array (ByteArray).StringWriter
wrote characters (char) to a string, butByteArrayOutputStream
writes bytes to an array of bytes inside it. When writing toStringWriter
the string inside it lengthened, and when writing toByteArrayOutputStream
its internal byte array, it also dynamically expanded. -
Why is a class needed
PrintStream
? Name the places where it is used?The class
PrintStream
has been thought up for a readable output of the information. It almost entirely consists of methodsprint
andprintln
. -
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.
-
How does RMI work?
RMI stands for Remote Method Invokation - remote method invocation. 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 spread over a network can be confusing because of its tedious and error-prone implementation. The best way to deal with this problem is to assume that some objects are located on a different machine, and that you can send messages to these remote objects and get the result as if they were on your local machine. This simplification is exactly what allows Remote Method Invocation (RMI) in Java.
Here is an article on creating your own RMI implementation: Remote Method Invocation (RMI)
-
What types of objects can be passed over RMI?
Objects must implement an interface
Serializable
Remote method Invocation is a mechanism that allows you to call a method on a remote object. According to it, all data preparation and transfer operations are encapsulated in the called method of the client stub object (stub). The method call itself is no different from calling the method of an ordinary local object, with a small exception:
- local objects are passed by value (copy);
- when passing a remote (
Remote
) object, if it is exported, the stub of this object is passed; - 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 are working with a remote interface, and not with a remote class.
DefNeo
Level 36
GO TO FULL VERSION