The easiest way to create your Java macro file is to record one in STAR-CCM+ while you perform all the steps that belong in the macro file. To do this, select the File > Macro > Start Recording... menu item.

Alternatively, click the
(Start Recording) toolbar button.
This opens the standard, operating system-specific Save dialog. Navigate to the directory where you want to place this macro and give it a name (the .java extension will automatically be added to the file name).
Perform the normal setup and initialization steps, then perform one iteration. Even if the simulation is to be iterated 1000 steps in the batch run, only one step should be completed at this stage.
Use the File > Save menu option to save the current solution. When the macro is run, the file you select will be over-written with the new solution.
When finished, simply use the stop recording action, which saves the macro file. It is also possible to pause and resume the recording process.