Java Vs PHP
Java Vs PHP
Every variable in Java needs to be prepended with a data type. This includes primitive types
such as boolean, int, double and char, as well as Object data-types, such as ArrayList, String,
and own objects.
In Java, arrays are the classic C arrays. They can only hold variables of one particular type,
and need to be created with a fixed length.
Java contains a series of collection Objects, one of which is named ArrayList. ArrayList will act
more like PHP arrays.
In Java, one cannot get the array like syntax; all manipulation must be done through methods.
Java has no pointers. However, all Objects are actually references, similar to PHP 5, and
dissimilar to PHP 4.
The main code entry point in Java is a method to a class, as opposed to PHP where it is not.
The Java Class library provides a mechanism to implement threads. PHP has no such
mechanism.
PHP methods and functions allow for optional parameters. In Java, a separate method must
be defined for each possible list of parameters.
PHP requires an explicit $this be used when an object calls its own methods. Java does not.
Java programs tend to be built from a "program runs, stays running, processes requests" kind
of way, whereas PHP applications are built from a "run, handle the request, stop running" kind of
way.
Java is strong and statically typed, while PHP is rather weakly and dynamically typed.
PHP is mostly used to dynamically generate Webpages. Java can do that too, as well as
Applets, mobile phone software, Enterprise stuff, desktop application with and without GUI, 3d
games, Google Web Toolkit, etc.
PHP offers OOP (object oriented programming) as an option that is ignored in most projects.
In, Java, OOP is the default.
String constants in PHP are declared using single or double quotes. Double quotes will
evaluate variables embedded in the text. All Java String constants use double quotes and have
no such variable evaluation.
PHP object method calls use the -> operator. Java uses the . operator
Constructors in Java are named after the class name. In PHP they are called __construct()
Method overriding and overloading is quite natural in Java but a bit of a kludge in PHP
PHP code is embedded in what is otherwise largely an HTML document, much like how JSPs
work
In PHP, there is no method overloading, but methods and functions can have optional
parameters.
From todays point of view also offer Java and PHP similar functionality.
Nevertheless, other aspects are to consider:
o
Stability
Java is, especially through the complicated concepts such as Class Loading and
packages, better prepared for modularization. Due to better tool support (Ant /
Maven, Javadoc, JUnit) Java Frameworks have easier to install, better documented
and tested artifacts. However PHP tools for these tasks are also on the rise (pake /
phing, PHPDocumentor, PHPUnit / lime).
o
Integration
Integration is certainly the strength of Java. On the one hand, Java itself is almost
Industry Standard, on the other hand, there are many standards implementations in
Java. If a PHP Web application should communicate with a specific protocol, the
selection of libraries is rather limited. Even worse, implementations are either only
partially implemented or very rudimentary (such as Zend OpenID). Integration of PHP
applications with other services usually happens through the database layer.
o
Developer know-how
Even 20 years ago, Frederic Brooks searched for the Silver Bullet and did not find
it. In his article he came to the conclusion that software design, problem formulation
and the capabilities of the developers are far more important than tools or languages.
Therefore, it is certainly a good idea to implement a website by a designer with
knowledge of PHP with a state of the art PHP Framework. If it would be a Web frontend of a Java EE backend application Java would be the obvious choice.