Both PHP and Java are very similar in terms of the benefits offered, but they are very different. PHP is a server-side server scripting language, and it is best for Java client side.
If you use a PHP code, execute it on the real server and Java is running on your client's computer. This means that if you are using Java and the client does not have the correct program, such as Java Runtime Environment, your webpage will not be displayed. PHP is not a problem.