Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

midhuna peru

Ranch Hand
+ Follow
since Aug 24, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by midhuna peru

Since I initialised trans with 20 I expected it to be that. Now is my file giving me an object without trans here in line 49

Object obj=ois.readObject();

and then what is happening during these lines 50 and 51

if(obj instanceof Student)
studentList.add((Student)obj);
4 years ago
Hi guys ! l know that transient variable does not get serialized, now I want to know what is happening to my transient variable in the following program! My objects s1,s2 and s3 is serialized and saved to a file. Next I retrieve it and save in the collections. And when I display its transient variable...it is 0. How? here is the code

output

Here are my questions...
what is happening to trans when I save the objects s1,s2, s3 to the file and again when I am retrieving the object from file.
The value I gave to trans is 20. Why is displayed 0?
4 years ago
Hi Guys!

I thought my output for the following should be 9s12 but it is 9s66. Why so?

5 years ago
Got the idea how to catch the exception. Thank you so much guys!

So I removed line 41

and added this instead


5 years ago
Yah good Idea but ArrayList is temporary. The point is to retrieve data from Permanent storage later ie say another program !!! Maybe a seperate file can be used to keep count of objects whenever added to StudentDetails file everytime.
5 years ago
It is 1.6.
This is the when i tried to read the object 3rd time



I have checked everywhere. People say there is no way for this. Guess i must go with the count method !!!
5 years ago
It is throwing java.io.EOFException. how do i test if eof is true here?
5 years ago
Yah sure ! But what i want to know is instead of keeping a count of objects stored, Is there a way to know the End of File? Like i use hasNext for List....?
5 years ago
Oh i got it! Now Say i have added some objects in the File, then how do i retrive all of them without knowing the no of objects in the File ?
5 years ago
Hi Guys! Iam trying to store and retrieve data using files, serialization and generics. My task is store 5 objects in file and retrieve them. Now After storing the objects in file i donot know how to retrieve all the objects. Here is my code..


The Output is:


How many ever objects i store, When i retrieve, i get the output for the first object that i stored in the file. Why is it so? and how do i retrive all the objects i store in the file?
5 years ago
Hey guys! I got my answers from here in detail.
5 years ago

Thanks for the notes. So CASE 2 and 3 are compilation errors. But in CASE 1, this Hiding concept is completly new to me. I did not get it. I modified my main method as the following,


Output is


Now what is happening here?
5 years ago
Oops sorry...I edited the proper code. Now it works.
5 years ago
Hi guys ! I was trying out the following code in 3 ways.
CASE 1: eat() method in both the base class and sub class are static.


The output is


CASE 2:
Only Animal's eat() method is static, the error is


CASE 3
Only Horse's eat() method is static, the error is


What is happenning in CASE 1,2,3 ? Is eat() method overriding in CASE 1?


5 years ago