Data management and data persistence in Java-EE applications

Source: Internet
Author: User
Tags object serialization serialization

This article analyzes the two data management policies available on the Java platform: Java object Serialization and Java Database Connectivity (JDBC). Although these two data management strategies do not have a superior or inferior problem in nature, JDBC easily wins when managing enterprise information systems. In this article, Java developers g.v.b. Subrahmanyam and Shankar Itchapurapu describes both serialization and JDBC, and through discussions and examples, shows you why JDBC is your best choice.

When you are building an enterprise information system, you need to ensure that enterprise data is stored, retrieved, and displayed in an efficient manner. For all businesses, data is a unique, maximum asset. All software systems involve data, so the importance of data cannot be overemphasized.

The data management capabilities of an application include four basic operations, and typically, these four actions are required for enterprise data: Build, retrieve, update, and delete (i.e. CRUD). Managing data in an enterprise system involves consistently and successfully performing CRUD operations over a long period of time without having to change frequently the code that actually performs these operations. In other words, managing data means developing robust, scalable, and maintainable software systems to ensure successful CRUD operations that can be performed in a consistent manner during the lifetime of the software.

This article discusses two of the available data management strategies in Java-EE: The serialization of a Java-based object and the Java database Connection (JDBC). We'll look at the pros and cons of these two approaches. Both of these data management strategies do not exist in essence. In a particular implementation, the availability of a policy depends on the scope of the project (the range of activities that appears in the system environment), the context of the system (the set of values driving the System/Subsystem runtime), and other external factors. However, Java serialization is not suitable for enterprise systems, and its data needs to be organized with a well-defined structure such as an RDBMS. We'll start by quickly browsing Java object serialization and then looking at some of the more important aspects of JDBC to see how the latter achieves some of the key features that the former lacks.

This article does not intend to make a comprehensive introduction to Java object serialization or JDBC. For more information on these two technologies, please review the Resources section.

Java Object serialization

Object serialization is the simplest Java persistence policy. Object serialization is the process of translating an object graph into a linear sequence of bytes. Object graphs are some of the relationships that are implemented as the result of object inheritance, association, and aggregation. The non transient instance properties of an object are written to persistent storage in bytes. The value of an instance property is the value in memory when the execution time is serialized. If a Java object is serializable, it must implement at least the Java.io.Serializable interface, which has the structure shown below:

package java.io;
public interface Serializable
{}

As you can see, the Java.io.Serializable interface does not declare any methods. It is a mark or token interface. It tells the Java runtime environment that the implementation class is serializable. Listing 1 shows a sample class that implements the interface.

Listing 1. Myserializableobject.java

import java.io.Serializable;
public class MySerializableObject extends MySuperClass implements Serializable
{
  private String property1 = null;
private String property2 = null;
public String getProperty1()
{
  return property1;
}
public void setProperty1(String val)
{
  property1 = val;
}
public String getProperty2()
{
  return property2;
}
public void setProperty2(String val)
{
   property2 = val;
}
   private void writeObject(ObjectOutputStream out)
   throws IOException
   {
     out.writeObject (getProperty1 ());
     out.writeObject (getProperty2 ());
   }
   private void readObject (ObjectInputStream in)
   throws IOException, ClassNotFoundException
   {
    setProperty1 ((String) in.readObject ());
    setProperty2 ((String) in.readObject ());
   }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.