PHP compared to Java/J2EE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • flarosa

    PHP compared to Java/J2EE

    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

  • igrosny@gmail.com

    #2
    Re: PHP compared to Java/J2EE

    On Nov 14, 2:35 pm, flarosa <fr...@franklar osa.comwrote:
    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:




    hope it helps

    Comment

    • Wojtek

      #3
      Re: PHP compared to Java/J2EE

      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

      --
      Wojtek :-)


      Comment

      • Jerry Stuckle

        #4
        Re: PHP compared to Java/J2EE

        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.
        >
        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.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Michael Fesser

          #5
          Re: PHP compared to Java/J2EE

          ..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

          Comment

          • KDawg44

            #6
            Re: PHP compared to Java/J2EE

            On Nov 14, 12:56 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
            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.
            >
            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.
            jstuck...@attgl obal.net
            =============== ===
            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.

            Comment

            • Wojtek

              #7
              Re: PHP compared to Java/J2EE

              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.

              --
              Wojtek :-)


              Comment

              • Steve

                #8
                Re: PHP compared to Java/J2EE


                "Wojtek" <nowhere@a.comw rote in message
                news:mn.72717d7 b10e20ffd.70216 @a.com...
                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.
                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.


                Comment

                • Lew

                  #9
                  Re: PHP compared to Java/J2EE

                  Steve wrote:
                  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.

                  "Wojtek" <nowhere@a.comw rote in message
                  >The server reads the byte code and uses the Java Runtime Environment (JRE)
                  >to run it.
                  ...
                  >- The JRE will inspect the code execution path and will optimize it on the
                  >fly.
                  Steve wrote:
                  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.

                  --
                  Lew

                  Comment

                  • Wojtek

                    #10
                    Re: PHP compared to Java/J2EE

                    Steve wrote :
                    php and java only get ONE pass at doing an optimization.
                    Nope. Modern Java implementations use adaptive optimization during
                    runtime. With traditional compiled languages, the compiler does it
                    once.



                    --
                    Wojtek :-)


                    Comment

                    • Lew

                      #11
                      Re: PHP compared to Java/J2EE

                      KDawg44 wrote:
                      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.

                      --
                      Lew

                      Comment

                      • Lew

                        #12
                        Re: PHP compared to Java/J2EE

                        "Wojtek" <nowhere@a.comw rote in message
                        >So the longer your code runs, the faster it runs.
                        Steve wrote:
                        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.

                        --
                        Lew

                        Comment

                        • Steve

                          #13
                          Re: PHP compared to Java/J2EE


                          "Wojtek" <nowhere@a.comw rote in message
                          news:mn.727b7d7 b87640b69.70216 @a.com...
                          Steve wrote :
                          >php and java only get ONE pass at doing an optimization.
                          >
                          Nope. Modern Java implementations use adaptive optimization during
                          runtime. With traditional compiled languages, the compiler does it once.
                          >
                          http://en.wikipedia.org/wiki/Java_pe...e_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?


                          Comment

                          • Jerry Stuckle

                            #14
                            Re: PHP compared to Java/J2EE

                            Wojtek wrote:
                            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.
                            >
                            No more so than Java, and in many cases, less.

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • Wojtek

                              #15
                              Re: PHP compared to Java/J2EE

                              Steve wrote :
                              what i'm saying is that this is not a continual process
                              Yes it is.

                              --
                              Wojtek :-)


                              Comment

                              Working...