PHP compared to Java/J2EE

F

flarosa

Hi,

I'm wondering if I can get a reasonably civil (without starting any
huge wars) opinion on how server-side PHP compares to server-side
Java.

I've been strictly a Java developer for almost 10 years now, and I'm
pretty happy with it. However, I can't help but notice that there are
a significant amount of PHP-based development projects where I live,
and I've also noticed when searching around the internet for ready-
made web applications that a lot of them are in PHP.

As an object-oriented programmer I've always assumed PHP was more of a
scripting language for doing things on individual web pages or writing
small applications and that Java/J2EE was better positioned for
writing large applications, but maybe that's no longer true.

Let me know what you think. Thanks.

Frank
 
I

igrosny

Hi,

I'm wondering if I can get a reasonably civil (without starting any
huge wars) opinion on how server-side PHP compares to server-side
Java.

I've been strictly a Java developer for almost 10 years now, and I'm
pretty happy with it. However, I can't help but notice that there are
a significant amount of PHP-based development projects where I live,
and I've also noticed when searching around the internet for ready-
made web applications that a lot of them are in PHP.

As an object-oriented programmer I've always assumed PHP was more of a
scripting language for doing things on individual web pages or writing
small applications and that Java/J2EE was better positioned for
writing large applications, but maybe that's no longer true.

Let me know what you think. Thanks.

Frank

Frank,
I asked myself the same question some time ago. most of the answer i
found it at:

http://www.tbray.org/ongoing/When/200x/2006/11/10/Comparing-Frameworks


hope it helps
 
W

Wojtek

flarosa wrote :
Hi,

I'm wondering if I can get a reasonably civil (without starting any
huge wars) opinion on how server-side PHP compares to server-side
Java.

I've been strictly a Java developer for almost 10 years now, and I'm
pretty happy with it. However, I can't help but notice that there are
a significant amount of PHP-based development projects where I live,
and I've also noticed when searching around the internet for ready-
made web applications that a lot of them are in PHP.

As an object-oriented programmer I've always assumed PHP was more of a
scripting language for doing things on individual web pages or writing
small applications and that Java/J2EE was better positioned for
writing large applications, but maybe that's no longer true.

I have done work in both

PHP
- scripting language. The source code gets read and interpreted every
time a page hit occurs, unless you are using a precompiler, but then
the host server must have a special Apache extension to run it.
- becuase of the above it is expensive to use a lot of constants, so
you end up with a lot of magic numbers
- sort of OO. It has classes, but the implementation is not complete.
It was bolted on after the fact, so you can mix OO with procedural.
- one of the big features is the ability to "include" (or "requires") a
file. That way you build up a web page from many smaller files.
However, any variable which an included file might use from the parent
file, must be created by the parent file. So you may include a file
which requires a variable, only to have it crash becasue that variable
is not present. Makes debugging difficult.
- by design, presentation code is mixed with business logic
- great for small projects

Java
- compiled language. The compiler produces byte-code. The server reads
the byte code and uses the Java Runtime Environment (JRE) to run it.
- All constants are resolved by the compiler, so using many constants
makes the code more readable.
- The JRE will inspect the code execution path and will optimize it on
the fly. So the longer your code runs, the faster it runs.
- Is OO by design
- great for large projects.

So for small simple projects I use PHP. For anything serious I use
Java.

$0.02
 
J

Jerry Stuckle

flarosa said:
Hi,

I'm wondering if I can get a reasonably civil (without starting any
huge wars) opinion on how server-side PHP compares to server-side
Java.

I've been strictly a Java developer for almost 10 years now, and I'm
pretty happy with it. However, I can't help but notice that there are
a significant amount of PHP-based development projects where I live,
and I've also noticed when searching around the internet for ready-
made web applications that a lot of them are in PHP.

As an object-oriented programmer I've always assumed PHP was more of a
scripting language for doing things on individual web pages or writing
small applications and that Java/J2EE was better positioned for
writing large applications, but maybe that's no longer true.

Let me know what you think. Thanks.

Frank

Frank,

PHP is more popular because it's supported by all the web servers. When
PHP first came out, for instance, Apache and IIS didn't support Java
well on the server side (don't know what it's like now). Plus is is
fast and has a smaller memory footprint than Java, which made it better
for shared hosting companies. The result is that a lot of hosting
companies offered PHP really cheap - but Java support was comparatively
lacking and more expensive.

PHP is getting more object oriented. It still has a ways to go - Java
is much better in that respect. But PHP is getting there, a little at a
time.

Now when you're talking larger applications, I agree Java is a better
language, especially when you're talking GUIs. There is a GUI available
for PHP, but it is sadly lacking in functionality compared to Java. And
Java's event model makes some things much easier than in PHP (which
doesn't have an equivalent).



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
(e-mail address removed)
==================
 
M

Michael Fesser

..oO(Wojtek)
PHP
- scripting language. The source code gets read and interpreted every
time a page hit occurs, unless you are using a precompiler, but then
the host server must have a special Apache extension to run it.

There are also several PECL extension for PHP to cache the compiled
bytecode (PHP code is compiled first and then interpreted by the ZE).
One of these caches (APC) will most likely be part of PHP 6.
- becuase of the above it is expensive to use a lot of constants, so
you end up with a lot of magic numbers

Huh? I use hundreds of global and class constants. This is definitely
not a performance hit, there are "better" ways to waste CPU time.
- by design, presentation code is mixed with business logic

Such mixing is possible in other languages as well. And it's always the
developer who decides if he wants to make use of it or not. Of course
you can also properly separate business from presentation logic.
- great for small projects

Also great for bigger projects. Of course like in all languages you have
to know what you're doing and know the tools you're using.

Micha
 
K

KDawg44

Frank,

PHP is more popular because it's supported by all the web servers. When
PHP first came out, for instance, Apache and IIS didn't support Java
well on the server side (don't know what it's like now). Plus is is
fast and has a smaller memory footprint than Java, which made it better
for shared hosting companies. The result is that a lot of hosting
companies offered PHP really cheap - but Java support was comparatively
lacking and more expensive.

PHP is getting more object oriented. It still has a ways to go - Java
is much better in that respect. But PHP is getting there, a little at a
time.

Now when you're talking larger applications, I agree Java is a better
language, especially when you're talking GUIs. There is a GUI available
for PHP, but it is sadly lacking in functionality compared to Java. And
Java's event model makes some things much easier than in PHP (which
doesn't have an equivalent).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
(e-mail address removed)
==================

This is an interesting discussion. I have used Java but never used it
for a web application. Can anyone point me to a good place to learn
how to use this? Is this using JSP and servlets or is this something
else?

I am starting work on a project and I was going to do it with PHP,
MySQL, and some AJAX stuff. I considered doing it in Java but my
timetable is pretty short and front end GUI stuff in Java is a
nightmare to me (not good at it, not bashing Java). So with my short
time frame, I figured that a web based application would be the best
way where I can quickly build the interface. My application is not
huge, probably 50-75 hours for me to do.

THanks.
 
S

Steve

Wojtek said:
flarosa wrote :

I have done work in both

PHP
- scripting language. The source code gets read and interpreted every time
a page hit occurs, unless you are using a precompiler, but then the host
server must have a special Apache extension to run it.

not true at all! php can run all by itself or as a module to most *any* web
server (if that is how you intend it to be executed).
- becuase of the above it is expensive to use a lot of constants, so you
end up with a lot of magic numbers

'because of the above' being FALSE, your point of expense is moot. not to
mention silly, even if what you'd claimed were true. last time i checked,
apache was still free.

as for 'magic numbers'? well hell, that's completely unrelated to the point
you were trying to make. second, *people* create magic numbers...not
programming languages. you may need to explain yourself a bit more here.
- sort of OO. It has classes, but the implementation is not complete.

in what way?
It was bolted on after the fact, so you can mix OO with procedural.

in *ANY* language, you can mix OO and proc code. as for being bolted on
after the fact, again that's a completely FALSE statement. aspects of OO
have been in php since at least php 3.0 and remained largely unchanged until
php 5. the major provisions of what is prized about OO were *all* there at
that time...that was back in early 1998 fwir!
- one of the big features is the ability to "include" (or "requires") a
file. That way you build up a web page from many smaller files.

ok...but again you assume php just does web pages. you do that with perl
too? or ruby? or java?
However, any variable which an included file might use from the parent
file, must be created by the parent file. So you may include a file which
requires a variable, only to have it crash becasue that variable is not
present. Makes debugging difficult.

well, that's a stupid argument. that goes to developer architecture,
implementation, and lack of error checking to prevent 'crashing'. it has
little to do with being a php weakness.
- by design, presentation code is mixed with business logic

ONLY BY THE DESIGNER !!!
- great for small projects

AND FOR THE MULTI-BILLION DOLLAR projects for the fortune 100 companies for
whom i've developed php applications. lots of data, lots of users, lots of
hits, lots of bad consequences if php (or my implementation of it) fails.
Java
- compiled language. The compiler produces byte-code.

not a fully compiled language. just like msil that is executed by the .net
framework, java need jre. not much of a greater advantage there.
The server reads the byte code and uses the Java Runtime Environment (JRE)
to run it.

see above.
- All constants are resolved by the compiler, so using many constants
makes the code more readable.

NO DIFFERENT THAN PHP.
- The JRE will inspect the code execution path and will optimize it on the
fly.

NO DIFFERENT THAN PHP. you need to quantify and qualify 'optimize'.
So the longer your code runs, the faster it runs.

that is UTTERLY FALSE! there is a thing called an optimal limit. java will
hit a primary, ultimate, optimzed execution plan at some point. however, it
evaluates what 'optimal' is EVERY SINGLE TIME that code portion is going to
be executed.

as far as web development goes, php and java only get ONE pass at doing an
optimization. i think your point here is coming up a little short.
- Is OO by design

nothing *IS OO*...java was written with OO support in mind from its onset.
though php put it in its tertiary release, it was done in short order. the
only argument to be made here is what of OO is supported by either AND of
the things NOT supported YET by php, which are NEEDED to get the job done.
- great for large projects.

just like php. moot point.
So for small simple projects I use PHP. For anything serious I use Java.

$0.02

yeah, i think you're charging to much. i'd rate your overview about...one
peso, if that.
 
W

Wojtek

Steve wrote :
your point of expense is moot. not to mention silly, even if what you'd
claimed were true. last time i checked, apache was still free.

Expensive in terms of processor time, not currency.
 
S

Steve

Wojtek said:
Steve wrote :

Expensive in terms of processor time, not currency.

yeah, i got that after i reviewed the post. :)

even still, when talking web dev, php has a supremely smaller footprint than
java coule ever hope to attain. what php does provide, it makes sure it
doesn't sacrifice speed. and, as i think i saw someone else post, you can
get php to a semi-compiled state just as java does.
 
L

Lew

Steve said:
not a fully compiled language. just like msil that is executed by the .net
framework, java [sic] need jre [sic]. not much of a greater advantage there.

Actually, Java JVMs are quite effective at runtime code optimizations.

NO DIFFERENT THAN [sic] PHP. you need to quantify and qualify 'optimize'.

Actually, it's quite different, for most JVMs. JVMs perform inlining, loop
unrolling, enregistering, escape analysis, common-code refactoring,
just-in-time adaptive compilation and various forms of run-time analysis that
static-compilation tools are hard-pressed to achieve. While it's certainly
possible to do these things with PHP, most interpreters don't.

The various optimizations in the JVM achieve at least a ten-fold increase over
strictly interpreted bytecode, according to articles I've read. I saw that
simply switching a major enterprise server at a job site from "-client" to
"-server" doubled its throughput.

If I may be so bold, resorting to /ad hominem/ remarks in your exposition
redounded to its detriment.
 
L

Lew

KDawg44 said:
This is an interesting discussion. I have used Java but never used it
for a web application. Can anyone point me to a good place to learn
how to use this? Is this using JSP and servlets or is this something
else?

Yes, JSPs and servlets. java.sun.com has tutorials on the topic, and you
should search their site for information on "Model 2" architecture, a
Model-View-Controller pattern for web apps.
I am starting work on a project and I was going to do it with PHP,
MySQL, and some AJAX stuff. I considered doing it in Java but my
timetable is pretty short and front end GUI stuff in Java is a
nightmare to me (not good at it, not bashing Java). So with my short
time frame, I figured that a web based application would be the best
way where I can quickly build the interface. My application is not
huge, probably 50-75 hours for me to do.

GUI in JSP is just GUI in HTML. If you can make PHP, you can make JSP.

If you use Java Server Faces (JSF), things get more sophisticated, but the
approach is still markup oriented.
 
L

Lew

that is UTTERLY FALSE! there is a thing called an optimal limit. java will
hit a primary, ultimate, optimzed execution plan at some point. however, it
evaluates what 'optimal' is EVERY SINGLE TIME that code portion is going to
be executed.

You are mistaken. JVMs do not use a static optimization plan. It changes how
it runs different code paths depending on the runtime profile. It will
decompile code back to bytecode, for example, if it falls into relative
disuse, and JIT another part that is currently undergoing heavy use.

It can also dynamically examine things like method arguments to determine if
it's safe to lift instance variables into registers or not.

Go back and review how JVMs actually work. Sun has a number of white papers
on java.sun.com that explain the sorts of things they can do. IBM
DeveloperWorks has a series of articles by Brian Goetz that explained these
matters back in about 2003 / 2004.
 
S

Steve

Wojtek said:
Steve wrote :

Nope. Modern Java implementations use adaptive optimization during
runtime. With traditional compiled languages, the compiler does it once.

http://en.wikipedia.org/wiki/Java_performance#Adaptive_optimization

what i'm saying is that this is not a continual process, like a gui, or
running process on a system. in the context of the web, java doesn't get to
capitalize on more than a few adaptations given the
run-produce-output-and-done nature of a web hit. make sense?
 
J

Jerry Stuckle

Wojtek said:
Steve wrote :

Expensive in terms of processor time, not currency.

No more so than Java, and in many cases, less.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
(e-mail address removed)
==================
 
D

Daniel Dyer

what i'm saying is that this is not a continual process, like a gui, or
running process on a system. in the context of the web, java doesn't get
to
capitalize on more than a few adaptations given the
run-produce-output-and-done nature of a web hit. make sense?

No, because the JVM's optimisation is over the lifetime of the JVM not the
liftime of a single request. A request just invokes a method in a
pre-existing Java application. That single, long-running Java application
is the servlet container (something like Tomcat or Jetty). The container
can either run standalone and serve-up everything (including HTML and
static resources) or, more common in large systems, it can sit behind
Apache, which will serve the static content and defer to the servlet
container for dynamic content.

So the JIT compiler can (and does) use information it has gathered from
hundreds or thousands of hits over hours or days in order to optimise the
code.

Dan.
 
L

Lew

Daniel said:
No, because the JVM's optimisation is over the lifetime of the JVM not
the liftime of a single request. A request just invokes a method in a
pre-existing Java application. That single, long-running Java
application is the servlet container (something like Tomcat or Jetty).
The container can either run standalone and serve-up everything
(including HTML and static resources) or, more common in large systems,
it can sit behind Apache, which will serve the static content and defer
to the servlet container for dynamic content.

So the JIT compiler can (and does) use information it has gathered from
hundreds or thousands of hits over hours or days in order to optimise
the code.

Steve,

Check out the white papers and articles on JVMs and how they optimize code.
 
S

Sherman Pendley

flarosa said:
I'm wondering if I can get a reasonably civil (without starting any
huge wars) opinion on how server-side PHP compares to server-side
Java.

I've yet to see a cross-posted language comparison that remained civil.
This may be the exception, but I doubt it will be.
I've been strictly a Java developer for almost 10 years now, and I'm
pretty happy with it. However, I can't help but notice that there are
a significant amount of PHP-based development projects where I live,
and I've also noticed when searching around the internet for ready-
made web applications that a lot of them are in PHP.

As an object-oriented programmer I've always assumed PHP was more of a
scripting language for doing things on individual web pages or writing
small applications and that Java/J2EE was better positioned for
writing large applications, but maybe that's no longer true.

Let me know what you think. Thanks.

Learn both - and Ruby, Perl, Python, C, C++, C#, etc. The more tools you
have in your toolbox, the better-equipped you'll be to apply the most
appropriate one for the task at hand.

The phrase "object-oriented programmer" makes about as much sense to me
as "brush painter" or "saw carpenter." I can't see the point in limiting
one's options so narrowly.

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top