This week's book giveaway is in the Agile and Other Processes forum.We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!See this thread for details.

PHP vs Java

bob reilly

Ranch Hand

Posts: 44

posted 8 years ago

I don't know if this is the right forum to ask but here it goes. Staff at my office are familiar with PHP. We are literally just getting off the ground in learning Java. The question - what's the benefit to learning Java. We're a local government organization - with a need for Internet application to interface with enterprise database.

PHP seems to be a very straight forward scripting language with objects that you become familiar with. Java seems more involved. Whats the benefit of Java over PHP.

Any comments you could provide would be appreciated. Thanks.

Alonso Faust

Greenhorn

Posts: 14

posted 8 years ago

Well first off, PHP is solely a web-based programming language; it's use is limited to web pages that exist on a PHP-enabled server. Java on the other hand can run from within a web page or completely independent of the internet whatsoever.

Secondly, and probably least important but as it leads to Thirdly I shall include it, PHP is a much less strict language than Java, and as such can lead to poor programming practices. e.g. I worked in a language called AutoIT where it doesn't require line/command delimiters or even initialization of variables. It took me months to remember to put ; at the end of every line and I'm still not entirely re-used to setting variables to null or anything else.

And thirdly, while certain languages can incite poor programming habits, understanding and having worked in a large selection of languages can only increase your knowledge and ability as a programmer. And as a miniature fourthly, the more programming you understand, the more efficient your code can be. ("Never underestimate assembly language" ~Michael Saladino, Presto Studios)

I'm not trying to sound harsh in any of this, but there's ALWAYS an upside to learning a new language.

"It is but the bedazzlement of the Great Enchanter which makes the Terrible Giants appear as windmills, to the untrained eye."

Jeremiah da Costa

Greenhorn

Posts: 12

posted 8 years ago

We've had this come up at our company but it was not with PHP that was thrown out. It came down to Flex and Java. We decided to go with Java for the simple fact that we could leverage the Eclipse IDE and distribute our solution in a J2EE environment. Now with that said, we can achieve the same with Flex (some may argue otherwise) but if we ever wanted to have a stand alone solution with Java we are able to do so. So really, it comes to requirements not only now but future.

Andrew Mast

Greenhorn

Posts: 4

posted 8 years ago

One thing I've noticed is that PHP doesn't have the same strict rules that Java has with regard to primitive and other variable types. Java has strict type rules so that casting is expected if changes to a data type are to be made. PHP sort of let's you do anything which is flexible but also leaving you (the coder) with a lot of validation and possible runtime errors to deal with.

My experience with PHP is pretty limited. I have about 20 hours of experience with modifying existing PHP apps.

In order to give some weight to the opinions I am about to express, I want to say that I have experience with dozens of languages, including 11 years of C/C++, and a plethora of scripting languages including an intense year and a half with Perl.

The real power and beauty of Java is:

<ul>

1) When your apps get big. Java does big better than any other language.

2) When you work with other engineers. No other language smooths the road better for many engineers working on the same app.

3) Readability. Java is the best for when you have to come back to your own code that is two years old.

4) Less bugs. It takes more time to write the app than if you used a scripting lanaguage, but your odds of it working right the first time is much higher.

</ul>

I think the list goes on and on with all sorts of great reasons why Java is the best language for damn near anything. But .... I am now a Java bigot.

Originally posted by paul wheaton: 1) When your apps get big. Java does big better than any other language.

Nonsense. You can write the same app in most other languages just as well, possibly with the help of some third party libraries to replace the Java API. Why is Java better? Because of packaging? Because of separate files for separate classes? You can do the same in C, C++, Python and dozens of other languages.

2) When you work with other engineers. No other language smooths the road better for many engineers working on the same app.

Again, nonsense. You can distribute the workload exactly the same in Java or C++, for example. The keywords for working together are communication and proper project managent. If either one is missing, the entire app will be doomed, whether it is written in Java or not.

3) Readability. Java is the best for when you have to come back to your own code that is two years old.

Do you really believe yourself here? Again, this is just the programmer having a consistent coding style. You can achieve the same in almost every programming language. To be honest, if I would choose a single language that improves, encourages and even enforces readability, it's Python - you have to maintain the same indentation for an entire block, or it won't even run. In Java it's very easy to screw up indentation, thereby screwing up readability.

I think the list goes on and on with all sorts of great reasons why Java is the best language for damn near anything. But .... I am now a Java bigot.

And it couldn't be more obvious. I too am mainly a Java developer, just because it's powerful and easy. But to incorrectly compare it to other languages, ignoring their pro's and even equalities with Java, that's just wrong.