Angel78 Posted July 12, 2016 Share Posted July 12, 2016 I'm planning to learn either java or php. Which language do you think will give better employment opportunity? Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/ Share on other sites More sharing options...
0 Andre S. Veteran Posted July 15, 2016 Veteran Share Posted July 15, 2016 On 13/07/2016 at 5:47 PM, n_K said: Found a few benchmarks but they're all mostly old except this one, and no, it shows java is significantly slower than PHP (native, not even using hhvm): https://blog.famzah.net/2016/02/09/cpp-vs-python-vs-perl-vs-php-performance-benchmark-2016/ The problem with these comparisons is that the author is rarely as expert in all the languages he writes. Well, I'm no expert in either PHP or Java, but I can tell you that while his PHP code does this: $s = range(3, $n, 2); His Java code does this: ArrayList<Integer> s = new ArrayList<Integer>(); for (int i = 3; i < n + 1; i += 2) { s.add(i); } Any reasonable implementation of that PHP range function will allocate a single array of the right size immediately, write directly to each index in the array, and return the array. While the Java code has no choice but to create a default-size array for the initial ArrayList (10 I think), and then re-allocate and copy every time it grows too big following some exponential growth algorithm that will take a while to go from 10 to 10,000,000. So the Java code is spending most of its time pointlessly allocating and copying arrays, due to programmer oversight. Oh, not only that, but it uses the boxed type Integer rather than int, for no apparent reason whatsoever. Which is of course, hugely slower in tight mathematical loops than using the native type directly, as the PHP code is doing. We're talking about a heap allocation for every integer and an another indirection for every access to an integer. Just by curiosity I rewrote this to use an actual range function like the PHP code uses: int[] s = range(3, n, 2); int[] range(int start, int end, int step) { int length = ((end - start) / step) + 1; int[] range = new int[length]; int value = start; for (int i = 0; i < length; i++) { range[i] = value; value += step; } return range; } And now the code is 6 times faster. That should be faster than PHP according to his original results. DevTech 1 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597497774 Share on other sites More sharing options...
0 n_K Posted July 15, 2016 Share Posted July 15, 2016 1 hour ago, Andre S. said: The problem with these comparisons is that the author is rarely as expert in all the languages he writes. Well, I'm no expert in either PHP or Java, but I can tell you that while his PHP code does this: $s = range(3, $n, 2); His Java code does this: ArrayList<Integer> s = new ArrayList<Integer>(); for (int i = 3; i < n + 1; i += 2) { s.add(i); } Any reasonable implementation of that PHP range function will allocate a single array of the right size immediately, write directly to each index in the array, and return the array. While the Java code has no choice but to create a default-size array for the initial ArrayList (10 I think), and then re-allocate and copy every time it grows too big following some exponential growth algorithm that will take a while to go from 10 to 10,000,000. So the Java code is spending most of its time pointlessly allocating and copying arrays, due to programmer oversight. Oh, not only that, but it uses the boxed type Integer rather than int, for no apparent reason whatsoever. Which is of course, hugely slower in tight mathematical loops than using the native type directly, as the PHP code is doing. We're talking about a heap allocation for every integer and an another indirection for every access to an integer. Just by curiosity I rewrote this to use an actual range function like the PHP code uses: int[] s = range(3, n, 2); int[] range(int start, int end, int step) { int length = ((end - start) / step) + 1; int[] range = new int[length]; int value = start; for (int i = 0; i < length; i++) { range[i] = value; value += step; } return range; } And now the code is 6 times faster. And that's exactly what my original point was: why am I going to spend an (exaggerated) hour to write something in java that takes me 20 seconds in PHP? PHP has this built in (it's also fully bug/regression tested), java does not. That's my reason for preferring PHP over over languages. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597497892 Share on other sites More sharing options...
0 Andre S. Veteran Posted July 15, 2016 Veteran Share Posted July 15, 2016 6 minutes ago, n_K said: And that's exactly what my original point was: why am I going to spend an (exaggerated) hour to write something in java that takes me 20 seconds in PHP? PHP has this built in (it's also fully bug/regression tested), java does not. That's my reason for preferring PHP over over languages. No, your point in quoting that article was that "it shows java is significantly slower than PHP". Which it doesn't. Java seems to have a popular implementation of something much more generic here: https://github.com/google/guava/wiki/RangesExplained Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597497910 Share on other sites More sharing options...
0 n_K Posted July 15, 2016 Share Posted July 15, 2016 56 minutes ago, Andre S. said: No, your point in quoting that article was that "it shows java is significantly slower than PHP". Which it doesn't. Java seems to have a popular implementation of something much more generic here: https://github.com/google/guava/wiki/RangesExplained From my first post in this thread... 'I can spend 20 seconds making a quick script to do something in PHP which would take an hour to make in java,' Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597497986 Share on other sites More sharing options...
0 Andre S. Veteran Posted July 15, 2016 Veteran Share Posted July 15, 2016 This is becoming really silly... yes you also made that point but that wasn't the one I was replying to with that benchmark analysis, so you can't say "that was my original point". If all you're going to do is cite bogus sources at best and fail at reading comprehension then I'll just step out of this conversation. dead.cell, Seahorsepip, ZakO and 2 others 5 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597498010 Share on other sites More sharing options...
0 SuperKid Posted July 15, 2016 Share Posted July 15, 2016 I use Java every day to create web applications that are in production for medium to large websites and Java is definitely NOT on its way out. Java is great and its perfect for microservices which is becoming more popular by the day. I'd definitely recommend looking into Java, a much more useful language and you can use that knowledge to make Android apps etc. Seahorsepip and adrynalyne 2 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597498022 Share on other sites More sharing options...
0 adrynalyne Posted July 15, 2016 Share Posted July 15, 2016 2 hours ago, n_K said: From my first post in this thread... 'I can spend 20 seconds making a quick script to do something in PHP which would take an hour to make in java,' That tells me you know php better than Java and not much else. DevTech, dead.cell, pqt and 1 other 4 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597498218 Share on other sites More sharing options...
0 vhane Posted July 16, 2016 Share Posted July 16, 2016 The funny thing about this thread is that none of the people who are saying that they'd take Java over PHP actually like Java all that much. I wouldn't reach for Java for new projects. On Android I would instead use Kotlin, and on server side JVM I would use Scala. If I want a dynamically typed language I wouldn't pick PHP. JavaScript and Elixir are more expressive, succinct and modern options. PHP is like a dynamic Java. Fairly verbose, without the type safety, but with worse third party libraries. The code quality in many of the flagship open source PHP projects is quite shocking. I spent the early years of my career writing mostly PHP code. I would have levelled up faster as a programmer had I been writing Java instead. I would have been exposed to to better code back then. Knowing several programming languages, I personally choose to not write any PHP anymore. Seahorsepip 1 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597498716 Share on other sites More sharing options...
0 Andre S. Veteran Posted July 16, 2016 Veteran Share Posted July 16, 2016 22 hours ago, vhane said: The funny thing about this thread is that none of the people who are saying that they'd take Java over PHP actually like Java all that much. Yup. If I had to write for the JVM it'd probably be in Scala or Clojure. But I'd rather keep writing F#. vhane 1 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597498778 Share on other sites More sharing options...
0 Seahorsepip Veteran Posted July 16, 2016 Veteran Share Posted July 16, 2016 On 7/15/2016 at 11:06 AM, th3rEsa said: Name one language where this wouldn't be the case. PHP isn't type specific as example which makes messy programming a lot easier. Also PHP misses quite a few basic programming structures like method overloading. Object oriented programming isn't even something that's a given in PHP. PHP methods are as example not part of a class like in C# or Java. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597499154 Share on other sites More sharing options...
0 th3rEsa Posted July 16, 2016 Share Posted July 16, 2016 PHP is as object-oriented as you want it to be, similar to C++. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597499160 Share on other sites More sharing options...
0 Andre S. Veteran Posted July 17, 2016 Veteran Share Posted July 17, 2016 This pretty much convinced me to stay away from PHP. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597500064 Share on other sites More sharing options...
0 +Fahim S. MVC Posted July 17, 2016 MVC Share Posted July 17, 2016 2 hours ago, Andre S. said: This pretty much convinced me to stay away from PHP. It's a classic article Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597500224 Share on other sites More sharing options...
0 DevTech Posted July 19, 2016 Share Posted July 19, 2016 On 7/16/2016 at 0:33 AM, vhane said: The funny thing about this thread is that none of the people who are saying that they'd take Java over PHP actually like Java all that much. I wouldn't reach for Java for new projects. On Android I would instead use Kotlin, and on server side JVM I would use Scala. If I want a dynamically typed language I wouldn't pick PHP. JavaScript and Elixir are more expressive, succinct and modern options. PHP is like a dynamic Java. Fairly verbose, without the type safety, but with worse third party libraries. The code quality in many of the flagship open source PHP projects is quite shocking. I spent the early years of my career writing mostly PHP code. I would have levelled up faster as a programmer had I been writing Java instead. I would have been exposed to to better code back then. Knowing several programming languages, I personally choose to not write any PHP anymore. There are many more funny things about this thread, but that just makes it one of those entertaining threads you just can't take very seriously and "comic relief" threads are just what we need sometimes... If you are hammering in a nail, there is nothing odd at all if you prefer a pipe wrench over the heel of your shoe. You will be happy to demonstrate how the heavy metal head of the pipe wrench is far superior. Of course you would rather have a hammer. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502204 Share on other sites More sharing options...
0 DevTech Posted July 19, 2016 Share Posted July 19, 2016 On 7/15/2016 at 10:47 AM, Andre S. said: The problem with these comparisons is that the author is rarely as expert in all the languages he writes. Well, I'm no expert in either PHP or Java, but I can tell you that while his PHP code does this: $s = range(3, $n, 2); His Java code does this: ArrayList<Integer> s = new ArrayList<Integer>(); for (int i = 3; i < n + 1; i += 2) { s.add(i); } Any reasonable implementation of that PHP range function will allocate a single array of the right size immediately, write directly to each index in the array, and return the array. While the Java code has no choice but to create a default-size array for the initial ArrayList (10 I think), and then re-allocate and copy every time it grows too big following some exponential growth algorithm that will take a while to go from 10 to 10,000,000. So the Java code is spending most of its time pointlessly allocating and copying arrays, due to programmer oversight. Oh, not only that, but it uses the boxed type Integer rather than int, for no apparent reason whatsoever. Which is of course, hugely slower in tight mathematical loops than using the native type directly, as the PHP code is doing. We're talking about a heap allocation for every integer and an another indirection for every access to an integer. Just by curiosity I rewrote this to use an actual range function like the PHP code uses: int[] s = range(3, n, 2); int[] range(int start, int end, int step) { int length = ((end - start) / step) + 1; int[] range = new int[length]; int value = start; for (int i = 0; i < length; i++) { range[i] = value; value += step; } return range; } And now the code is 6 times faster. That should be faster than PHP according to his original results. I can't possibly emphasize enough how little of what we accept as "everybody knows" in the programming area has been actually tested. Big congrats to Andre for following the fundamental power of science and testing the issue. For "Computer Science" to be a science far far more of the silly social memes that circulate in the programming industry need to be tested. Extra big call out to do this extra effort in the context of an internet thread. Andre S. 1 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502210 Share on other sites More sharing options...
0 DevTech Posted July 19, 2016 Share Posted July 19, 2016 On 7/15/2016 at 4:19 PM, adrynalyne said: That tells me you know php better than Java and not much else. Exactly right. Every complex programming language has idiomatic features that make some task a one-liner that other languages will take 20 lines to write. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502212 Share on other sites More sharing options...
0 DevTech Posted July 19, 2016 Share Posted July 19, 2016 On 7/13/2016 at 6:37 PM, DevTech said: A lot of factors go into choosing programming technology and it is often additionally complicated because you don't get to start with a clean slate. Some of the criteria for technology selection presented so far have been ROTFLOL But if selecting the best bet for a career, then the performance and other factors of technical aesthetics just don't matter. http://trends.builtwith.com/framework PHP - 27% ASP.NET - 21% Java - 9% Ruby - 9% There are many ways to slice the data presented and really there is a lot of local variation in any career market so look at local ads and call up recruiters to get an idea. That all being said, programming computers is HARD. And if you have to go to a forum and ask this question, the next question to ask yourself, is it something you crave? Famous Broadway Choreographer once said "I don't want people who want to dance, I want people who NEED to dance." Since the thread has jumped the boundaries of the original PHP vs Java to people's favorite language of the day, I shall point out that from the OP career employ-ability point of view, C# would be the next choice after PHP given the statistics I linked to which at least is based on real world data. And C# (combined with F#) is not lacking in anything. PHP - 27% ASP.NET - 21% Java - 9% Ruby - 9% After C#, it appears we need a coin toss for Java or Ruby Those numbers are for the web which the OP implied by starting with PHP. But there is also a vast world outside the web where the breakdown would be different. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502220 Share on other sites More sharing options...
0 DevTech Posted July 19, 2016 Share Posted July 19, 2016 On 7/17/2016 at 0:56 PM, Andre S. said: This pretty much convinced me to stay away from PHP. Well right or wrong, you can't avoid admiring this gem: "PHP is an embarrassment, a blight upon my craft. It’s so broken, but so lauded by every empowered amateur who’s yet to learn anything else, as to be maddening. It has paltry few redeeming qualities and I would prefer to forget it exists at all." Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502224 Share on other sites More sharing options...
0 redfish Posted July 19, 2016 Share Posted July 19, 2016 Well... if this would be about learning programming... what you should know is that if you know one programming language, you know them all. I mean, there are a few things you'll have to adjust to going from one language to another, but its not difficult to transition. Ultimately, by the time you're looking for a job, you want to have an understanding of what type of work you actually want to be doing, and should have some familiarity with the tools used for the job. However, if you're just taking a course to learn programming, that's not necessarily what matters. I'd point out that many universities still use Java to teach -- just because from their perspective, its a good platform to learn structured programming with. Whether or not you're actually going to be coding in Java for a job is a different issue, but you can take the skills you learn in a Java course to any other language. If you're doing web programming, you'll be able to apply Java skills to JavaScript and PHP, which are both typically used. If you're doing app development, one choice is to work in C#, which you'll also be able to transition to easily from Java. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502244 Share on other sites More sharing options...
0 Kevin Petit Posted July 19, 2016 Share Posted July 19, 2016 If you want to learn from scratch, go Java. I made the mistake to learn PHP first, which led me to miss basic programming conventions. Most languages require you to cast a variable before you can use it, this happens automatically in PHP - and there's a few things that PHP does by it's own that makes it easier to use, but not always better to use. Though I think that PHP doesn't deserve all the hate that it gets here (as most of it is coming from the PHP 4 days and earlier), where PHP wasn't as object oriented as it should be - something that is solved now. PHP has evolved enormously the last few years, but I have to agree that the language has been very slow in implementing several things, and as a result of that, many of these things aren't really used yet by all programmers. Namespaces for example took way too long to get into PHP. Java however wasn't my second language to learn (it actually was C#, but I'm now looking into Java myself). You might want to try C# as well, as it's very alike to Java in many ways, but you're locking yourself in the Microsoft ecosystem (though you can avoid that with Xamarin). But in general, if you really want to program, learn Java first. It'll teach you a lot more, it will make sure you'll be able to understand concepts more easily and you'll have an easier time going from Java to PHP. About how or when to use PHP.. well, with frameworks like Laravel, a lot of the pain points of PHP is gone. It depends on what you need to do. Should I need to set up a microservice, I will probably use Lumen (Laravel mini framework) for that - it's often a lot easier to spin up a PHP application compared to a Java application (it might take you longer to get to the same result). In the end however, that's not the most important thing. But I do recommend learning Java or C#. Do try to avoid the "old" tutorials though on the internet - if you browse for PHP tutorials, you'll easily find tutorials more than 10 years old (or even recent ones) using the mysql_ functions, which are deprecated and removed in PHP 7. Same thing goes for Java - try to find modern, up to date tutorials. Sites like Codecademy, Laracasts etc. can help with that. Kev Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502274 Share on other sites More sharing options...
0 th3rEsa Posted July 19, 2016 Share Posted July 19, 2016 The problem with frameworks like Laravel is that you learn the framework, not the language, which is a bad order of things. As someone who does C# development for food, I can say that C# is much less annoying than Java, but I'd still stick to C++, PHP and Lisp any day. It's wrong to assume that learning a language equals general programming though, like someone above did. There are too many abstractions in most languages. Learning ASM is probably the best way to learn programming, but would you really want that? Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502278 Share on other sites More sharing options...
0 DevTech Posted July 19, 2016 Share Posted July 19, 2016 4 hours ago, th3rEsa said: Learning ASM is probably the best way to learn programming, but would you really want that? If you wanted to really learn, then you would really want that... The first year in my mythical "You Really Want This Programming Course" would consist of various ASM for real CPUs with hardware targeted to circuit boards you actually build in the Digital Design course and then debug on a hardware debugger, plus a traditional Art class, Graphic Design, The Science of Color, and essential Networking. Maybe add in some Frank Loyd Wright. Then when you understand the silicon you are working with and at the opposite end, the vast sea of media culture your works will swim in, then, and only then, will you appreciate all the crazy layers of abstraction that we shovel in by the boatload between those two endpoints. th3rEsa 1 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597502580 Share on other sites More sharing options...
0 svnO.o Posted July 24, 2016 Share Posted July 24, 2016 I'm a big fan of PHP. I graduated with a degree in software development and used a lot of C# / .NET back in the day, but I primarily do web development with the LAMP stack currently. If you need high to write high functioning algorithms then I would suggest combining it with python scripts on the back end. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597509196 Share on other sites More sharing options...
0 +Fahim S. MVC Posted July 24, 2016 MVC Share Posted July 24, 2016 On 7/19/2016 at 7:46 AM, redfish said: Well... if this would be about learning programming... what you should know is that if you know one programming language, you know them all. I mean, there are a few things you'll have to adjust to going from one language to another, but its not difficult to transition. Ultimately, by the time you're looking for a job, you want to have an understanding of what type of work you actually want to be doing, and should have some familiarity with the tools used for the job. However, if you're just taking a course to learn programming, that's not necessarily what matters. I'd point out that many universities still use Java to teach -- just because from their perspective, its a good platform to learn structured programming with. Whether or not you're actually going to be coding in Java for a job is a different issue, but you can take the skills you learn in a Java course to any other language. If you're doing web programming, you'll be able to apply Java skills to JavaScript and PHP, which are both typically used. If you're doing app development, one choice is to work in C#, which you'll also be able to transition to easily from Java. Don't agree with the idea of if you can do Java, you can do JavaScript. If you program your JS like Java, your JS code would be awful - despite looking the same (at a very high level), they are completely different animals. adrynalyne, th3rEsa and vhane 3 Share Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597509232 Share on other sites More sharing options...
0 th3rEsa Posted July 24, 2016 Share Posted July 24, 2016 I rewrote one of my PHP sites in C yesterday. Lovely. Simply lovely. Link to comment https://www.neowin.net/forum/topic/1302738-java-or-php/page/3/#findComment-597509234 Share on other sites More sharing options...
Question
Angel78
I'm planning to learn either java or php. Which language do you think will give better employment opportunity?
Link to comment
https://www.neowin.net/forum/topic/1302738-java-or-php/Share on other sites
140 answers to this question
Recommended Posts