JBuilder 9 Personal Tutorial I

Speed coding and debugging with an integrated, extensible source code editor, graphical debugger, compiler, visual designers, timesaving wizards, sample applications, and support for Java standards. Get started quickly using the included tutorials. Develop on the Windows, Linux, and Solaris platforms. Rapidly build Java applications using the Borland AppBrowser™ integrated development environment, refactorings, build and configuration management tools, CVS version control, and Two-Way-Tools™. Easily create JavaBeans with BeansExpress™. Speed coding and reduce syntax errors with CodeInsight™ and ErrorInsight™ technologies.

Many developers prefer to learn by doing. If this is you, follow the steps outlined in this tutorial to learn about using JBuilder's integrated development environment (IDE) to create applications. The tutorial shows how to

The JBuilder development environment

The JBuilder integrated development environment (IDE) consists of a window that contains several panes and panels for performing most development functions: editing, visual designing, navigating, browsing, comparing, modeling, building, compiling, debugging, and running. This window is the JBuilder AppBrowser.

JBuilder



1. Creating a new project

Before creating an application in JBuilder, you must first create a project to work in. JBuilder uses a project file with a .jpx extension to organize the application files and maintain the settings and project properties. The Project wizard can create a project HelloWorld for you.

  1. Choose File | New Project to open the Project wizard.

  2. Make the following changes to the appropriate fields in Step 1 of the Project wizard:

    1. Type HelloWorld in the Name field.

      Note: As you type the project name in the Name field, the same name is entered in the Directory field. By default, JBuilder uses this project name to create the project's directory name and the package name for the classes. The package name is forced to lowercase according to the Java convention for naming packages. Projects in JBuilder are saved by default in the /<home>/jbproject/ directory. The home directory varies by platform.

    2. Accept jpx as the project file type.

    3. Check the Generate Project Notes File option.

      When you check this option, the Project wizard creates an HTML file for project notes and adds it to the project.

    Step 1 of the Project wizard should look similar to this:

    Project wizard Step 1

  3. Accept all other defaults in Step 1.

  4. Click Next to go to Step 2 of the Project wizard.

    Project wizard Step 2
  5. Accept the default paths in Step 2. Note where the compiled class files, project files, and source files will be saved.

    Step 2 of the Project wizard should look similar to this:

  6. Click Next to go to Step 3 of the wizard.

  7. Make the following changes in the appropriate fields of Step 3:

    1. Accept the Encoding and Automatic Source Packages defaults.

    2. Type Hello World in the Title field of the class Javadoc fields.

    3. Enter your name, company name, and a description of your application in the appropriate optional fields.

      Note: The information in the class Javadoc fields appears in the project HTML file and as optional header comments in the source code.

    Step 3 of the Project wizard looks similar to this:

    Project wizard Step 3

  8. Click the Finish button.

    Two files, HelloWorld.jpx and HelloWorld.html, are generated by the wizard and appear in the project pane located in the upper left of JBuilder's AppBrowser.

  9. Double-click HelloWorld.html, the project notes file, to view it in the content pane located in the center of the AppBrowser. Note that it contains the project name, author, company, and description information you just entered in Step 3 of the Project wizard.

2. Creating a project from existing files

The Project For Existing Code wizard allows you to create a new JBuilder project using an existing body of work. When you use this wizard, JBuilder scans the existing directory and builds paths that are used for compiling, searching, debugging, and other processes. Any JAR or ZIP files that aren't already in libraries are placed in a new library and added to the project. Project libraries are listed on the Required Libraries tab of the Paths page of Project Properties (Project|Project Properties).

To access the Project For Existing Code wizard,

  1. Select File|New. The object gallery appears.
  2. Select the Project tab.
  3. Double-click the Project For Existing Code icon.

Selecting the source directory and name for your new JBuilder project

Step 1 sets your project directory, name, type, and project template.

  1. Choose the directory where the existing project or source tree is located. Click the ... button to browse to it. JBuilder scans the selected directory for such files as class, source, JAR, and ZIP and places them in the appropriate directories within that directory.

  2. Enter a name for the new project. JBuilder uses the project name as the package name by default, so if you have an existing package name use that as the project name. JBuilder's wizards also use the project name as the package name, which can be edited in the wizards.

  3. Select your project template:

  4. Choose whether to generate an HTML project notes file. The initial information in this file, such as title, author, and description, is generated from the class Javadoc fields set in Step 3 of the Project For Existing Code wizard. You can also add notes and other information in this file as needed.

  5. Click Next to go to Step 2.

Steps 2 and 3 of the Project For Existing Code wizard are identical to the Project wizard.

If your project requires specific libraries, you can add them to the project on the Paths page of the Project Properties dialog box. To set the main class to run your project, choose the Run page of the Project Properties dialog box.

3. Opening an existing project

There is one way to open an existing project for the first time: use File|Open Project. There are two ways to open an existing project you have opened before: either the File|Open Project command or the File|Reopen command.

To open a project using the File|Open Project command,

  1. Choose File|Open Project. The Open File dialog box appears.
  2. Navigate to the directory that contains the project file you want to open.
  3. Select the project file and click OK or press Enter. You can also double-click the project file to open it.

To open a previously opened project with the File|Reopen command,

  1. Choose File|Reopen.
  2. Choose the project you want to open from the list of previously opened projects.
    The project file and its source files will appear in the project pane.

To open a file in the content pane, you may do one of four things:

To view a project in a new AppBrowser,

  1. Select Window|New Browser.
  2. Select File|Open Project and navigate to the file in the Open Project dialog box.

If you have more than one AppBrowser open and the same files open in multiple AppBrowsers, changes you make in one AppBrowser will be reflected immediately in the same file open in the other AppBrowser. This keeps all your working versions of a file congruent.

Note: All open projects are available in all AppBrowsers from the Project drop-down list.

4. Generating your source files

The Application wizard creates .java source files that are added to the project you just created.

To generate source files for your application using the Application wizard, follow these steps:

  1. Choose File | New or click the New button [Toolbar] on the main toolbar to open the object gallery.

    [Object Gallery]

  2. Select the General tab and double-click the Application icon to open the Application wizard.

  3. Accept the default package name, helloworld, in Step 1 of the Application wizard.

    By default, the wizard takes the package name from the project file name, HelloWorld.jpx.

  4. Type in HelloWorldClass in the Class Name field.

    This is a case-sensitive Java class name.

  5. Check Generate Header Comments.

    When you select this option, the project notes information you entered in Step 3 of the Project wizard appear at the beginning of each source file that the Application wizard generates.

    Step 1 of the Application wizard should look like this:

    [Application Wizard Step 1]

  6. Click the Next button to go to Step 2 of the Application wizard.

  7. Type HelloWorldFrame in the Class field to name the Frame class.

  8. Type Hello World in the Title field.

    This text appears in the title bar of the frame in your application.

  9. Check all of the options for additional application features: Generate Menu Bar, Generate Toolbar, Generate Status Bar, Generate About Dialog, and Center Frame On Screen. The wizard generates the basic code to support these features.

    Step 2 of the Application wizard should look like this:

    [Applet Wizard Step 2]

  10. Click the Finish button.

    The new .java source files and toolbar images are added to your project and displayed as nodes in the project pane. The source code for HelloWorldFrame.java is open in the content pane as shown in the following image.

    The message pane appears only when a message is displayed. Therefore, you won't see the message pane yet if you are following these steps.

    Note: Step 3 (defining and creating a new runtime application configuration) is skipped because it isn't a necessary to create a new application configuration for your HelloWorld application.

    Note: An automatic source package node named helloworld also appears in the project pane if the Enable Source Package Discovery And Compilation option is enabled on the General page of the Project Properties dialog box (Project|Project Properties).

    AppBrowser elements

    [AppBrowser]

  11. Choose File|Save All to save the source files and the project file.

    Note: The source files are saved to: /<home>/jbproject/HelloWorld/src/helloworld.
    The class files generated from the source files by the Java compiler are saved to: /<home>/jbproject/HelloWorld/classes/helloworld.


If you don't select any application feature, choose File | New Class.

For example #2, we are going to create a new project named myproject in c:/Ruby/TA directory:

  1. Choose File | New Project. In the Project wizard,
    step 1: select name and template for your project.
    Name (your project name): myproject
    Directory (the directory where your project is to be saved):c:/Ruby/TA/myproject
    Click Next.
    step 2: Specify project paths.
    Output path (the directory where .class files are to be saved): c:/Ruby/TA/myproject/classes
    Backup path:c:/Ruby/TA/myproject/bak
    Working directory:c:/Ruby/TA/myproject
    Source ( the directory where .java source codes are to be saved:c:/Ruby/TA/myproject/src
    Test :c:/Ruby/TA/myproject/test1
    Click Next.

    JBuilder UI

    step 3: Specify general settings: title, author,... e.g.,
    @author: not attributable
    Click Finish.
  2. Choose File | New Class. In the New Class wizard,
    Class name: myclass
    Then Choose options such as generat main method, ....
    Click OK.
  3. Choose File | Save All.
The new window should look like the following and if you check c:/Ruby/TA/myproject directory, the myproject.jpx file is created.

In the project pane, you'll see the project file and the source file that now belongs to the project.

Project pane

You can also add a new empty file to the project; choose File | New File, specify the new file name and type, and choose OK.

5. Editing your source code

You can change information in the About box by directly editing the code. The default application version created by the Application wizard is version 1.0.

  1. Double-click HelloWorldFrame_AboutBox.java in the project pane to open the file.

    The content pane changes to the source view where you can edit the code in the editor.

  2. Choose Search|Find to open the Find/Replace Text dialog box.

  3. Type the following line of code in the Text to Find list box:
    String version = "1.0";
    
  4. Click Find.

    The editor finds the selected text.

    [Hello World code]

  5. Select 1.0 and enter 2.0 inside the quotes.

  6. Choose File|Save All.
Click here for detailed editor tutorial.

6. Compiling and running your application

Now, compile and run the application. Compiling is the process of running the Java compiler. The compiler, which translates source code into Java bytecode, generates .class files.

  1. Choose Run|Run Project or click the Run Project button Run button  on the JBuilder toolbar to compile and run your application.

    Tip: You can also select HelloWorldClass.java in the project pane, right-click, and choose Run using "HelloWorldClass".

    First, the message pane opens displaying the run process. Then, your application is displayed and should look like this:

    [Hello World application]

    Note: The running application shown above reflects the Metal Look & Feel.

  2. Choose File|Exit in the "Hello World" application to close it.

  3. Click the Close button on the HelloWorldClass tab in the message pane to close any messages.

For example #2, the detailed process is following:

Building, compiling, and running your project

To run your project, choose Run | Run Project or click Run Project button from the menu. The Runtime Configuration Properties dialog box appears. Select main class for your project from the pop-up window.

Editor

Click OK, the result will be shown in the message pane.

Editor

To set the main class and VM parameters for your project, go to the Run page of the Project Properties dialog box (Project | Project Properties or Run | Configurations ).

There is a very good tutorial about Compiling, running, and debugging in the Help | Tutorial. It is located at Contents | Builing Applications with JBuilder| Tutorials: Building Applications | Tutorials: Compiling, running and debugging. This step-by-step tutorial shows you how to start and stop the debugger, set a breakpoint, step into and step over a method, and set a a local variable watch to find and fix syntax errors, compiler errors, and runtime errors.

7. Running your application from the command line

You can also run the application outside the JBuilder environment from the command line.

Note: The <jdk>/bin/ directory which contains the java command must be on your path. If java is on your path, when you type java at the command line, information explaining the command should display. If it's not on your path, you need to run the application from within the <jdk>/bin/ directory.

To run the application, assuming java is on your path,

  1. Open the command-line window.

  2. Run the application with the following command on one line at the command prompt:
    java -classpath 
    /<home>/jbproject/HelloWorld/classes helloworld.HelloWorldClass
    

    Note: For Windows, use a backslash (\).

    This command should be in the following form:

    java -classpath classpath package-name.main-class-name
    

    In this example,

8. Debugging your program

You can debug both local and distributed applications, including servlets, JSPs, applets, EJBs, and unit tests. To debug files in your project, choose Run | Debug Project. Your program may be compiled. When debugging, you can view threads and data values and control your program's execution. The debugger UI, consisting of the debugger views, the toolbar, the session tab and the status bar, is displayed in the message pane.

Debugger user interface

There is a very good tutorial about Compiling, running, and debugging in the Help | Tutorial. It is located at Contents | Builing Applications with JBuilder| Tutorials: Building Applications | Tutorials: Compiling, running and debugging. This step-by-step tutorial shows you how to start and stop the debugger, set a breakpoint, step into and step over a method, and set a a local variable watch to find and fix syntax errors, compiler errors, and runtime errors.

9. Using Javadoc

The tutorial about Javadoc is located at Help | Building Applications with JBuilder | Building Applications | Creating Javadoc from source files.

10. Preparing your application for deployment

The Archive Builder collects all the files needed to distribute your program and can archive them into a Java archive file (JAR file).

To deploy your application:

  1. Choose Wizards|Archive Builder to open the Archive Builder.

  2. Select Application from the Archive Type drop-down list.

    [Archive Builder Step 1]

  3. Click Next to go to Step 2.

  4. Accept the defaults in Step 2.

    Note that HelloWorld.jar will be saved to the HelloWorld directory.

    [Archive Builder Step 2]

  5. Accept the defaults in Steps 3 through 5 and click Next in each step.

  6. Click Finish in Step 6 to close the Archive Builder.

    An archive node called Application appears in the project pane. You can modify this file by right-clicking and selecting Properties.

  7. Right-click the Application node and choose Make or choose Project|Make Project "HelloWorld.jpx" to compile your application and create the JAR file.

    The Archive Builder gathers all the files in the project's output path (Project|Project Properties|Paths) into the JAR file.

  8. Click the expand icon next to the Application archive node to expand the node and see the HelloWorld.jar archive file.

  9. Double-click the JAR file in the project pane.

    The manifest file appears in the content pane and the contents of the JAR file appear in the structure pane.

    Archive viewer

  10. Save your project.

11. How to submit assignments

Coming later...