Building Java Applications Using Oracle 9i JDeveloper[1]

 

Overview

JDeveloper is an integrated development environment (IDE) for Java programming. The 9i version includes many useful features to help design, develop, debug, and deploy all types of 3GL Java. JDeveloper’s wizards and code generators make the internal mechanisms of Java easier, enabling developers to solve many business problems using Java. Help with code organization and configuration management have also been included making the Oracle9i release of JDeveloper a giant leap forward from past versions of the product.

History

In 1997, Oracle licensed Java-based tools from Borland International. At the time, Borland's JBuilder was a strong Java development tool. By purchasing the rights to the JBuilder source code Oracle was able to speed up its entry into the Java development environment. The initial release in 1998 called “AppBuilder for Java” was similar to its JBuilder foundation. The product was renamed JDeveloper later in 1998 and there was a second release (2.0) in 1999. Through these early versions, the product was slowly maturing in order to function effectively in the Java environment. Meanwhile, behind the scenes Oracle was working on solving the nagging problem of Java programs connecting to relational database objects.

Since Oracle9i JDeveloper is built upon Java 2 Platform, Enterprise Edition, it sits on a stronger foundation than any other product in Oracle's history. Many earlier products had to make compromises because of the limitations of existing technologies and accommodations to backward compatibility. JDeveloper is based upon a relatively new technology that has vast support from other vendors and the backing of recognized standards.

Oracle9i JDeveloper provides a solid Java development environment. A web search for articles mentioning JDeveloper yields many positive reviews from the Java community. For writing Java to interact with an Oracle database, JDeveloper is a clear winner because of the BC4J layer.

Java Applications and Applets

Java applications are standalone programs that run within the Java Virtual Machine (JVM) on the client. They are deployed like any other client/server environment. Sun's Swing components are usually used to create the user interface of any Java application. Applets are similar but run in a JVM in a browser. It is a simple task to convert Java applications to applets or the reverse. Java applications start from a  main() method and are subclassed from window classes such as JFrame. Applets start from an init() method and are subclassed from the JApplet class. Deployment is the one area where Java applications and applets differ more since applets are deployed to an application server, so when users command the applet to be run, it is loaded and run within the browser. Although once popular, applets are now infrequently used since the creation of JavaServer Page (JSP) architecture. Java applications and applets allow developers to full featured applications. Java applications or applets, use the Java language primarily, as opposed to JSP pages, which use a combination of tag languages and Java.

Moving to a Java Development Environment

There are many competing Java development tools on the market including Visual Café, JBuilder and Forte. However, for working with an Oracle database, JDeveloper has no real competition. It is by far the best tool for building Oracle-based Java applications and an almost complete JSP solution.

For the 9i release, JDeveloper's IDE was completely rewritten in Java. The choice of Java means that JDeveloper may be run in the Java Virtual Machines (JVMs) of different operating systems with few, if any, changes. This makes JDeveloper extremely portable.

However, moving from a traditional client/server environment to a Java/Web environment is not a simple task. In the “good old days,” only one or two products and languages were needed to develop applications. Table 1 illustrates the tools and languages needed to develop different types of applications in a Java environment.

 

 

Oracle Developer Client/Server

Java Applications

Java Applets

JavaServer Pages (JSPs)

Tools

Oracle Form Builder

SQL*Server or TOAD

JDeveloper

SQL*Server or TOAD

Oracle Form Builder

SQL*Server or TOAD

Apache or IAS

Oracle Form Builder

SQL*Server or TOAD

Apache or IAS

DreamWeaver or FrontPage

Languages

SQL

PL/SQL

SQL

PL/SQL

Java

XML

JDBC

SQLJ

SQL

PL/SQL

Java

XML

JDBC

SQLJ

SQL

PL/SQL

Java

XML

JDBC

SQLJ

HTML

JavaScript

Security Issues

 

 

Firewalls

Secure Sockets

Encryption Keys

Firewalls

Secure Sockets

Encryption Keys

Table 1: Products and Languages needed for Application Development

 

The number of tools that a developer needs to master in a Java environment has increased dramatically when compared to the traditional client/server environment.  For JSPs in particular, the number of tools and technologies that need to be mastered is quite daunting.  JDeveloper will have to mature as a product or the underlying architecture will have to change before JSP development becomes popular in the Oracle environment.  There has even been a recent surge in discussions about resurrecting the idea of client/server-style architecture for the Web. The author is currently working on a project to investigate the idea of a thick client for the web (termed “thicknet”).  Anyone interested in further details is welcome to contact the author.   

The rule of thumb when working with any Java IDE is to try to reduce the amount of hand coding. Of course, expert Java programmers may produce code just as fast as a generator. However, generated code is consistent, predictable, and error free. Although it is not possible to create an enterprise-class application using only the wizards and existing components, these features give you a big head start and greatly minimize the supplemental code that you have to write. If you are careful about how elaborate your GUI becomes, the amount of code you need to write will be very small. The details that Java requires to make the code work, such as imports and constructors, can all be handled by the code generators and Property Inspector.

The JDeveloper Integrated Development Environment (IDE)

JDeveloper IDE allows users to quickly and easily access commonly used Java components. A Java component corresponds to a control in Windows and other environments. Components (JavaBeans) are used to create Java client applications and not servlets or JSP applications. In most cases, a component represents a visual object, but may also refer to nonvisual data control objects. Similar to the way in which Forms developers work, using the JDeveloper IDE, you can insert components into your project, define events,  and set many properties without having to write any code. However, JDeveloper creates 3GL code and Forms is a 4GL tool. The code generated by JDeveloper is ready to run, error free, and can be edited using the Code Editor.

JDeveloper’s Component Palette provides an easy-to-use interface for creating components and generating code. The Component Palette adjusts the pages available based upon which type of file is open in the Code Editor.

Business Components for Java (BC4J)

JDeveloper's Business Components for Java (BC4J) framework and associated code generators make JDeveloper the tool of choice for Oracle developers building Java or web-based applications. BC4J is supported by a programming protocol or standard that describes how to build classes that will interact with a relational database.

Prior to the existence of BC4J, connecting a Java-based application to a relational database was an extraordinarily difficult task. Complex Java Database Connectivity (JDBC) and/or SQL embedded in Java (SQLJ) code was required in order to coordinate any Java front-end with the database. Data caching, batch updates, table locks and commits were all difficult to contend with. JDeveloper’s BC4J components provide a functional interface to the database. They can be easily created using the built-in code generators or wizards in order to make the Java code interact with relational database tables. This automatically generated code allows Java applications to safely interact with the database, solving the many of the security, locking, and performance problems. This generated code relies heavily on an Oracle-supplied Java library, and requires only a small amount of code to be created by the BC4J wizards.

To enable developers to create Java applications with a user interface, Oracle supplied extensions to selected Swing components that attached directly to the BC4J-generated elements. While BC4J proved to be conceptually solid, and able to handle complex applications, the Data Aware Components (DACs) built on Sun's InfoBus architecture proved problematic. After the industry abandoned the InfoBus architecture, Oracle also abandoned all of the InfoBus technology in favor of JDeveloper version 9i's support for Sun's Model-View-Controller (MVC) architecture (implemented in JDeveloper as the client data model).

In JDeveloper projects, BC4J components will have both XML and Java files associated with them. The XML file holds the metadata that defines the business component, and the Java file holds the methods that implement the business component. The .java file contains get( ) and set( ) methods, which dynamically generate insert, update, and delete statements at runtime.

 

Creating Java Applications

JDeveloper provides complete support for Java applications, including visual editing and property setting in a Forms-like interface. You can build applications of the same or greater complexity and sophistication as was possible using products such as Forms Developer. However, you will not be able to build as quickly using JDeveloper as you can with Forms Developer. The JDeveloper wizards are not sufficiently mature for JDeveloper to compete effectively with Forms Developer as a RAD development tool.

While Forms Developer is a true 4GL, where properties of objects are stored in an internal repository, JDeveloper is actually a code generator and code organizer.

Although you interact with the JDeveloper wizards and IDE areas as in a 4GL environment, you are really generating Java code. Frequently, the application development process goes beyond the capabilities of the JDeveloper wizards, and manual intervention is required to modify property settings that the wizard assigns or to add code that the wizard does not generate.

When you build Java applications and applets using JDeveloper, your work is organized within workspaces and projects just as with all other JDeveloper development. The first step in application development is to build or add the BC4J project or projects that will support your program. These BC4J projects must be open in the same workspace as your application. Next you build the user interface portion of the program. This will usually reside in its own project or projects within the same workspace as the BC4J project.

Should You Build a Java Application or Applet?

Are you going to build your program as a Java application or as an applet? If you are going to deploy it as an applet, you may want to limit the size of your program. You may want to break
it up into several smaller programs to limit the size of each portion.

Security considerations may influence your decision. Many programs may be difficult to deploy as applets. If your program needs to perform operations that are usually considered unsafe in
a browser (for example, create/delete/read hard disk files, or write files to the local hard disk), you will have to set up extra security files to give your applet the ability to override the security controls inherent in your browser. This adds a level of complexity to your deployment that many may find challenging.

How Many Independent Programs Will You Use?

One of the temptations when writing programs in Java is to write very complex, graphics-intensive programs just because it is possible. For developers who have been restricted for years as to what they could build in a 4GL environment, this new capability can be very tempting. The dream of building a “super program” that can support a major portion of a complex system can be realized. But this new capability can lead to programs that are so large that they suffer from poor performance and are difficult to maintain.

There is no restriction on the number of physical programs that make up the construction of
a Java application. One advantage of a 3GL environment is that you can partition your code any way you like.

Very large programs take longer to load and may consume enough memory resources that the program runs slowly. It is easier to manage a few programs of moderate size than one giant program. Large programs should be partitioned into manageable chunks.

Breaking Java Applications into Separate Classes

When you build a master-detail Java application using the JClient Form Wizard, the tool generates four classes that are nested inside each other. You can break your program into classes any way that you like. In building this Java application by hand, it would be logical to combine the first two classes into a container class, but it is recommended that you keep the master and detail classes separate. Using one class for each table is a good way to organize your code.

How Many Directories, Workspaces, and Projects Will You Create?

You have a lot of flexibility in how you manage your program within JDeveloper. Workspaces and projects are merely logical folders where you place your work. You can place many programs in the same workspace or split a single program across multiple workspaces. You can build reusable components that can be used by several programs, and you can store your work in multiple folders/directories in the operating system.

JDeveloper is well suited to manage up to a few dozen classes in a single project and can support several projects in the same workspace. However, the product supports neither logical groups of classes within the project nor logical groups of projects in the workspace. So, for very large programs, the developer will be able to significantly improve the readability and manageability of the code by partitioning the code into several projects, and perhaps even several workspaces. Oracle9i JDeveloper allows you to have multiple workspaces open at the same time, and this feature allows you to work on many logically distinct application areas at the same time.

What Is the BC4J and Data Validation Strategy?

There are several possible strategies for BC4J usage. The main architecture-level BC4J-related decision to be made is where the data validation will take place.

Data validation can be supported in many places in a Java application. The selection of the validation location is the same kind of decision that had to be made in a 4GL environment. In a 4GL environment, a decision must be made about whether the validation would take place in the database or in the application. In a Java application, data validation can be accomplished in one of three places: in a database, within BC4J entity objects, or in the user interface portion of the application.

In addition, data validation can take place in the BC4J view objects, but that does not make much sense and is only recommended when there is a specific validation requirement for a particular user-interface screen.

What Type of Container Layout Should Be Used?

Laying out the containers (frames, panes, and panels) in your Java application or applet is something that should be accomplished before you get very far into your application. It is quite easy to change your mind about the container structuring at any time during development if you are a skilled Java developer. If you want to rely on the JDeveloper wizards to lay out your containers for you and to make sure that they are bound to BC4J correctly, then it is much easier to think through the structure before doing much development.

How Many Packages Will You Create and How Will You Name Them?

Packages govern the deployment, internal .jar file structure, and the work area subdirectory names for your program. They are also the logical internal storage area names for your program. The point here is that the package names are used in many places. Changing package names after development can be quite difficult. Similarly, going from a single-package structure to a multiple-package structure after significant development has been done is difficult to implement.

Changing the default package name in a JDeveloper project (in the project settings dialog) will only change the package for future objects. Anything already created will belong to the original package.

Other Issues

In addition to trying to figure out what code to use, it is also often difficult to determine where to put the code. The scope and visibility of Swing components does not always lead to an obvious conclusion about where to place the appropriate code.

As in any new product, the first time you try to do something it will take some time to figure it out and get it to work. With JDeveloper and Swing components, you will quickly need to go beyond JDeveloper's default behavior. Because the possibilities are virtually limitless, you will be figuring out many more little tricks than would have been needed in a product like Oracle Forms. Two of the authors estimated that to be an efficient developer in Forms, you would need about 1000 tips and techniques at your fingertips. With years of experience, it is possible to keep this number of tricks in memory. Even if the exact code syntax needs to be looked up, it is usually easily found.

To be an excellent Java programmer, the number of techniques required on a day-to-day basis is probably closer to 10,000 and therefore not manageable in one developer's head. Even after years of experience, you will still be constantly finding new things that you need to do and others that you have forgotten. Too much information must be absorbed.

There is usually no unique way to accomplish a task in Java, and often there are a number of equally good ways to do something. Even the way in which a basic application is built with enclosing frames and panels is not unique. The JDeveloper wizards have evolved over time, making significant modifications to the way in which generated applications are constructed.

Working with Swing Components in JDeveloper

Swing components are Java program units written to conform to a specific (JavaBean) protocol.
Swing components are used to control the layout and visibility of your data. All Swing components have three aspects to their use as described in the J2EE Model-View-Controller (MVC) architecture:

·         Model How the component accesses data

·         View The component's look-and-feel

·         Controller The component's response to events

 

The client data model is an implementation of the MVC Model layer. Most Swing components are visual in nature, which provides the View layer. The event code you write for each component corresponds to the Controller layer.

Using Swing Components

Swing components can be used as easily in Oracle9i JDeveloper as any control in a 4GL product. Objects in the JDeveloper environment can be added in any of three ways. They can be placed into the Structure window in a tree structure, dropped directly into the UI Editor, or added to the code. Getting the components on the screen and coupling them to BC4J is very straightforward. With practice, you can quickly be as productive at adding components as in any 4GL tool such as Oracle Forms Developer.

Trying to control the objects you have created reveals both the blessing and the curse of using Java. Java is almost limitlessly flexible. You can do just about anything you want; however, almost anything you might want to do other than dropping a Swing component into your application and setting properties in the Property Inspector requires a good deal of work to figure out how to achieve the desired result.

Even a simple-sounding task such as making a field wider, adding a double-click event, or changing the color of a field in a specific context may be a frustrating experience if you do not have some guidance. Using the right layout manager may help. It may take you a few tries until you find the right clue in the right Java book or find the answer to your question on an Internet list server to solve some of the problems you may encounter.

 

Adding Swing Components to a Program

Swing components are the most often used Java UI components. Adding Swing components to a program is very simple. You can add many components at once by using the high-level wizards in JDeveloper or one at a time by using the UI Editor. Of course, you can also add them by editing the code itself.

If the component you want to add is in the Component Palette (while the UI Editor is open), you can select it and click either on the UI Editor where you want the component to appear or in the Structure window in the desired position. It is usually easier to add components to the Structure window and then to adjust their position in the UI Editor. It is important to have each component in its correct logical place. Sometimes it is hard to position an object in the correct place (usually in a particular JPanel) by using the UI Editor, because a layout manager imposes a particular behavior.

When you add a Swing component using the Component Palette, JDeveloper writes code into your program. For example, when you add a button (JButton) using the UI Editor, the wizard first adds a line of code that declares the button as shown here:

 

private JButton jButton1 = new JButton();

 

Next, in the jbInit() method of the code, the wizard will typically set one or more properties of the component. In this case it only sets a single property as shown next:

 

jButton1.setText("jButton1");

 

Finally, it adds the component to the container in the position in a logical place as shown here:

 

dataPanel.add(jButton1, BorderLayout.CENTER);

 

In addition, it adds the appropriate import statements so that the proper class files are available. In this example, JDeveloper adds the following code:

 

import javax.swing.JButton;

 

If you rename the component or modify properties, the code will be updated to reflect the change.

 

Swing Component Categories

Swing components are usually written very flexibly so that virtually any aspect of the component can be changed to meet your requirements. The various types of Swing components can be loosely grouped as follows:

·         Container Windows, frames, panes, and panels. Components that act as areas on the screen and into which you place visual objects such as fields and labels.

·         Data Text fields, checkboxes, tables, trees, charts that display data.

·         Action Buttons, sliders, free-standing scrollbars, and so on. Components that control other components, generate actions, generate a value, or respond to events.

·         Static Labels and graphic items that are not data related.

·         Nonvisual Timers and similar components that are not displayed.

·         Dialog Help messages, modal alert boxes, and similar components.

 

Using most of these components is pretty straightforward. Containers are a bit more complex and require a bit of explanation.

 

Creating Application Code in JDeveloper

JDeveloper is an application development tool that act as a blank sheet of paper for the sophisticated do-it-yourselfer, or as a code generator for those who prefer developing applications by using 4GL techniques such as drag and drop. Using JDeveloper, you can also automatically generate basic database interface code so that you can customize the results.

Coming to an understanding of Java and JDeveloper is like trying to learn English and a computer word processing program at the same time. You should have some experience with other computer languages and application conventions before you leap into this type of effort.

The first major difference between the traditional environments and the JDeveloper environment is that in some development environments, the user interface and its interaction with the database are inseparable. In JDeveloper, you create files in logical containers called projects. Each program will usually consist of two types of JDeveloper projects:

·         Business Components for Java built and written using Java and XML to provide the database interaction components

·         User interface components and logic built and written mainly using Java and
Java-related languages

JDeveloper is optimized to assist you in producing a multi-tier architecture for your database applications. The power behind JDeveloper to produce a multi-tier application is centered on BC4J. A multi-tier architecture encourages the logical separation of the following elements:

·         Client tier The client tier supports the data access requirements of the end user. Complex GUIs can be supported using application code over the Internet, browser-
scripting capabilities, and/or by installing application code on the client's desktop and running it outside of the browser.

·         Application tier The application tier is where the business logic is generally enforced and data access is coordinated. Application servers contain business logic that can be reused across a wide variety of clients and applications, thus making it possible to share physical and logical resources across multi-tier architectures. The application tier can also contain specialized reporting and analysis tools to handle complex business intelligence requirements. In addition, the application tier (which contains the Web Tier and Business Tier of the J2EE architecture) can serve HTML user interface code that displays in a browser.

·         Database tier The database tier is where the data is stored and queried. This layer may also contain links to other external data sources and applications, which may be members of the overall architecture.

 

General Development Steps

For many Java applications, you will need to build a BC4J project first. You can create a data form that interacts with the database through the BC4J objects.

The general steps to create application code in JDeveloper are as follows:

1.        Create a workspace.

2.        Create a BC4J project if the application will connect to the database. This creates a separate project for the application files.

3.        Define and test the BC4J objects.

4.        For the user interface project to have access to the BC4J objects, you need to create a client data model (.cpx file) at design time using the BC4J Client Data Model Definition Wizard. The .cpx file is a container that stores the client data model, and connections to the BC4J application module in the middle tier. You can modify this definition. The Java code will only reference the name. This allows you to redeploy or change definitions without changing any of the code.

5.        You must already have a BC4J project in the same workspace before you can complete this wizard. The client data model binds the BC4J application module to the user interface project. JDeveloper’s data binding feature allows you to partition the client application so that different user interface styles can use the same data layer.

6.        Create an application user interface project using the high-level wizards

7.        Add code for forms and other user interface objects. This code uses objects in the BC4J project.

8.        Test the user interface code with the BC4J project.

9.        Deploy the BC4J project and the user interface project.

 

These steps can be used to create a simple Java application. The JDeveloper wizards can be used to create all of the code. To summarize the process of creating a Java application using the wizards:

·         Create an image of the database using entity objects and associations.

·         Create application-specific sets of view objects and view links, which are then assembled into one or more application modules.

·         Create a client data model for binding the BC4J application module to the user interface.

·         Create the user interface application

 

Because JDeveloper allows you to write your own Java code independent of the generator, applications will not suffer from any of the common functional limitations of 4GL. These limitations do not exist in Java applications. Almost anything you can imagine can be supported. Also, the underlying business logic is still very flexible. As with any other tool, once you become familiar with the JDeveloper IDE, it will be easier to learning to use the features of JDeveloper.

Using the JDeveloper  high-level wizards is not the only way to build applications. You can also create an equivalent application by building all of the structures using lower-level wizards. Everything may be placed in one large procedure or divided into multiple procedures that call each other.

For example, to create a simple master-detail application using JDeveloper, you use the JDeveloper Component Palette, UI Editor and Structure window to add panels, containers, scrollers, navigation bars, labels and fields. The JDeveloper panel class is an implementation of the JPanel interface. JPanel is an Oracle-supplied panel that is an extension of the Swing JPanel, modified to support BC4J. An example of the JDeveloper interface is shown in Figure 1:

 

 

 

 

 

 

Figure 1: JDeveloper application development interface

The Structure window (lower left) displays the information relevant to the active Editor UI, Code, etc.) If the UI Editor is active, the UI tree structure perspective of the objects will be shown. Different layout properties are available

Some amount of manual effort is required to build a Java application. For example, labels and fields must be handled independently. Separate panels and scroll panes are necessary to display a multi-record department structure as a detail to a master location record. Unlike Oracle Forms where everything you could manipulate on an object is visible in its associated Property Palette, this is not the case in the Java environment. The JDeveloper Property Inspector acts as a limited functionality wizard for Swing components. In addition to the list of Property Inspector items, other things can be modified in these structures. These modifications must be made in the code itself.

It is strongly recommended that you purchase the official Sun reference manual so that you can understand this code (The Java™ Class Libraries, Second Edition, by Patrick Chan, Rosanna Lee, Doug Kramer; Addison-Wesley, 1998; ISBN: 0201310023). As these libraries evolve, the functionality of the components may change somewhat. Future releases of JDeveloper may eliminate some of the work that you currently need to do by hand.

 

 

About the Author

Dr. Paul Dorsey is the founder and president of Dulcian, Inc. an Oracle consulting firm specializing in business rules and web based application development. Paul is the co-author of six Oracle Press books on Designer, Database Design, Developer, and JDeveloper, which have been translated into seven languages.  He is President of the New York Oracle Users Group and a Contributing Editor of IOUG's SELECT Journal.  In 2001, Dr. Dorsey was honored by IOUG as volunteer of the year and by Oracle as one of the six initial honorary Oracle 9i Certified Masters.  Paul is also the founder and Chairperson of the ODTUG Business Rules Symposium, now in its fourth year. He can be reached via email at paul_dorsey@dulcian.com.

 



[1] Much of the material in this paper is adapted from The Oracle 9i JDeveloper Handbook (Koletzke, Dorsey & Faderman), Oracle Press, 2003.