Java vs Php[Language Features]
Feature Data types
PHP boolean, integer, float, string, array, object.
Java boolean, char, byte, short, int, long, float, double, String, array, Object.
Winner Java.
2 Feature Variables names
PHP Variables are represented by a dollar sign followed by the name of the variable.
The variable name is case-sensitive.
Java There is no special character to start the variable name. The variable name is case-sensitive.
Winner Java.
3 Feature Variable declaration
PHP The variable is declared when it is created. Its type is implied from the assigned value. A variable can change its type if it is assigned a new value.
Java Variables must be declared with a specific data type before usage.
Winner Java. It is convenient for a small program not to require variable declarations, but for large software, this is harmful. Variables changing their types based on their value are very dangerous in large programs.
4 Feature Global variables
PHP PHP has a large number of predefined variables.
Java Java does not have global variables.
Winner Java. Global variables introduce possible bugs in large software.
5 Feature Variable variable names. A variable that contains the name of another variable.
PHP Supported.
Java Not supported.
Winner PHP.
6 Feature Constant declaration
PHP Constants are defined through a function, e.g.:
define(“MYCONST”, “Hello world”);
Defines a constant named MYCONST.
Java Constants are declared like variables with a “static final†modifier, e.g:
static final String MYCONST = “Hello world”;
Winner Java. Introducing a special function to define constants is counter-intuitive.
7 Feature Using libraries
Java import libraries. PHP includes libraries.
Java Java import libraries.
Winner Java. Including libraries can introduce variable scope issues. Packages are better structured than included libraries. 8 Feature Method overloading
PHP Not supported.
Java Supported.
Winner Java.
9 Feature Passing method parameters
PHP Passed by value and by reference.
Java By value only.
Winner PHP.
10 Feature Varying number of method’s parameters
PHP Supported.
Java Not supported, but can be done with method overloading.
Winner PHP.
11 Feature Variable functions: A variable name contains the name a function to call.
PHP Supported.
Java Supported with reflection.
Winner PHP. Java is harder to do.
12 Feature Invoking class members PHP object->member()
Java object.memeber()
Winner Tie.
13 Feature Multiple inheritance
PHP Not supported.
Java Not supported.
Winner Tie.
14 Feature Static methods
PHP ClassName::method()
Java Method must be declared static then called as follows:
ClassName.method()
Winner Tie.
15 Feature Object serialization
PHP Supported. Serializes to a stream.
Java Supported. Serializes to a stream or to XML. Winner Java.
16 Feature Interfaces
PHP Not supported.
Java Supported.
Winner Java.
17 Feature Scope of class members
PHP Only default public scope.
Java public, private, protected, and default (package).
Winner Java.
18 Feature Polymorphism
PHP Not supported. Methods cannot be overridden.
Java Supported.
Winner Java.
19 Feature Abstract classes and methods
PHP Not supported.
Java Supported.
Winner Java.
20 Feature Exception handling
PHP Errors can be ignored or raised.
Java Structured handling with try/catch/finally construct.
Winner Java.
21 Feature Multiple threads processing
PHP Not supported. (Supports Unix style process control with an add-on library that works on Unix only).
Java Supported.
Winner Java.
22 Feature Components
PHP Not supported.
Java Supported with Java Beans and EJBs.
Winner Java.
23 Feature Security
PHP Limited support with the “safe mode†feature.
Java Detailed support for applets, servlets, EJBs, and applications.
Winner Java.
4 Conclusion
The following shows the scores for each language:
Number of feature 21
PHP Won 3
Java Won 15
Tie 3
PHP is suitable for small web based applications. Notice how PHP won in features that are geared towards the script’s writer, e.g. Variable variable name, or multi-line strings.