Hello Hemant, you can create an automation process to run Static as well as Object methods using Java Activities package:
The Static Method:
- Open UiPath Studio and start a new Process.
- Drag a Java Scope activity to the Workflow Designer. Because no path is specified in the Java Library Path property, the Scope defaults to using the PATH environmental variable to initialize the Java Library.
- Drag a Load Jar activity to the Designer panel. Assign the path to the Objects.jar file in the JarPath property field.
- Drag an Invoke Java Method activity below the LoadJar. Input the method name in the MethodName property and then fill in the TargetType field with the Java package name and the class you want to use.
- Create a JavaObject variable, called JavaObjectResultStaticMethod, to store the values returned by the Invoke Java Method activity and place it into the Result property field.
- Add a Convert Java Object variable to the workflow and place the JavaObjectResultStaticMethod variable into the JavaObject property field. In the TypeArgument property field, select the System.Int32 variable type.
- Create a new Int32 variable, called ResultStaticMethod, and add it in the Result property field.
- Next, drag a For Each activity to the Designer panel.
- Set the TypeArgument property to Int32, and assign the ResultStaticMethod variable to the Values property field. This enables you to go through each integer of your array.
- Drag a Write Line activity into the Body of the For Each activity and assign value.ToString into its Text property. This helps you write all the values in the ResultStaticMethod variable in the Output panel, at runtime.
The Object Method:
Add a Create Java Object activity to the workflow, under the Java Scope activity used in the previous example.
- Use the name of the Java package and the Coordinate class to fill in the TargetType property - uipath.java.test.Coordinate.
- Create a variable in the Result property field by using the Ctrl+K hotkey and name it JavaObject.
- Drag an Invoke Java Method activity to the Designer panel.
- To get the sum of the data returned by the Coordinate class, write the getCoordinateSum method into the MethodName property.
- Create a variable in the Result property field by using the Ctrl+K hotkey and name it JavaObjectResultObjectMethod.
- Add the JavaObject variable in the TargetObject field.
- Add a Convert Java Object activity to the workflow.
- Add the JavaObjectResultObjectMethod variable in the JavaObject field.
- In the TypeArgument property drop-down, select the System.Double datatype.
- Create a new Double variable, called ObjectMethodResultValue, and add it to the Result property field.
- Drag a Message Box to the Designer panel.
- Assign ObjectMethodResultValue.ToString to the Text property to display the values inside the Double variable. At runtime, the JavaObject is created, containing the Coordinate class, then the getCoordinateSum method is run and its results are returned in another JavaObject. The results are then converted to a .NET Double variable which is then displayed in a MessageBox.