Show TOC Start of Content Area

Procedure documentation Creating Development Objects  Locate the document in its SAP Library structure

Use

In this step, you create the required Java development objects for the development activity – that is, you create the package, the interface and the classes required by this tutorial.

Prerequisites

You are in the Java perspective in the Package Explorer view.

Procedure

Adding a Package to the Development Component

...

       1.      Open the project node of your component and select the src/packages folder.

       2.      From the context menu, choose New Package.

       3.      Enter org.example.tax as the name of the new Java package and choose Finish.

       4.      You have created a new Java package.

Adding an Interface to the Development Component

...

       1.      Select the package org.example.tax and from the context menu, choose New Interface.

       2.      Specify ITaxCalculator as the name and choose Finish.

       3.      On the dialog that appears, confirm that you want to add the new file to the Design Time Repository (DTR) by choosing OK.

       4.      Select your activity New Java Component and choose OK.

Note

For certain development steps, you can specify an activity as the default activity. All your changes are automatically added to this activity.

To do this, in the Open Activities view, choose Use as Default from the context menu of an activity. To deactivate this option, in the same view in the context menu of the workspace, choose Always Explicitly Select Activity. If, for example, you want to create a new DC, you should choose this option or select a new default activity because activities are – among others – used to group related file versions.

The Java editor appears for ITaxCalculator automatically.

       5.      Insert the following code:

package org.example.tax;

 

public interface ITaxCalculator {

   double calculateTax(double income);

}

       6.      Save the entries.

The new interface ITaxCalculator is added to the package org.example.tax.

Adding Classes to the Development Component

Here you add the two classes of this tutorial - TaxCalculator and TaxFactory and specify their source code.

...

...

       1.      Select the package org.example.tax and from the context menu, choose New Class.

       2.      Enter TaxCalculator as the name and choose Finish.

A dialog box is displayed.

       3.      When asked to add the new file to the DTR repository, confirm this by choosing OK.

       4.      Select activity New Java Component, if necessary, and again choose OK.

Note

If you specified this activity as the default activity, the query does not appear.

The Java editor for the class TaxCalculator appears automatically.

       5.      Insert the following code:

package org.example.tax;

 

public class TaxCalculator implements ITaxCalculator {

   private double rate = 0.5;

   public double calculateTax(double income) {

      return income * rate;

   }

}

       6.      Save the class.

The new class TaxCalculator is added to the package org.example.tax.

       7.      To create a new class TaxFactory, repeat steps 1 to 4. In step 1, specify TaxFactory as the name of the new class.

The Java editor for the class TaxFactory appears automatically.

       8.      Insert the following code:

package org.example.tax;

 

public class TaxFactory {

   public static ITaxCalculator createInstance() {

      return new TaxCalculator();

   }

}

       9.      Save the class.

The new class TaxFactory is added to the package org.example.tax.

Result

You have now created and added the required Java package, interface, and classes for this tutorial. They are part of the development activity now.

Next Step

Building Locally the Development Component

End of Content Area