 2007 West |
|
GOLD SPONSORS:
|
Active Endpoints Your SOA Needs BPEL for Orchestration
|
BEA Virtualized SOA: Adaptive Infrastructure for Demanding Applications
|
Nexaweb Overcoming Bandwidth Challenges with Nexaweb
|
TIBCO What is Service Virtualization?
|
|
SILVER SPONSORS:
|
WSO2 Using Web Services Technologies and FOSS Solutions
|
|
Click For 2007 East Event Webcasts
|
|
TOP THREE LINKS YOU MUST CLICK ON
Java Basics
Java Serialization
In lessons 5 and 6 of this series, you've learned how to use some of the Java streams to read or write bytes, characters or numeric data. This lesson is about reading or writing entire Java objects into streams.
Reader Feedback : Page 1 of 1
#9 |
ndhai commented on the 17 Jun 2008
I have some pb with a test following: package com.lecam; import java.io.*; public class testFile implements java.io.Externalizable{ byte one_byte = 1; int one_int = 1024; public testFile() { } public void writeExternal(ObjectOutput stream) throws java.io.IOException { stream.writeByte(one_byte); stream.writeInt(one_int); } public void readExternal(ObjectInput stream) throws java.io.IOException { one_byte = stream.readByte(); one_int = stream.readInt(); } public static void main(String args1[]) { System.out.print("Writing..."); try { testFile SubFile = new testFile(); FileOutputStream fos = new FileOutputStream("c:\\test.bin"); ObjectOutputStream oos = new ObjectOutputStream(fos); SubFile.writeExternal(oos); oos.flush(); oos.close(); fos.close(); } catch (java.io.IOException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } System.out.print("Reading..."); try { FileInputStream fis = new FileInputStream("c:\\test.bin"); ObjectInputStream ois = new ObjectInputStream(fis); testFile tFile = new testFile(); tFile.readExternal(ois); System.out.println("SubFile : "); System.out.println("byte : "+(tFile.one_byte)); System.out.println("int : "+ (tFile.one_int)); ois.close(); fis.close(); } catch (java.io.IOException e) { e.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } System.out.print("END..."); } } question: the test.bin file should be 5 bytes (one byte + one int = 1 + 4 = 5 bytes) but it is 11 bytes! I don't know why! thanks |
#8 |
Sreerag commented on the 7 Aug 2007
You have explained it in a simple, nice manner. Thanks a lot ! |
#7 |
Sreerag K M commented on the 7 Aug 2007
The presentation is so nice, simple. Thanks a lot |
#6 |
Josh commented on the 14 Apr 2004
Ravi, If you serialize an externalizeable object, it''s readExternal or writeExternal methods will automatically get called. So, the scenario you mention should never happen. When you implement Externalizable, you take control of the serialization completely, so the transient modifier will not have an effect on fields in the Externalizable object. |
#5 |
Ravi commented on the 14 Apr 2004
Excellent article. I had a concern with transient data serialization when we do a serialization with externalizable interface. I mean when I implement a class with externalizable and do a normal serialization without being used its readExternal or writeExternal calls, then the Transient data is still get serialized. Can anyone update me on this point? |
#4 |
Josh commented on the 14 Apr 2004
Good article. As the previous comment indicates, using Java serialization can introduce some problems when the objects are read in by a different version of the software. I don''t recommend using Java serialization for ''durable'' persistence for this reason. Using Externalizable can help, but for complex applications this encourages the programmer to blend the persistence and other, unrelated aspects into the same object, which is not the best design. I would recommend delegating the Externalizable implementation into another object in this case. |
#3 |
Mathieu commented on the 31 Mar 2004
Very Good introductory material. However I would like to add a paragraph on class version management. Upon a change of the code of your class if you try to read an old serialized data, you may experience error. Externalize interface is for now the safe way to prevent yourself from that. |
#2 |
java-user commented on the 29 Mar 2004
Excellent article. Liked real-world experiences shared by author. |
#1 |
andre commented on the 26 Mar 2004
Awesome! Did not know about the alternative to Serializable which exposes your application. |
YOUR FEEDBACK  | What Does the Future Hold
for the Java Language? By Joe Winchester Thierry Coq wrote: Well,
I don't sympathize at all
with the author. We've
had this junk all before:
- COBOL and FORTRAN
started it all... then,
- C was THE language
everybody could do
things, then,
- Ada was THE language
designed to do
everything, then
- C++ was THE language
for... |  | Rich Internet
Applications with Adobe
Flex 2 and Java By Victor Rasputnis; Yakov Fain; Anatole Tartakovsky One Way Link Building
wrote: Flex is simply
awesome. The only
drawback is that the
widget library (even in
version 2) is a bit
small. Hope that changes
soon. |  | NetBeans: It's Not Just
for Java Anymore By Tim Boudreau Christopher Judd wrote:
Nice article. But I am
surprised you did not
mention the upcoming
Groovy support when you
mentioned the upcoming
PHP support. |  | Creating a Pet Store
Application with
JavaServer Faces, Spring,
and Hibernate By Derek Yang Shen en3rgizer wrote: to:
Zakaria Chakih
if you provide me your
email, i could send
working project to you.
or feel free to write me
a letter to
en3rgizer[at]mail[dot]ru |  | Cover Story: What Is POJO
Programming? By Christopher Richardson Preet wrote: interesting
read... answers the what,
but, and what ifs..
Thanks! I am newbie in
this domain and this is
exactly what I was
looking for. |
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
|
SYS-CON FEATURED WHITEPAPERS  | AJAX and RIA Technology
Will Be Free for All: Sun
CEO By Java News 'Java's always been a RIA
platform - before the
world really wanted one,'
claimed Sun's CEO
Jonathan | Adobe's Kevin Lynch and
Microsoft's Scott Guthrie
to Keynote AJAX World RIA
Conference & Expo By RIA News Desk Two of the biggest
launches in Rich Internet
Application history took
place in 2007/2008 when
Adobe | Quest Software's JProbe
Now Available as Eclipse
Plug-In By Eclipse News Desk Quest Software announced
the latest release of its
Java profiler, JProbe
8.0, which is now offered
a | What Does the Future Hold
for the Java Language? By Joe Winchester Before Java I was a
Smalltalk guy. I remember
switching from one
language to the other and
the tippi | White Paper: "Ensuring
Code Quality in
Multi-Threaded
Applications" By Java News Desk Today, the world of
software development is
presented with a new
challenge. To fully
leverage this n | AccuRev and Rally
Software Partner to Scale
Agile Software
Development Best
Practices By SOA World Magazine News Desk AccuRev and Rally
announced a technology
partnership that will
integrate AccuRev
software change and | MyEclipse 6.5: The Maven
Tipping Point for 1
Million Java Developers By Eclipse News Desk Genuitec announced the
availability of MyEclipse
Enterprise Workbench 6.5;
Java's most compelling ID | AccuRev Leverages Web 2.0
Technology to Extend
Process Management Reach
Across the Organization By Web 2.0 News Desk AccuRev announced a new
AJAX-based Web Interface
and a native integration
with Microsoft Windows
Exp | Voyager Offers Android,
.NET CF, Java Runtime
Support By Wireless News Desk Recursion Software
released a private beta
version of their Voyager
mobile platform, with
powerful i | Is Open Source Good for
the Java Developer? By Orion Letizi Commercial open source
software has arrived.
There have been
commercial sponsors of
open source proj | NetBeans: It's Not Just
for Java Anymore By Tim Boudreau Java developers have had
a nice ride the last few
years. With ferocious
competition in the Java
tool | AJAX and Enterprise RIA
Tools - JSF, Flex, and
JavaFX By Max Katz 2008 is going to be an
important year for Rich
Internet Applications.
Most organizations are
deliver | Infrastructure
Virtualization Software
to Support Sun Logical
Domains By Virtualization News Desk Scalent Systems announced
support for Sun Logical
Domains (LDoms) server
virtualization and
partitio | Savvion BusinessManager
Turns Process Improvement
Ideas Into Real-World SOA
Solutions By SOA World Magazine News Desk Savvion announced it will
now be providing
customers with
human-centric process
solutions through Sa | Sun Microsystems Unveils
New Version of Java CAPS By SOA World Magazine News Desk Sun Microsystems
announced the
availability of Sun Java
Composite Application
Platform Suite (Java C | AdaCore Releases GNAT
Ada-Java Interfacing
Suite By Java News Desk AdaCore announced
availability of the GNAT
Ada-Java Interfacing
Suite (GNAT-AJIS), which
allows deve | Vega 3 Compute Appliance
Raises the Bar for Java
Performance By Java News Desk Azul Systems announced
that its Vega 3 Compute
Appliance recorded world
record results in the
indust | A Lightweight Approach to
SOA and BPM in Java Using
jBPM By SOA World Magazine News Desk SOA is mostly associated
to technologies such as
BPEL, SCA and Web
Services. But does SOA
really imp | JBoss Hits Amazon's EC2
Cloud By Maureen O'Gara Red Hat is beta testing
its JBoss Enterprise
Application Platform as a
solution on Amazon's
Elastic | Secrets Of The Masters:
Core Java Job Interview
Questions By Yakov Fain If you are planning to
hit the job market, you
may need to refresh some
of the Java basic terms
and |
SPONSORED BY INFRAGISTICS
|