Can the @BeforStep and @AfterStep annotations be used in Java?
Yes, you can.
Currently you only have @Before / @ followed by before / after each script.
If you want a hook for steps / scripts / functions / set etc, you need to have a class like your hooks class, implement Cucumber Formatter and Reporter interfaces.
When you implement these interfaces in your class, it will automatically import all methods into that class, which you will override, and then just execute sysout on each method and you will see it automatically execute.
To get this to work, you also need to add this file as a plugin to CucumberOptions.
Have a look at this Hooks class: https://github.com/GeeChao/stag-automation-reports-parent/blob/master/stag-extentreports/src/test/java/org/stag/steps/Hooks.java
See also Runner class: https://github.com/GeeChao/stag-automation-reports-parent/blob/master/stag-extentreports/src/test/java/org/stag/runner/RunCucumberTests.java
source to share