• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is String[ ] Serializabel?

 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String[] str = new String[7];
str= data.readRecord(recNo);
Is str serializiabel? Can it be transmitted by rmi or socket or ObjectStream?
 
Vinod Chandana
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To the best of my knowledge, string is serializable. I was able to send string using rmi as well as sockets
Regards,
Vinod.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An array is serializable as long as it's an array of a Serializable reference type, or an array of privitives. So String[] is serializable because String is serializable.
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Jim and Vinod
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim:
Thanks for your acurate explaination.
An array is serializable as long as it's an array of a Serializable reference type, or an array of privitives. So String[] is serializable because String is serializable.

String array is serializable and we can transmit it throug net-work or to files. So, do you think we also need to create a class Record

what approach is better, using String[] or class Record to transmit data?
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone has a good idea?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String array is serializable and we can transmit it throug net-work or to files. So, do you think we also need to create a class Record
You don't need to, but you're allowed to if you want.
what approach is better, using String[] or class Record to transmit data?
I think that depends on whether you use a fat client or thin client design. Or as they're commonly but misleadingly called here, 2-tier or 3-tier. Read this thread until you get bored, make a decision, and then don't worry about it. If you use the "2 tier" model, you wouldn't have a Record class in your networking code; you'd just use String[]. If you use "3-tier" you have the option of using a Record class. In this case I think you could go either way - I don't think it matters much whether you use a new class or not. Perhaps others have strong opinions on this though.
 
Peter Yunguang Qiu
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Jim:
thanks for your help.
I think use String[] is staitforward. Using an objects of class Record need more unneccesary work, but does that means good OO Design?
I am not clear with 2-tier and 3-tier, could you explain?
Peter
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter
I am not clear with 2-tier and 3-tier, could you explain?

See the link Jim pointed you at for a long discussion on it.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic