Skip to main content

skip to main content

developerWorks  >  WebSphere  >

Keeping Simple Things Simple: "Hello, World" in 90 Seconds with WebSphere Studio Application Developer

developerWorks
Document options

Document options requiring JavaScript are not displayed


New site feature

Check out our new article design and features. Tell us what you think.


Rate this page

Help us improve this content


Level: Intermediate

Tom Mitchell (tommitch@us.ibm.com), Application Architect, Worldwide WebSphere Technical Sales Support Team

16 Jan 2002

This article shows you how to create and test a Hello World application and then shows you how easy it is to add a scrap page for testing snippets of Java code using WebSphere Studio Application Developer.

Introduction

When evaluating development tools, it is common to focus on features that simplify, accelerate, or make practical the development of complex applications. One of the underlying fundamentals of all IBM tools is the promise of making development of complex components easier and faster. WebSphereTM Studio Application Developer (Application Developer) has a rich set of features that deliver on this promise. These features greatly simplify and accelerate the process of developing, testing, and deploying complex J2EE applications containing HTML, JSPsTM, Servlets, JavaTM beans, EJBs, and other components.

Another important criterion for development tools that should be considered is that many of the day-to-day tasks that a developer performs are fairly simple and narrow in scope. A good tool must allow simple tasks to remain simple. Frequently, Java developers create a small application to test or experiment with a simple Java feature. In these cases, development tools should help the developer to quickly create, build, and test the application. They shouldn't require the developer to navigate through or even be aware of more advanced features and project structuring that is necessary for efficient creation of large, complex J2EE applications.

One of the first things I do when evaluating a new tool is to create the classic (or cliché, depending on your opinion) "Hello, World" application. Once that works, I feel I have a solid base from which I can experiment with the other features. Ideally, I like to be able to perform this task without any product education. In fact, I've been known to skip the product documentation altogether. I imagine there are a few other "try it first, read the documentation later" types out there as well. As you will see, the "Hello, World" exercise is very easy and intuitive with Application Developer.

The rest of this article shows you how to create and test a "Hello, World" application, and then shows you how easy it is to add a "scrap page" for testing snippets of Java code. At the end, I think you'll agree that Application Developer is the tool of choice for both simple and complex development tasks.



Back to top


Two minutes or less to a "Hello, World" application

The steps below assume you are using the 60-day trial edition of Application Developer. If you're using the beta version, some of the perspective selection menus may be slightly different.

Before we start, there is one important concept that needs to be addressed. Application Developer is a task-oriented tool that whose user interfaces are customized for the task being performed. The interface used for developing a JSP is much different from the one for EJB development. Application Developer lets you control what windows and views you see by switching the perspective you are using. A perspective is a set of views that show the resources you need when performing a specific task. Application Developer has perspectives defined for Web application development, J2EE development, debugging, and many other common tasks. Now, the fastpath to "Hello, World."

  1. Start Application Developer and open a Java perspective. To open Application Developer, select Start => Programs => WebSphere Studio Application Developer - Trial Edition. Next, select Perspective => Open => Java from the main menu. If you are using the beta version of Application Developer, you may need to select Perspective => Open => Other, and then select Java from Select Perspective window.
    Figure 1.

  2. Alternatively, you can click the Open Perspective button and select Java from the submenu.
    Figure 2.

  3. Next, create a new Java project. Select File => New => Project. On the New Project dialog, select Java in the left column and Java Project in the right column. See Figure 3 below.
    Figure 3.

  4. Click Next and enter the project name Hello in the project name field. Then click Finish to create the project.
  5. Now you will see the Hello project in the Packages view, as shown in Figure 4 below.
    Figure 4.

  6. Add the Hello class. To do this, right-click on the Hello package and select New => Class, or simply click on the New Class button in the toolbar while the Hello package is selected
    Figure 5.

  7. Type Hello in the name field and check the option to create a public static void main(String[] args) method.
    Figure 6.

  8. At this point, the main window should look like Figure 7 below.
    Figure 7.

  9. You could now run the application, but it wouldn't do anything, so we'll add one line of code to the main method. After the left brace ( { ), add System.out.println("Hello, World");
  10. You can add code like this more quickly by using code-assist. After you've typed System., select Ctrl-space, and a code-completion dialog will present valid object/method names. Code-assist reduces both keystrokes and errors significantly.
    Figure 8.

  11. Select Ctrl-S to save and compile the Hello class.
  12. Click the Run button to start the application . If this is the first time you've done this, a dialog will open asking how the application should be launched. Select Java Application and click Set as default launcher for project.
    Figure 9.

  13. Click Next => Finish and your application will run. Application Developer will switch into the debug perspective, and you will see your output in the console window, as shown in Figure 10 below.
    Figure 10.

  14. As you can see, Application Developer helps you get started quickly and simply. I timed myself when verifying the steps and it took 71 seconds.
  15. While it's unlikely that you'd need a debugger to follow the flow of this application, it's very easy to add breakpoints and debug. To set a breakpoint, right-click on a line of code and select Add => Breakpoint, or else right-click in the gray bar to the left of a line of code and select Add Breakpoint. Once you've set a breakpoint, a green circle appears to the left of the line of code.
    Figure 11.

  16. To debug, click the Debug button, not the Run button. Clicking Run causes the application to run without stopping at the breakpoints.


Back to top


Want more speed?

So far, you've seen a fastpath for running and debugging applications. For testing a few lines of code, there's an even quicker path: the Application Developer Scrap Page.

  1. To demonstrate it, take your "Hello, World" project and click on the navigation button on the left to return to the Java perspective.
    Figure 12.

  2. Now right-click on the Hello project and select New => Scrapbook page.
    Figure 13.

  3. Enter Scrap for the scrapbook file name and click Finish. You will return to the Java perspective with the Scrap.jpage file open
    Figure 14.

  4. Now type the same line of code in that we used before: System.out.println("Hello, World"). You can still use code-assist to complete method names. Select the line of code, right-click on it, and select Run. The line of code will be compiled and executed. You don't need a main, or any other method definition, to test it.
    Figure 15.

  5. After the code runs, you will see the result in the console pane at the bottom of the Application Developer window, as shown in Figure 16 below.
    Figure 16.

  6. The asterisk in front of the scrap.jpage tab indicates that you have not yet saved the file. Select Ctrl-S to save it and the asterisk will disappear.

That is all there is to it! "Hello World" in under two minutes.



Back to top


Summary

While WebSphere Studio Application Developer is a great tool for developing complex, multi-tier J2EE applications, it also excels at quick development of simple applications. With it unique task-oriented interface and its ability to switch perspectives, it is the tool of choice for all kinds of development tasks. Give it a try and you'll soon be on your way to increased productivity.



About the author

Tom Mitchell is an application architect with the World Wide Websphere Technical Sales Support team. He spends most of his time helping customers understand the Websphere Family of products, how it implements the J2EE specifications, and where it is going in the future. He is a co-author of Professional Java Fundamentals (WROX Press, 1996). It is a "must have" for people still developing AWT applications for Java 1.0. You can contact Tom at tommitch@us.ibm.com .




Rate this page


Please take a moment to complete this form to help us better serve you.



 


 


Not
useful
Extremely
useful
 


Share this....

digg Digg this story del.icio.us del.icio.us Slashdot Slashdot it!



Back to top