views:

3813

answers:

12

I already have some knowledge in Java and I was looking to start writing scripts for web development. I was wondering if I should just learn .jsp since I already have a Java background or is PHP that much better I should take the time and learn it.

I'm looking for some pros and cons for each, or just a straight out witch ones better!

Any help would be awesome!

A: 

Don't learn PHP. JSP is certainly better. Generally people avoid working in PHP once they know better :P

-- edit

Perhaps to explain a bit more; PHP is considered generally unsecure, as opposed to Java.

Java has lots of benefits; namely a large language API, very nice frameworks, and, of course, it's statically typed.

-- edit

I don't mind being downvoted for my dislike of PHP, that's fine. But please do realise that PHP is not a language that lends itself to security.

Reasons:

  • magic quotes
  • mysql integration encourages 'appending' method of building sql queries; increases risk of sql injection
  • lack of strong types combined with the sql thing above also increases risk of sql injection

Other such reasons apply.

Okay; back to downvoting me :)

Noon Silk
Yeah .. that was offensive...
Chacha102
Offensive maybe but it's accurate ...
Noon Silk
Not really.... making sweeping, unfounded generalizations is offensive.
Chacha102
It's completely founded. But not much point arguing about it.
Noon Silk
It may be your opinion but it's an opinion without factual basis.
cletus
It is fact; all programmers I know consider PHP not good for real-world apps (regardless of anecdotes showing 'popular' things being implemented in it). And it's a *fact* that it is generally more insecure then Java.
Noon Silk
Ah come on. Web programming is about returning HTML to the server. A Language like PHP is perfectly suitable for doing it. I can write web apps in C and I do the exact same thing!
toto
Security is not generally a language feature, it is a developer/code feature.
Amber
@silky that only means you don't know many programmers. AND you shouldn't be making programming language recommendations based on popularity, even if your popularity perceptions *were* true. AND many programmers consider the fact that Java is statically typed to be *a bad thing* for web development. AND I'd like to see any evidence whatsoever that Java is more secure than PHP.
Imagist
@Dav I'm sorry but security *is* a language feature. It's too complicated to answer here [in this little box], but please look into it more and you will discover that.
Noon Silk
How exactly is someone supposed to enter your app from a <form> ?Even if you code like a foot and deliberately direct the input to your stack, the only thing that can happen is that your web app crashes!
toto
Toto your comment is a bit to ridiculous to address I'm sorry. But please, maybe look up OWASP comments on PHP. It may help you.
Noon Silk
@Silky Security is sometimes a language feature; for example: if the standard libraries for a language implement features in an insecure way. However, that doesn't really apply here: both JSP and PHP have put a lot of effort into implementing their libraries in a safe manner. There might be a slight difference in security, but I see no evidence to say that the difference favors JSP. In any case, the difference is small in comparison to the fact that neither language prevents one from doing something stupid like writing unsanitized user input to an SQL query.
Imagist
@silky I cannot think of a viable development language in which a poor programmer (or poorly-written code in general) could not be unsecure, nor can I think of a commonly-used language in which well-written code would be inherently less secure than average code in another language.
Amber
@Silky I think Toto is making fun of you.
Imagist
Dav, just because you can't think of it doesn't mean it's true. Check the OWASP guide perhaps, for some insights.
Noon Silk
@Imagist, I've slightly updated my post to comment on why.I'm a bit concerned about the number of people who don't realise that PHP is not good from a security point of view. I had previously assumed this was comment knowledge.
Noon Silk
@silky all of those reasons you just listed are easily avoided, so they are all really stupid reasons to back up your answer.
Chacha102
@Chacha102 they are easily avoided by an expert, but not by a newbie to the language, and they do prove my general point - php is typically insecure compared to Java.
Noon Silk
@Dav C is both a viable development language and a language in which well-written code would be inherently less-secure than average code in PHP or JSP (at least for web development). Even the best programmers occasionally allow buffer overflows.
Imagist
@silky Bad code is bad, no matter what language you write it in. If I went to write in Java, I probably would write bad code too, because I don't know Java. That doesn't mean it is less secure. (Plus SQL injection is easily avoided by using MySQLi)
Chacha102
@Chacha102 actually, it does. Regardless, this argument is proceeding along predictable and boring lines now. I have no interest in trying to convince you of something you are not interested in listening to, so lets just leave it. If you feel motivated enough, do some research into the topic. Start with OWASP.
Noon Silk
@silky It takes very little expertise to avoid any of those issues. And "JSP is more secure than PHP" *isn't* common knowledge because it isn't based in any facts. Furthermore, what makes you assume that security is the only concern? If productivity is a big concern, then PHP wins hands down. If readability is a concern, PHP wins. If not making you want to tear out your eyes because taglibs are the invention of satan is a concern, then PHP wins.
Imagist
Java can be advocated but this isn't a way to do that. PHP has humongous language API. It has frameworks for every taste, from large Drupal CMS to completely thin Zend, to rails clone CakePHP. Static typing is not an advantage, mere preference, and PHP is only unsecure in the hands of poor programmer. Trust me, I can write you a horribly protected java program. Java has things going for it but you didn't mention a single one of them.
hakunin
@Imagist I won't be replying here anymore; the argument is now useless and better information is available for those who wish to research into it themselves.
Noon Silk
@silky Pointing people to OWASP and saying that they should go do research to prove your point is dumb. I could equally claim that OWASP proves that PHP is more secure and that there's not enough room to show it here but you should look it up.
Imagist
And for anyone interested, I don't like PHP either. I would pick Python/Django or Python/Pylons any day.
Imagist
+1  A: 

Read PHP vs JSP.

adatapost
Read it and see that maybe PHP pulls ahead a little, but then the fact I know Java already makes JSP pull ahead a little further in my opinion.
Jacob Nelson
@jacobnlsn I don't think that your Java knowledge will be much help in learning JSP. The languages are significantly different despite being on the same platform. I knew Java before I learned JSP and despite my previous Java knowledge, I *still* found PHP easier to learn.
Imagist
+1  A: 

I would choose PHP over JSP. Primarily because I think you will find vastly more code in the Open Source world built using PHP. I've also found I can do simple things very rapidly with PHP. Also some major CMS systems (like Drupal and Joomla) are made using PHP.

Finally FWIW, there are almost 12,000 questions tagged 'php' here at SO. (7th most popular tag). There are less than 800 tagged 'jsp'.

Scott Evernden
-1 the tag stats are meaningless and misleading. Many Java Web questions get tagged java and j2ee.
cletus
+1 to cancel out cletus. The tags are relevant, not to establish popularity, but for finding information about the language. If many PHP questions were tagged as Perl, it would be a lot harder to find PHP stuff.
Imagist
+15  A: 
cletus
One thing I should mention is that there are plenty of best practices for PHP (and Java as well) that can tighten up the security of both languages. Things like using prepared statements for DB queries, etc - none of which are all that hard to wrap one's head around, it's just a matter of knowing them.
Amber
There are an incredible number of PHP libraries out there, too, not to mention the fact that a lot of what requires libraries in Java is baked-in enough to PHP that you either get it for free with the language, or you just need a snippet from someone's blog or the PHP manual.
Xiong Chiamiov
There are 11,000 PHP questions on SO and 800 JSP, if that counts for anything.
Chacha102
@Chacha: no, it doesn't count for anything.
cletus
It means if he has questions, which obviously he will, he'll have a good chance of finding the answers here if he chooses PHP. It counts for something, regardless of your personal language preference.
UltimateBrent
+3  A: 

I wouldn't focus so much on the language. If you're going to be coding web applications, I would focus more on the common structures, such as Model-View-Controller and ActiveRecord. I've done more PHP than anything else, but I've done quite a bit of J2EE (Struts) and Ruby on Rails as well.

jessehanson1981
+1  A: 

As someone who has done web development in both JSP and PHP, my vote is to use PHP. Java programming and JSP programming are pretty much unrelated beyond the fact that they both run on the JVM and can interoperate a bit. If you do JSP, you won't be able to leverage most of your Java knowledge. Even with the slight advantage you would gain from already knowing Java, PHP would still be easier to learn. That's not to say PHP doesn't have some serious issues, it's just that it's on the whole a much better language than JSP.

If you wanted to use your Java knowledge, I would recommend Scala, Clojure, Jython, or nearly any other Java technology over JSP short of manually writing servlets.

Imagist
+2  A: 

It would be better to start with knowing what kinds of project you want or will be working on. Asking which language, framework or design pattern to use before determining the problem will just limit your options from arriving at the best possible solution.

Randell
+1  A: 

What is your goal? Java is widely used in large enterprise applications (although more than just JSP and raw servlets), and PHP is the king of small sites.

It's easy to find free no-ads shared hosts with PHP, but they won't be running a JVM.

OTOH, since you're already a Java developer, if you're just looking to expand your knowledge in what you already know, and be able to do similar things with similar companies, just on the web, then learning JSP (and its associated technologies) would be more useful.

Now, if you're looking to just do something quick and fun, I'd recommend taking a look at Python and Ruby. Django and Rails, respectively, are the predominant leaders in frameworks for those two, and, although there are several other good options, for you, I'd recommend one of those. If you do go this route, take a look at the examples, documentation and community of each to decide which one fits you better.

Xiong Chiamiov
A: 

Learn both. Since you already know Java, JSP is a very small amount extra to learn and shouldn't take terribly long. PHP is easy to grasp and can be picked up in a couple of days.

From what I have seen, PHP is used a lot more for open source web projects but JSP is used a lot in enterprise web apps.

Sionide21
A: 

PHP is easier to learn and write.Any new learner can start with PHP

pranay
A: 

If you're a programmer for 10 years, you won't need more than 10 days to switch from one platform to another... But now when Oracle is behind Java... Try to guess what will happen in next couple years :)

Speaking about security in web apps is ridiculous... Do not blame Java, PHP or any other language for your mistakes...

mangia
A: 

I use php and Spring and JSP, and I can say that JSP and String took me more time to learn but after you learn, you don't want to go back to PHP.

also I think you must learn Design Pattern, so this way you can organize your project.

Gabriel