Java code can be written directly in Activity using Java method but in Data Transform we cannot write the code as we don't have any such methods. But as per best practices directly writing Java code in the Activity is also not suggested. So write the Java code that performs your requirement and call the Function from the data transform.
There is no direct method in the Data transform to call the java. Instead, you can configure the activity with the required java step and call this activity from the Data transform with the function (pxExecuteAnActivity) on passing the pageName, ActivityName. But as per the standards, its recommended to find the suitable OOTB functionality before writing the java steps in the activity.