Exforsys

WebSphere Tutorials

  1. WebSphere V5.0 : Building Expressions
  2. WebSphere V5.0 : Creating SQL statements
  3. WebSphere V5.0 : Applying DDL scripts to a remote database
  4. WebSphere V5.0 : Deploying to the database
  5. WebSphere V5.0 : Defining a table
  6. WebSphere V5.0 : Defining a database
  7. Working with Data in WebSphere
  8. WebSphere V5.0 : Debugging - JSP debugging
  9. WebSphere V5.0 : Debugging - Scrapbook Page
  10. WebSphere V5.0 : Debugging - View variables
  11. WebSphere V5.0 : Debugging - Step-through code
  12. WebSphere V5.0 : Debugging - Set breakpoints
  13. WebSphere V5.0 : Running Applications - Export J2EE applications
  14. WebSphere V5.0 : Running Applications - Run/operate server
  15. WebSphere V5.0 : Running Applications - Understand Session Manager
  16. WebSphere V5.0 : Running Applications - Configure data sources
  17. WebSphere V5.0 : Running Applications - Create server instance and server configuration
  18. WebSphere V5.0 : Web Development - Use Web Page Wizards
  19. WebSphere V5.0 : Web Development - Work with Web Application Deployment Descriptor
  20. WebSphere V5.0 : Web Development - Use content assist
  21. WebSphere V5.0 : Web Development - Use Page Designer to add and modify HTML and JSP content
  22. WebSphere V5.0 : Web Development - Understand classpath and module dependencies
  23. WebSphere V5.0 : Web Development - Create resources in appropriate J2EE locations
  24. WebSphere V5.0 : Web Development - Create a web project
  25. WebSphere V5.0 : Java Development - Use property dialogues
  26. WebSphere V5.0 : Java Development - Use hierarchy view
  27. WebSphere V5.0 : Java Development - Use task view
  28. WebSphere V5.0 : Java Development - Use search function
  29. WebSphere V5.0 : Java Development - Use content assist function and declarations
  30. WebSphere V5.0 : Java Development - Use refactoring features
  31. WebSphere V5.0 : Java Development - Use Outline View and Browsing View
  32. WebSphere V5.0 : Java Development - Create Java project, packages, classes, methods
  33. WebSphere V5.0 : Workbench Basics - Use the Help feature to aid in development activities
  34. WebSphere V5.0 : Workbench Basics - Import to and export from the workbench
  35. WebSphere V5.0 : Workbench Basics - Work with Perspectives
  36. WebSphere V5.0 : Workbench Basics - Set workbench preferences
  37. WebSphere V5.0 : Workbench Basics - Create J2EE projects

Ads


Home arrow Reviews arrow WebSphere Tutorials

WebSphere V5.0 : Java Development - Create Java project, packages, classes, methods

Author : Exforsys Inc.     Published on: 26th Feb 2006

WebSphere V5.0 : Java Development - Create Java project, packages, classes, methods

In this tutorial you will learn about Create Java project, packages, classes, methodsm, Java project, Java project organization, Creating a Java project, Creating a new Java package, Creating a new Java class and Create new methods.

Ads

Java project

Java projects contain the resources needed for Java applications, including Java files and class files. Java projects are used to create Java packages. When you create a new Java project, the environment is set up for Java development. The Java project contains information about the type hierarchy and Java elements. This information is kept current as changes are made.

A Java builder is associated with the project so the Java source is incrementally compiled, automatically, as it is updated. Web, EJB, and application client projects can also contain the resources needed for Java applications. The Java builder will incrementally compile the resources within these projects as the resources are updated.

Java packages can be exported as JAR files and included in the build path for other project types, or in the class path for application servers.

Each Java project maintains additional information about the type hierarchy and the references and declarations of Java elements. This information is constantly updated as the user changes the Java source code; it is not dependent on the builder.

Java project organization

You can organize Java projects in two different ways:

1. Using the project as the source container. In this organization, all Java packages are created directly inside the project. This is the recommended organization for simple projects. The generated .class files are stored along with the .java source files.

2. Using source folders as the source container. In this organization, packages are created not directly inside the project, but in source folders. You create source folders as children of the project and create your packages inside these source folders. This is the recommended organization for more complex projects. It allows you to subdivide packages into groups.

Depending on the file organization that you choose when creating the project, the class files are either stored along with the Java files in the project folder or, if you are using source folders, the class files are stored in a separate output folder. The builder will also copy non-Java resources (for example, GIF files) into the output folder. If you have non-Java resources that should not be copied into the output folder, for example a readme file, you can create an ordinary folder and store the resources there.

Creating a Java project

1. Open the New Project wizard by selecting the menu item File > New > Project ....

2. On the left pane of the first wizard page, select Java, and on the right pane, select Java Project. Then click Next.

3. In the Project name field, type new project name, then click Finish. A new Java perspective opens within the workbench with the new Java project in the Package Explorer.


Java Project name

If you click Next, you can change new Java project properties:


Java Project Properties
.

Creating a new Java package .

To create new Java packages in the Package Explorer:

1. Optionally, select the project or source folder where you want the package to reside.
.
2.Click the Create a Java Package button in the workbench toolbar. The New Java Package wizard opens.

Create a Java Package button

You can do the same by selecting the menu item File > New > Package.

3. Edit the Source Folder field to indicate in which container you want the new package to reside. You can either type a path or click Browse to find the container. If a folder was selected when you chose to create the new package, that folder appears in the Source Folder field as the container for the new package.

4. In the Name field, type a name for the new package.

Type a name for the new package

5. Click Finish when you are done.

Note: the default (unnamed) package always exists and does not need to be created.

Creating a new Java class

Use the New Java Class wizard to create a new Java class. There are a number of ways to open this wizard:

1. Select the container where you want the new class to reside.

2. Click the Create a Java Class button in the workbench toolbar.

Create a Java Class button

or

1. Select the container where you want the new class to reside.

2. From the container's pop-up menu, select New > Class.

New > Class

or

1. Select the container where you want the new class to reside.

2. From the drop-down menu on the Open The New Wizard button in the workbench toolbar, select Class.

Open The New Wizard > Class

or

Click the Open The New Wizard button. In the left pane, select Java, and in the right pane, select Class.

Java > Class

or

Select the container where you want the new class to reside. Then, select from the menu bar File > New > Class.

File > New > Class

 
This wizard helps you to create a new Java class in a Java project:


New Java Class



Ads

Create new methods

1. Confirm that the alphabetical Sort button in the toolbar of the Outline view is toggled off.

2. Start adding a method by typing the following at the end of the Java file (but before the closing brackets of the type) in the Java editor:

public String toString() {

As soon as you type the method name in the editor area, the new method appears at the bottom of the Outline view.

3. Click the Save button. The compilation unit is compiled automatically and errors appear in the Package Explorer view, in the Tasks view and on the vertical ruler. In the Package Explorer view, the errors are propagated up to the project of the compilation unit containing the error.

4. Complete the new method by typing the following:

return str;
}


5. Save the file. Notice that the error indicators disappear.

_____________
Author: Mikalai Zaikin. Please Click Here to visit Authors site for any updates and changes to the study notes.





 
This tutorial is part of a WebSphere Tutorials tutorial series. Read it from the beginning and learn yourself.

WebSphere Tutorials

  1. WebSphere V5.0 : Building Expressions
  2. WebSphere V5.0 : Creating SQL statements
  3. WebSphere V5.0 : Applying DDL scripts to a remote database
  4. WebSphere V5.0 : Deploying to the database
  5. WebSphere V5.0 : Defining a table
  6. WebSphere V5.0 : Defining a database
  7. Working with Data in WebSphere
  8. WebSphere V5.0 : Debugging - JSP debugging
  9. WebSphere V5.0 : Debugging - Scrapbook Page
  10. WebSphere V5.0 : Debugging - View variables
  11. WebSphere V5.0 : Debugging - Step-through code
  12. WebSphere V5.0 : Debugging - Set breakpoints
  13. WebSphere V5.0 : Running Applications - Export J2EE applications
  14. WebSphere V5.0 : Running Applications - Run/operate server
  15. WebSphere V5.0 : Running Applications - Understand Session Manager
  16. WebSphere V5.0 : Running Applications - Configure data sources
  17. WebSphere V5.0 : Running Applications - Create server instance and server configuration
  18. WebSphere V5.0 : Web Development - Use Web Page Wizards
  19. WebSphere V5.0 : Web Development - Work with Web Application Deployment Descriptor
  20. WebSphere V5.0 : Web Development - Use content assist
  21. WebSphere V5.0 : Web Development - Use Page Designer to add and modify HTML and JSP content
  22. WebSphere V5.0 : Web Development - Understand classpath and module dependencies
  23. WebSphere V5.0 : Web Development - Create resources in appropriate J2EE locations
  24. WebSphere V5.0 : Web Development - Create a web project
  25. WebSphere V5.0 : Java Development - Use property dialogues
  26. WebSphere V5.0 : Java Development - Use hierarchy view
  27. WebSphere V5.0 : Java Development - Use task view
  28. WebSphere V5.0 : Java Development - Use search function
  29. WebSphere V5.0 : Java Development - Use content assist function and declarations
  30. WebSphere V5.0 : Java Development - Use refactoring features
  31. WebSphere V5.0 : Java Development - Use Outline View and Browsing View
  32. WebSphere V5.0 : Java Development - Create Java project, packages, classes, methods
  33. WebSphere V5.0 : Workbench Basics - Use the Help feature to aid in development activities
  34. WebSphere V5.0 : Workbench Basics - Import to and export from the workbench
  35. WebSphere V5.0 : Workbench Basics - Work with Perspectives
  36. WebSphere V5.0 : Workbench Basics - Set workbench preferences
  37. WebSphere V5.0 : Workbench Basics - Create J2EE projects
 

Comments