wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes Exchanging data between servlets and Session Beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Exchanging data between servlets and Session Beans" Watch "Exchanging data between servlets and Session Beans" New topic
Author

Exchanging data between servlets and Session Beans

Afshir Irani
Greenhorn

Joined: Jun 13, 2001
Posts: 4
We need to use these value objects to transmit data between Servlets and Session Beans in a distributed envirnoment.
The server being used is WebLogic 6.1.
We have value objects ( Classes containing private attributes and get and set methods to access these attributes).
These value objects implement the Serializable Interface.
Some of these private attributes are primitive datatypes (like int, char etc).
Are the Primtive Data types in Java serializable.
Will this design work out???
Deepak Mahbubani
Ranch Hand

Joined: May 12, 2001
Posts: 68
Originally posted by Afshir Irani:
We need to use these value objects to transmit data between Servlets and Session Beans in a distributed envirnoment.
The server being used is WebLogic 6.1.
We have value objects ( Classes containing private attributes and get and set methods to access these attributes).
These value objects implement the Serializable Interface.
Some of these private attributes are primitive datatypes (like int, char etc).
Are the Primtive Data types in Java serializable.
Will this design work out???


Primitive datatypes are not serializable.
You just have to implement the serializable interface for passing the value objects.
public class MyClass implements java.io.Serializable {
....
}

------------------
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Originally posted by Deepak Mahbubani:

Primitive datatypes are not serializable.
You just have to implement the serializable interface for passing the value objects.
public class MyClass implements java.io.Serializable {
....
}

Hogwash! Primitive datatypes (int, char, etc.) are most CERTAINLY serializable. How do you think you would ever serialize anything if they weren't?


------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Kyle,
A separate but related question:
What happens if I have a non-Serializable class A within a Serializable class B? Will class B be Serializable?
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Originally posted by Miftah Khan:
Kyle,
A separate but related question:
What happens if I have a non-Serializable class A within a Serializable class B? Will class B be Serializable?

No. In fact, an exception will be thrown for Class A during the serialization of the instances of Class B. However, the instance of Class B may still be written out -- albeit the variable holding Class A will have no value (null) when it is read back in -- it depends on how the code doing the serialization handles the exceptions.
Kyle
P.S. Some good information on this (an article by John Zukowski; always a good source of accurate information -- can be found at http://developer.java.sun.com/developer/technicalArticles/ALT/serialization/?frontpage-jdc)

------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exchanging data between servlets and Session Beans