PHP, or hypertext pre-processor, is a server side scripting language used to build dynamic web pages. It was one of the first coding structures to be embedded directly into HTML. Java, on the other hand, is a programming language supporting an object oriented structure and is dynamic in its features. It supports much more high level programming needs than PHP.
These two maybe completely different entities to compare, but can be evaluated on common grounds such as web building and scalability, and ease of programming.
Java is a client side scripting language whereas PHP is server oriented. This means that PHP code is executed on the server and the Java code is executed on the client’s computer. So, if your computer system does not execute Java, the web page wouldn’t load. This maybe a slight drawback of Java, but the fact that JRE (Java Runtime Environment) is easily available and free for download makes this problem less significant. The fact remains that there are many internet service providers provide PHP services for a cheaper price than Java.
Both are widely accepted forms of web building but when it comes to ease of learning and use, PHP is a step ahead. Certain simple programming is done easier with PHP than Java. But Java offers a better way of multilevel threading and separation of layers. Writing reusable content and defining and using class/object system is tedious and confusing in PHP. So when it comes to designing forms and display information PHP is preferable, and for logins and sessions Java is suitable.
Java is an industry standard technology and more robust than PHP. It was designed to be scalable and reliable.
PHP is a free and has many support resources and can be used along with many database servers. People are easily acquainted with PHP and feel that is easy to customize, tweak or rebuild. Java does not come for free, is not widely used as PHP and mastering it takes time and effort. There are no proper qualifying levels for PHP unlike Java, which provides certification for its students. The expertise is easier to measure.
Both these technologies have their own set of advantages and disadvantages. It is tough to decide which is better than the other but you have the objectives in hand, you would know which option is more suitable.