-
Why is it needed
RandomAccessFile
?RandomAccessFile
is 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 withFileInputStream
orFileOutputStream
, butRandomAccessFile
will give you this ability. -
What happens if the file from which it reads
RandomAccessFile
does not exist?Will
FileNotFoundException
-
What happens if the file where it writes
RandomAccessFile
does not exist?It will create a new one and write it to it.
-
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
-
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.
-
Why do we need a class
ByteArrayStream
?So,
ByteArrayInputStream
andByteArrayOutputStream
.These classes are essentially similar to
StringReader
and< code="">. It only <>StringReader
read characters (char) from a string (String), butByteArrayInputStream
reads bytes from a byte array (ByteArray).StringWriter
wrote characters (char) into a string, butByteArrayOutputStream
writes bytes into a byte array inside it. When writing toStringWriter
it, the string inside it lengthened, and when writing toByteArrayOutputStream
its internal array, the byte also dynamically expanded. -
Why do we need a class
PrintStream
? Name the places where it is used?The class
PrintStream
was invented to display information in a readable manner. 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. 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)
-
What types of objects can be transferred via 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 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.
DefNeo
Level 36
GO TO FULL VERSION