0% found this document useful (0 votes)
118 views3 pages

Java Vs PHP

This document compares Java and PHP programming languages. It notes several key differences between the two languages, including that Java uses static typing while PHP uses dynamic typing, Java passes parameters by value while PHP passes by reference, and Java focuses on object-oriented programming by default while PHP offers OOP as an optional approach. The document also discusses differences in strings, classes, arrays and other features. It concludes by discussing considerations around stability, performance, choice of libraries, integration capabilities, and developer expertise for choosing between the two languages.

Uploaded by

Headless77
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
118 views3 pages

Java Vs PHP

This document compares Java and PHP programming languages. It notes several key differences between the two languages, including that Java uses static typing while PHP uses dynamic typing, Java passes parameters by value while PHP passes by reference, and Java focuses on object-oriented programming by default while PHP offers OOP as an optional approach. The document also discusses differences in strings, classes, arrays and other features. It concludes by discussing considerations around stability, performance, choice of libraries, integration capabilities, and developer expertise for choosing between the two languages.

Uploaded by

Headless77
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

PHP is good for making quick one time systems.

Java is good for enterprise


systems.

Some differences between Java and 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, every variable can only hold a value of its type.

In Java, equality on objects checks for object identity.

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.

In Java, ArrayLists and other collections are implemented with generics.

Java has no pointers. However, all Objects are actually references, similar to PHP 5, and
dissimilar to PHP 4.

All method parameters are passed by value in Java.

The main code entry point in Java is a method to a class, as opposed to PHP where it is not.

In Java, variable names do not usually start with a sigil ($).

Class names in Java are case sensitive.

Strings are not mutable in Java.

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 compiled to bytecode, PHP is interpreted.

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

PHP has in my opinion, significant weaknesses. The procedural backward


compatibility, no real deprecation mechanism, a mess semi platform independent
libraries and functionality are just some of the issues the PHP. PHP lacks a clean cut,
which the PHP planned to do with version 6.
Java, however, has a clean platform independence and a fairly well-defined number
of core libraries with appropriate quality standards.
o
Performance
While Java was formerly often described as slow, todays JVMs are highly optimized
for speed, while the script languages, including PHP, still struggle with this. For
example a first usable garbage collector will be shipped with PHP 5.3. Also other
optimizations were moving very slowly into PHP Runtimes. This might be due to the
fact that PHP in contrast to Java restarts the VM after each request, which of course
brings additional performance problems. For example for each request session data
has to be read from disk. Although there are solutions in PHP (MemCache, APC)
these are rarely and partly still heavily in development.
Interestingly, this drawback makes scaling of PHP applications fairly simple. As
completely separate requests can be processed, additional hardware results in
relatively linear improvements in the capacity of the server. On the Web, the focus is
rather on the number of requests, not directly on the exact duration of an individual
requests.
o
Choice
Ideally, you never will re-invent the wheel. It makes sense to look for already existing
solutions. Both in PHP, as well as in Java, there is a lot of modular software, partly
with free, partly with non-free licenses. However, PHP modules expose significantly
more problems than those written in Java. For example, some PHP module
developers invented own concepts (e.g. Zend Loader was created by Zend as a
substitute for packages) or the modules are only optimized for a framework (like
symfony plug-ins).

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.

You might also like