Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exchanging data between servlets and Session Beans

 
Afshir Irani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic