Answer the question
In order to leave comments, you need to log in
what are the advantages of java over php in web applications
Greetings to everyone,
but I am primarily interested in the opinion of java programmers,
please tell me what, in your opinion, is the advantage of Java over php when writing web applications,
one fact is clear - writing shitty code in Java is more difficult than in php, and this is an essential argument, but what else is there ?
php is easier to learn, more examples, libraries in bulk, easier to use ... the same servers in bulk, I disagree about performance - the same FarmVille with 70 million users has php on the backends.
In no way do I want to breed holivar,
thank you all.
Answer the question
In order to leave comments, you need to log in
The advantages of Java “in general” do not concern iron in principle. This is a strict language in which you can solve in principle any problem that will work almost anywhere. A purely "ideological" aspect - it is more difficult to learn from it, but easier to write, it is more logical and does not irritate the programmer, it is developed and expanded "to infinity". It really is a tool for all occasions. But it has a "heavy" infrastructure.
PHP is easy to learn, easy to load, works inside HTML pages. Because of what it is in demand and widespread. But all is well only in the beginning. Then the lack of strict restrictions becomes a source of subtle errors, and the language itself is perceived as illogical and unpredictable. Large projects in PHP are pitch darkness. But this is also all “ideological” argumentation.
But in a real situation, everything is decided by the task, means and environment. So you won't get an answer :)
In the argument between Java and PHP, Python wins! :)
Java is heavier than PHP. A VPS for a simple application will be more loaded for java than for php. And it will require more memory. For complex and heavy - as it is written and will be.
Yes, I have not heard something about shared hosting under java.
In terms of development cost, PHP is better - faster and cheaper. In the case of developing large applications, we can talk about prototyping in PHP, followed by rewriting to something that is compiled - it can be java. Although the python/C bundle looks better.
> it's harder to write shitty code in java than in php
It's just a stereotype. It is more difficult to write shitty code in java just because it is more difficult to write any code in java than in php. A poor understanding of OOP, coupled with its capabilities in Java, sometimes lead to such crooked solutions that PHP developers never dreamed of.
I see a big advantage of Java in that a program compiled into bytecode will work everywhere the same, while for php there is a whole bunch of different optcache.
PHP - Hypertext Preprocessor, it works great with text. This is the advantage of PHP, web applications are its specialization. PHP scripts are easier to write, easier to edit, there is nothing that is not related to the web, unlike Java.
In general, there is no advantage of Java over PHP in Web applications, the reverse is also true.
In Web2.0 - Java already works better out of the box, but PHP is already needed, and most importantly, you can (!) twist.
From my own experience I will say that personally in my experience - programs written in php usually work 3-4 times faster than (my :) ) applications in java.
Now the question is why.
The answer is because they are written that way.
The advantage of Java is the existence of the Google Web Toolkit, which allows you to write both the server part of the application and the client part in one language, quite “transparently”. (Including using common classes in this and that code, and imperceptibly chasing objects from the client to the server.)
> I disagree about performance - the same FarmVille with 70 million users has php on the backends.
Absolute numbers do not say anything, even if you compare the number of users (and not hits, not to mention scenarios) related to the resources involved. Maybe where it is necessary to raise a cluster for PHP, enough for Java VPS, or maybe vice versa, I don’t know. I myself am now rushing between different languages, choosing what is best suited for a server with a peak of 100 requests / second, if it is possible at all on a 4-core processor with 8GB of RAM, it turns out 40 ms per request. According to some tests, Java shows about a 4-fold performance advantage over PHP and is comparable to C # aside, which I look at.
I have not worked with PHP for a long time (the last project was 2006), so maybe something has changed now. But in general, I still think that Java and generally typed languages (like Go, which recently came out) are better at developing large projects.
When a language is typed, it is much easier to learn third-party (and your own) code or API. And in an IDE, it's harder to make a mistake while writing code.
Regarding the libraries in PHP, of course, there are a few more of them than in Java (in the web direction). But I solved this problem through RPC (on non-critical areas) or through JNI (native call of C\C++ functions through a special interface). On the other hand, fundamental things like ORMs or web frameworks are much better done.
Improved dependency management, build and production of the project. Everything is automated and tailored for Java.
In Java, you have one process working with clients, while in PHP you need a new process for each client. I don’t know how much this affects performance, but in Java it’s more convenient to work in this regard when writing some kind of shared services for clients.
In the near future it will be possible to call Python, Ruby libraries or frameworks directly from Java. You can already do this now, but in Java7-8 it will be significantly optimized. So the problem with libraries will be solved.
If you want to get started with Java on the web now, take a look at Grails or Tapestry 5 web frameworks. The first one is not quite Java (built on Groovy), but has a lot of library integrations. The second one is completely in Java, but there are fewer integrated libraries.
Also Spring is now mainstream in web project development. The frameworks listed above are either built on it or have the ability to integrate with it.
php tempts to "write fast", and as the project grows, so does a bunch of exceptions written "quickly". proper design helps in any project, but in the case of java, the language helps, and in the case of php, the eternal desire to make “to work” instead of “how to do it right” leads astray.
What is the advantage of a chair over a table?
Although I understand perfectly how such questions are formed =)
There is no advantage, on the web we don't often have to worry about memory and speed. In JAVA, types are strict, which makes development slow. And in PHP, you can quickly do a lot, and the difference is almost imperceptible. But if you're going to write a video converter there, it's better to use C/C++/Perl right away.
I myself don’t make websites professionally, but if you need to do something in php, for some reason I immediately do it in classes, it’s more convenient and easier to support later. I haven’t worked with large projects, so I don’t know yet what difficulties appear if they are done in php using OOP.
Actually, why I posted this question - I want to write a framework for creating web applications for myself, everywhere I see that professionally it is java, and large projects are not written in php.
Maybe then someone will answer what kind of difficulties appear when writing large projects in php?
but we are discussing php and java :) in ruby I am completely incompetent and have nothing to say
PHP has another advantage that is important for the web: Script execution can be time-limited and memory-limited. And this restriction will not affect other connections in any way.
In Java, to do this, you have to kill the application server and restart it, which is time consuming and will affect other connections. That is why in production they run several servers on one machine.
Java has EJB, JSTL, JSF, Spring, hibernate , JPA, JSP , Servlet . In php and other programming languages for the web, there is nothing like this and is not expected. For this reason, it is easier to write in JAVA something other than a business card site. The business card just flies to java. PHP is only developing towards java, and java has all the technologies. You only need to write XML nicknames to add functionality. If we compare the performance, then JAVA has an advantage over PHP. 1000 requests to a java page are processed for 3 seconds in a servlet. Others do not have such speed. Yes, and in terms of resources, java is not very demanding if it is not crooked to write code. I would even say that in java, as well as in c ++, everything works well, but you need to study it. Learning java is hard work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question