鹰翔宇空

学习和生活

BlogJava 首页 新随笔 联系 聚合 管理
  110 Posts :: 141 Stories :: 315 Comments :: 1 Trackbacks

原文引自:http://www.oracle.com/technology/obe/obe1013jdev/introide/introjdevide.htm

                                                     Introduction to the JDeveloper IDE

Introduction to the JDeveloper IDE

This tutorial provides a tour of major components in Oracle JDeveloper 10g, and shows you how they are used to build a basic application.

Approximately 20 minutes.

Topics

This tutorial covers the following topics:

Launching JDeveloper 10g

Creating Your First Application

Creating Your First Java Class

Using the Code Editor with Your Java Class

Debugging Your Java Programs

Place the cursor over this icon to load and view all the screenshots for this tutorial. (Caution: This action loads all screenshots simultaneously, so response time may be slow depending on your Internet connection.)

Note: Alternatively, you can place the cursor over an individual icon in the following steps to load and view only the screenshot associated with that step. You can hide an individual screenshot by clicking it.

Overview

In the tutorial, you will learn how to create a simple Java class. Using your new class, you then explore some of the features of the JDeveloper IDE, including the Code Assist and the Debugger..

Back to Topic List

Prerequisites

Before you begin this tutorial, you should:

1.

Have access to or have installed Oracle JDeveloper 10g Release 3 (10.1.3) Production edition. You can download it from Oracle Technology Network.

 

2.

Start JDeveloper. Double-click the JDeveloper executable (jdeveloper.exe) found in the root directory where you unzipped it..

If the Migrate User Settings dialog box opens, click NO.

Close the Tip of the Day window.

Back to Topic List

Launching JDeveloper 10g

1.

Once loaded, the JDeveloper IDE appears.

 

2.

The very first time you open JDeveloper, the Start Page displays. You can re-invoke the Start Page later, by choosing Help | Start Page.

Notice the various options available to help you learn about JDeveloper.

 

Back to Topic List

Creating Your First Application

1.

By default, the JDeveloper IDE displays the Application Navigator on the left side of the window. This is the main pane from which you access the components of your application.

The structure of the Applications Navigator is hierarchical and supports applications, projects, images, .html files, and more.

2.

To create an application, right-click the Applications node and select the New Application... option.

The Create Application dialog displays.

Note:

The application is the highest level in the control structure. It is a view of all the objects you need while you are working. An application keeps track of your projects while you are developing your Java programs.

Applications are stored in files with the extension .jws. When you open JDeveloper, the last application used is opened by default, so you can resume where you left off.

When creating a new application in JDeveloper you have the option to create an application based on a template. The application template you select will determine the initial project structure, that is, the named project folders within the application. You can alter existing templates or create new ones.

In JDeveloper, you always work with projects contained in an Application.

 

3.

In the Create Application dialog, modify the default application name Application1 to MyFirstApp.

Note that the Directory Name changes accordingly.

 

4.

Click the downwards-pointing arrow in the Application Template field to see the list of available templates. Click it again to select No Template[All Technologies] for this application.

Click OK.

 

5.

The Create Project dialog displays.

Note:

A JDeveloper project is an organization used to logically group files that are related. A project keeps track of the source files, packages, classes, images, and other elements that your program may need. You can add multiple projects to your application to easily access, modify, and reuse your source code.

Projects manage environment variables such as the source and output paths used for compiling and running your programs. Projects also maintain compiler, run time, and debugging options so you can customize the behavior of those tools per project.


In the Navigator pane, projects are displayed as the second level in the hierarchy under the application.

 

6.

In the Create Project dialog, change the default Project Name Project1 to MyProject, then click OK.

 

7.

The Application Navigator should look like this:

Note that the project folder is a child of the applications folder.

Back to Topic List

Creating Your First Java Class

 

1.

Right click the MyProject node in the Application Navigator and select the New... option from the context menu.

 

2.

The New Gallery displays. By default, the first category, General, is highlighted in the Categories pane. Notice the other categories, enabling you to work with different technologies to build the various tiers of an application. Click the + sign to the left of the General category, to expand it, and see some of the sub-categories available. Select the Simple Files node.


3.

In the Items pane, select Java Class. Click OK.

The Create Java Class dialogdisplays.


4.

Change the default name Class1 to Dog. Accept all other defaults and click OK.

Notice that the package name is the one that was specified when you created the project.


5.

The new class opens automatically in the Code Editor, where you see the skeleton class definition.


6.

Add a method to the class. After the constructor, click Enter to create a new line, and type the following code: public String sayHi()

 

7.

At the end of the line, press Ctrl+Shift+Enter and JDeveloper provides auto-completion of the method structure.

 

8.

In the highlighted yellow line, add code to return the following values: return " woof " + "Kate";


Notice that when you type the first double quote symbol ("), JDeveloper automatically provides you with the second double quote, enclosing the cursor between them, so that you can easily type the literal.

 

 

Back to Topic List

Using the Code Editor with Your Java Class

Code Editor Viewers are where most of the application development work takes place; this is where you write code
and design user interfaces. In this topic you explore some of the features of the Java Source Editor.

Using code templates

Code templates assist you in writing code more quickly and efficiently while you are in the Code Editor. You can edit existing templates or create your own. This topic shows you how to use some of the existing code templates in the Dog class.

1.

There is a code template for adding a main method to a Java class.
Press Enter to create a new line after the sayHi() method. Type the letter m, and press Ctrl+Enter to invoke code templates.

The main method template is suggested.

2.

Press Enter again to accept the suggestion, and incorporate the template.


3.

Create a dog object in the main method, as follows: Dog myDog = new Dog();

Note: The myDog object is displayed in gray because it has not yet been used anywhere in the program. You will see other examples like this in the topic on Code Assist later in this tutorial.

 

4.

Press Ctrl + Enter to see the list of code templates that are available.

 

5.

You decide to create an integer-based loop using the fori code template.
In a new line after creating the dog object, type f, and then press Ctrl + Enter.

Three templates are suggested.

 

6.

Scroll to the second of the three suggestions, theforiinteger-based loop. Press Enter to select it.

The template code is incorporated into the file.

 

7.

Modify the template.
Replace 'i' with 'count' and limit the loop to 3 iterations.

Notice that changing the first i variable name in the loop changes all referring ones.

 

8.

Enter a System.out.println statement.
Place the cursor inside the curly braces of the fori loop, and type System., press Alt + Enter to import the suggested statement.

Typeo, and press Enter to select the suggested code.

Type.p and select theprintln() suggested code. Then press Ctrl+Enter.

 

9.

Add code to use the loop to display the sayHi message. Inside the parentheses after println, type: count + myDog.sayHi()

 

10.

Right click within the editor view and select the Reformat option to have JDeveloper restructure your code.

 

11.

Your code should now look like this:

 

 

Back to Topic

Compiling and running your Java class

1.

In the Application Navigator, right-click the Dog.java node and select Make from the context menu.

2.

At the bottom of the JDeveloper screen, a new window should appear (the Log window). If the Log window does not display, use View | Log to display it ( or Ctrl+Shift+L).

Notice that when using the Make option to compile your project, JDeveloper saves all the files in your project.

 

3.

Right-click the Dog.java node again, and this time select Run from the context menu.

.

4.

The Log window displays 3 counts of the ' woof Kate' message.

 

Back to Topic

Working with Code Assist

Code Assist examines your code in the editor, and provides assistance to fix common problems. Here you use the Dog class to explore some examples of the suggestions offered.

1.

Create a cat object.

At the start of the main method, just after the first curly brace, press Enter to create a new line. In the new line, type Cat myCat = new Cat();

 

2.

Notice that a light bulb icon has appeared to the left of the new line. Place your mouse over this icon and the message 'Quick fixes and code assists for this line' displays.


3.

Click the light bulb to see the suggested fixes.

Notice the different colors of light bulbs beside the suggestions, and different signs inside them. The amber light bulb containing a question mark (?) indicating a suggestion; the red light bulb containing an exclamation point (!) indicating that there is an error here.


4.

You would need a Cat class to create a cat object. If you click the first suggestion, JDeveloper invokes the Create Class dialog where you could create a Cat class.


5.

You will not create a Cat class just now, so click Cancel to close the Create Class dialog. However, remind yourself to do it later by doing the following:
Click Enter after new Cat(): to open a new line. In the new line type: //TODO create a Cat class


6.

Select View | Tasks Window to see a list of tasks that you have created.


7.

The Tasks window displays a list of the tasks you have created (in this case, it is your first task).


8.

Click a task in the list, and JDeveloper takes you to the relevant task, inserting the cursor at the start of the line.


9.

Notice the red square on the right hand side of the screen, beyond the scroll bar. Moving the mouse over this icon informs you that there are errors in your program.


10.

A smaller red mark, at the appropriate point in the code, gives more information about the error.


11.

The pink markers indicate where you have created a task. Hover over the marker with the mouse to see what the task is.


12.

Comment out the 'cat' line .Notice that the red markers have now disappeared, to be replaced by a green marker, indicating that there are no errors in your code.


13.

Right click within the editor window and select the Reformat option. Your code should look like this:

 

Back to Topic

Refactoring code

Refactoring is an editing technique that modifies code structure without altering program behavior. A refactoring operation
is a sequence of simple edits that transforms a program's code but keeps it in a state where it compiles and runs correctly.
JDeveloper provides a collection of refactoring operations.

1.

Let's discover one possible example of a refactoring operation illustrating how you can replace a constant expression in a method body by a parameter for the method. The expression will be replaced by the parameter name. The new parameter will be added to the method's parameter list, and in all invocations of the method.
To do this in the Dog class, right-click in the literal, 'Kate' in the sayHi() method code, and from the context menu, choose Refactor | Introduce Parameter...

2.

In the Introduce Parameter dialog, type p_name in the Name field, and click OK.


3.

Examine the code to see the results of the Refactor operation. The method declaration now contains p_name in its parameter list; the parameter p_name has replaced the literal 'Kate' in the method return value, and the literal 'Kate' has been inserted as a parameter in the method call.

 

4.

Another refactoring operation is to derive a new interface from selected methods in an existing class.

To do this in the Dog class, right-click in the Dog class declaration method, and from the context menu, choose Refactor | Extract Interface...

 

5.

In the Extract Interface dialog, type IntAnimal as the name of the interface, and check the sayHi(String) method in the Members to Extract list. Click OK.

 

6.

The IntAnimal interface has been created and opened in the Java Source Editor.

 

7.

A simple refactoring operation is to rename a method, whereby every occurrence of the method name is replaced by the new name.

To do this in the IntAnimal interface, right-click in the sayHi() method, and from the context menu, choose Refactor | Rename.

 

8.

In the Rename Method dialog, change the sayHi method name to sayHowDoYouDo. Check the Preview box to see all the usages that will be affected by the name change. Click OK.

 

9.

A Log window displays, listing all usages of the sayHi() method. You should examine each usage to check that you want each occurrence of sayHi()to be changed to sayHowDoYouDo(). If so, click the Do Refactoring button in the Log window toolbar.

 

10.

Note that the name change has taken place in the IntAnimal interface......

 

11.

.....and in the Dog class.

 

Back to Topic

Viewing your code modification history

JDeveloper has a built-in history feature.This local history does not require a version control system to provide a recent
change record and visual "diff" between versions. Versions are automatically created based on user interactions such as
Save, Compile, Rename, etc.

1.

Notice the three tabs at the foot of the Java Source Editor window. Click the History tab.

The History window displays.

 

2.

Notice the list of revisions and dates in the top part of the window, and the list of changes to the code in the bottom part. The two windows are synchronized, so that the detail in the bottom part of the window matches the selection in the top part. The revisions for the selected date are summarized in the bottom line of the screen, in this case 5 differences: 3 added, 0 removed, 2 changed.


3.

The lilac-colored boxes indicate changes to the code.
Position your mouse over the green left-pointing arrow in the lilac box in the left window containing the sayHi() method declaration. Notice that a message displays, indicating that clicking the green arrow allows you to replace the adjacent difference i.e. the sayHowDoYouDo() method would revert to sayHi().

 

4.

The green boxes indicate additions to the code.
Select the return "woof " + p_name; line in the green box in the right hand window. Hover over the red X with your mouse. Notice the message indicating that to delete the addition(s), you click the X.

 

Back to Topic

Navigating through your code

1.

You can navigate from one part of the code to another related part. One example of this, is navigating from a method to its declaration in an interface.
A method that implements a declaration from an interface displays a call out icon in the left-hand margin. Clicking this icon takes you to where the method is declared. Notice the i icon next to the sayHowDoYouDo() method in the Dog.java file.

2.

Click the icon. JDeveloper takes you to the interface, IntAnimal, where the method is declared, and highlights the method name for you.


3.

To return to where you were in the Dog class, click the green button in the toolbar.


4.

You can also navigate to the Javadoc for a given element. Click on the Dog.java tab to return to the file, and then right-click in the parameter list for the sayHowDoYouDo() method. From the context menu, choose Quick Javadoc.


5.

The Javadoc tag for the String object is displayed.


6.

Code folding allows you to expand and contract sections of code, making large programs more navigable.

Place your mouse in the space between the dotted and solid lines to the left of the 'cat' line.

Notice that a blue vertical line displays beside the main method body.


7.

Click the minus (-) sign at the top of the vertical blue line to contract this section of code.


8.

Hover over the plus (+) sign next to the contracted section of code. The contracted lines of code display in a blue shaded box.

back to Topic

Back to Topic List

Debugging your Java Programs

The integrated JDeveloper debugger allows you to debug your Java programs in the Java Source Editor. This topic shows
you how you can control the execution of a program by setting breakpoints. When your program execution encounters a
breakpoint, the program pauses, and the debugger displays the line containing the breakpoint in the source editor. You
can then use the debugger to view the state of your program.

1.

Set a breakpoint in the Dog.java file.
To do this, click in the margin to the left of the System.out.println(count + myDog.sayHowDoYouDo("Kate")); line.

The breakpoint icon displays.

 

2.

With the line selected, right-click and choose Debug from the context menu.

 

3.

Program execution proceeds up to the breakpoint (the red arrow in the left margin of the source code editor indicates where the break is occurring). The Log window opens and displays the debugging trace.


4.

Click the Step Over icon in the Debugger Log window toolbar to execute the first iteration of the myDog.sayHowDoYouDo() method.


5.

Note that the Log window displays the first woof Kate message.


6

Notice the Smart Data window at the bottom right of the screen. Select the count variable, and double-click in the Value column, to display the Modify Value dialog.


7.

Type 2 as the new value. Click OK.


8.

In the Debugging window toolbar, click Resume to continue program execution.


9.

The count variable is incremented, and exceeds its limit, so the program terminates, and the debugger disconnects.


Back to Topic List

This tutorial gave you a basic programming tour of the JDeveloper IDE. You created an application and a Java class. You then used the class to explore a number of features of the Java IDE, including refactoring, incorporating code templates, using Code Assist, and reviewing your code modification history. Finally, you saw how to debug your program using the integrated debugger.

You've learned how to:

Back to Topic List

Place the cursor over this icon to hide all screenshots.

 

posted on 2006-04-12 10:59 TrampEagle 阅读(662) 评论(0)  编辑  收藏 所属分类: IDE

只有注册用户登录后才能发表评论。


网站导航: