Use Java when you absolutely cannot do it in PL/SQL, or if Java will allow you greater performance.
As an example, if you wish to use sockets within a PL/SQL program (logging, external calls, etc), you can:
- write a PL/SQL client that uses UTL_TCP. There is no way to do UDP using only native PL/SQL though.
- write a Java client that uses TCP or UDP sockets.
In the first case, you have a synchronous socket that can back up your PL/SQL calls if the remote service has issues. Additionally, if you are using dbms_session.reset_package (as in OWA), you will have to reconnect the socket for every request, which is very expensive.
In the second case, TCP is still synchronous, but if you need asynchronous, non-blocking behavior you can use UDP. Additionally, reset_package does not reset Java TCP or UDP sockets, so you won't need to deal with tear-down/reconnect pain.