The Java module in Mule 4 is built to:
Minimize the need for custom code.
Avoid the need for you to know or understand Java.
However, there are some advanced uses cases that require integration with custom Java code, for example:
Reuse of a library, such as a tax calculation library.
Reuse of a canonical object model that is standard in the organization.
Execution of custom logic using Java.
Note that in Mule 3, MEL serves as bridge for creating instances of particular Java classes and executing Java methods. In Mule 4, interoperation with Java changes due to the replacement of MEL by DataWeave, a functional language. Functional languages should not have side effects on their input arguments, so it does not make sense for DataWeave to execute random instance methods on random object instances.
You can use Java module or execute Groovy code through the Scripting module. However, the Scripting module does not offer DataSense support.