Serialization and write object [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wanted to know can we change the way serialization works in java , like say if we have two fields in a class and we create an object of the class. Can we change the order in which the fields of the object is serialized ? also is this any way related to writeObject() method that is used to write the data into a .ser file..?? please help
Thanks in advance....
I wanted to know how to do custom serialization..

use Interface Externalizable. It will give you more control over your serialization and de-serialization process .
http://docs.oracle.com/javase/7/docs/api/java/io/Externalizable.html
[code example ] http://www.jusfortechies.com/java/core-java/externalization.php
from docs
Only the identity of the class of an Externalizable instance is written in the serialization stream and it is the responsibility of the class to save and restore the contents of its instances. The writeExternal and readExternal methods of the Externalizable interface are implemented by a class to give the class complete control over the format and contents of the stream for an object and its supertypes. These methods must explicitly coordinate with the supertype to save its state. These methods supersede customized implementations of writeObject and readObject methods.

Related

Diferences (uses) between Internal Interfaces & Subinterfaces [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
please I need help with a theoretical issue in Java SE. Below I detail the information I'm looking for:
Difference between internal interfaces (that is, nested, interfaces within others) and subinterfaces (that is, interfaces that extend from other interfaces, or interfaces that implement other interfaces, is this possible?), and most important, under what circumstances do we use each one? I mean, what do we use them for?
I know that there're internal interfaces, since in the Java API there is, for example, the Entry interface, of the java.util package, which is declared within the Map interface of the same package, Entry is an internal interface of Map. But I don't understand the functionality of these internal interfaces. I'd also like to know what the subinterfaces are for, so that I can distinguish them from the internal interfaces.
Greetings,
F
Nested interfaces are exactly the same as non-nested interfaces.
The only difference is that they're defined inside a class or interface instead of being defined outside, and that their name thus includes the enclosing class or interface name: Map.Entry instead of Entry.
That makes it clear that they are conceptually linked to their enclosing class or interface (i.e. Map.Entry makes it clear that it's an entry of a Map).

Java - Implementing my own Stream [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Is it possible to implement a custom Stream?
I would like to create a StringStream in addition to IntStream or LongStream.
I would like to add extra methods, like storeToFile(path).
I thought it is a lot of work to implement a Stream. The standard implementation is java.util.stream.ReferencePipeline, but I cannot instantiate it directy.
Is there a simple solution?
Thanks for help.
It sounds like you want a Collector that is custom, not a Stream. You can create a Stream out of anything with Stream.of(), but you would need collectors for this.
storeToFile would be a StoringToFileCollector or something...
Yeah, you can create a stream of anything you want.
Extend the interface BaseStream
public interface MyStream extends BaseStream<MyClass,MyStream>
Then implement it
public class DefaultMyStream implements MyStream
{
//...
}
Probably crosscheck another stream implementation when writing your implementation.
I don't know that there's necessarily a huge advantage to doing this. Maybe there's a valid use case. In any case, it's possible.

Java: Create Instances based on prototype [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I, and What is the best/proper way (ie, most performant and clearest syntactically) in Java to create object instances based on a prototype object instance, when this will occur repeatedly and in a performance critical code path?
I have thought about cloning via a cloning support library, but is that the best/only way? (These need to be arbitrary objects, btw, not ones that implement Clonable).
To clarify what I mean: I have an existing instance of Class T, which has fields set on it, and I want to pop out many versions of the same object to use separately, with the best performance and syntactic clarity possible.
Thanks.
Create a builder, which receives this class instance:
Person newOne = new PersonBuidler(oldOne).setAge(42)
Implementation of this builder may use apache common BeanUtils for cloning Java Beans or some other utility library for cloning arbitrary class.
See How do I copy an object in Java?

Why Java utilizes both Collection and Collections classes to provide different things [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In many places Java utilizes the approach to have both, for example, Collection and Collections class.
Collection is interface, it defined some methods.
Collections class also provide some method.
Why didn't they choose to place all methods inside the interface?
because the names are too puzzled word. Collection is like Collections.
I know the historical reason. like interrupt() and interrupted() , because java must fit to old version, the methods' names are likely, make developer difficult to write and read.
But the collection framwork must have reason in this way.
For starters, an interface cannot have static methods. Note: until Java 8.
Arguably, some of the static methods of Collections should have been made instance methods of Collection, but that would create a lot of "clutter". Plus, extra work for implementations not derived from AbstractCollection etc.

Input output streams [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If possible I would like to know what class provides input and output streams? Is it Object or System class? I am asking this because every class inherits Object class. This is a bit confusing to me.
Input and Output operations are performed by the reader class and it's sub-classes. Object is a base class which provides some "usefull" methods such as equals() and toString().
i don't know what exactly is your confusion , but i think its java.io.OutputStream and java.io.InputStream both are interfaces , based on what Stream you use , there definition in Stream class changes. i suggest you read some basic books and gets your fundamental of OOP strong.
and make full use of
Reference doc

Categories