Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serializable Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serializable Problem" Watch "Serializable Problem" New topic
Author

Serializable Problem

Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
Here is The code from the book of K&B Can Any one please tell me how we use the private methods??? how the private methods of Dog Class involbs??? :roll:

(shouts not necessary in topic title)
[ February 26, 2007: Message edited by: Barry Gaunt ]

SCJP 1.5, SCWCD 1.4, SCBCD 5.0, next SCDJWS...
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
This is rhe code..............




class Dog implements Serializable {
transient private Collar theCollar;
public int dogSize;
public Dog(Collar collar, int size) {
theCollar = collar;
dogSize = size;
}


public Collar getCollar() {return theCollar; }

private void writeObject( ObjectOutputStream os)
{
try {
os.defaultWriteObject();
os.writeInt(theCollar.getCollarSize());
}catch(Exception e) { e.printStackTrace(); }
}

private void readObject(ObjectInputStream is) {
try {
is.defaultReadObject();
theCollar = new Collar(is.readInt());
} catch (Exception e) {e.printStackTrace(); }
}
}//End of dog class
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
How the private readObject and writeObject methods are invocked...
Nandu Jawale
Greenhorn

Joined: Feb 04, 2002
Posts: 22
Through reflection. Java reflection provides fields, methods and constructors to be made accessible via setAccessible(boolean) method.
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi Damodar,

I appreciate you for imposing the Why.
I too don't know what happens exactly there.
Here is a hint that can happen.
Hope it will improve your thought process...

interface Catch{

private void display();
public void callDisplay();

}

class Try{

private void display() {
System.out.pritntln("I like the way you thinking");
}

pulic void callDisplay(){
display();
}

}

Cheers


Thanks & Regards, T.Srinivasan
SCWCD 1.4(89%), SCJP 5.0(75%)
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
correction class Try implements Catch
Srinivasan thoyyeti
Ranch Hand

Joined: Feb 15, 2007
Posts: 557
Hi,
I am sorry for the above example where i have written private method in interface.

I am also very curious to know how the private(readObject) method is accessed from Dog class.

Any suggestions welcome
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
It is still not clear to me...
My question is how the private methods are implemented and by whom?
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
The method is invoked by the JVM. JVM can access your private methods. But other classes would not be able to access the same. Serializable is a marker interface having no methods. There are many methods you can have in your class which implements serializable to tell the JVM what to do at runtime with the method. A look at the api would be good. Here you go.
Damodar Mukhopadhyay
Ranch Hand

Joined: Jan 15, 2007
Posts: 98
Thank You so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializable Problem
 
Similar Threads
How could this be possible
private methods
How private method are written in Jsp page
Unit testing-private methods
testing private methods with junit?