Boris Mandovskes
Boris Mandovskes

Reputation: 111

Understanding flow of object creation

I'm new to java and I wonder if there is simple way to know flow like the following of object creation, I'm using eclipse and when I write new ObjectInputStream and press CTRL+SPACE. I don't see any option that I can enter new BufferedInputStream (I have copied the code from example) and than to create new object for FileInputStream etc.

in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("emp.dat")));
List temp = (List)in.readObject();

I give that example since this is the first time that I saw this kind of creation new object flow and I want to use some best practice for the next times.

Upvotes: 1

Views: 274

Answers (3)

midhunhk
midhunhk

Reputation: 5554

This is a classic example of using [Decorator Pattern][1]. You will wrap objects to add behavior.

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533492

Ctrl+Space shows you options you have available at that point to get the options you might value if you created something you have to type new and then Ctrl+Space

BTW: ObjectInputStream and ObjectOutputStream are already buffered so adding more buffering isn't best practice IMHO.

Upvotes: 0

Nandkumar Tekale
Nandkumar Tekale

Reputation: 16158

This is very simple. This is equivalent to :

FileInputStream fis = new FileInputStream("emp.dat");
BufferedInputStream bis = new BufferedInputStream(fis)
ObjectInputStream in = new ObjectInputStream(bis);

As you are new to Java, you should check javadocs instead of checking it in Eclipse.

Check : FileInputStream, BufferedInputStream, ObjectInputStream

Upvotes: 1

Related Questions