Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Nick Zachary
Nick Zachary
6,816 Points

How is php superior to java?

Hi, How is php superior to java? It seems like there almost the same, but java is more wide(beginner understanding). Why use/learn php when you could use java?

5 Answers

Are you meaning to say javascript?

If not, then because Java is severely unsecure and that's why they have to update it all the time. It requires the user to have java installed on their computer and they have to run the app which could potentially steal info from their computer that they don't want taken. With technology where it is, there are lots of options other than it that will work better and make your users happier.

Nick Zachary
Nick Zachary
6,816 Points

Interesting, so I mean java script :P

Aaron Martone
Aaron Martone
3,290 Points

Hey Nick.

Javascript is a client-side language and PHP is a server-side language. What this comes down to is that they have their limitations. Personally, I use ColdFusion for a server-side language (but to each their own) Javascript is actually interpreted by the browser (different browsers support different versions of Javascript, and others, like IE, can even support proprietary technology like JScript - which is a bad thing).

In short, Javascript can communicate with the client browser, but it cannot communicate with the server (without it making separate requests and parsing the response, which is the basis of the technology known as AJAX) You probably know HTML. On its own, HTML cannot do dynamic things. Like if you were tasked to create a page that displayed a smiley face picture for whatever day of the month it is (17 smiley images for the 17th of the month), HTML on it's own, cannot fulfill this request. PHP and other server-side languages have access to variables and functions that can be used to complete such a task. For example, in ColdFusion, it would look like:

<cfloop from="1" to="#day( now() )#" index="i"> <img src="smiley.gif" alt="smiles!" /> </cfloop>

PHP, ASP.NET and other server-side languages have their own syntax to do likewise. So in short, you need a server-side language AND client-side (Javascript) to get the best of both worlds.

What Aaron said is correct. To add: Javascript can do server side stuff as well but I think it's pretty advanced. I've never done it so I don't have experience but tools like Node.js make it possible and can be used to make some really cool and interactive sites!

Aaron Martone
Aaron Martone
3,290 Points

Oh, and to expound a little on the difference between client and server, think of client as the user at a website, and think of server as the actual computer that is serving the website to your users. Remember! The web is "stateless". That means if you request a page, say, "index.html" and then you click to go to "contact.html", between those 2 visits, the server doesn't really know that you're the same person who just a moment ago requested index.html.

When we start to introduce technology like cookies "which allow the website to store information on the client computer that is sent back on subsequent requests" the server can then see "Hey! You're the person who just requested index.html before that" and begin to track the user's "session".

There's lots of technology out there and it can become very overwhelming. Just know that server-side languages use their own code (that you write) to serve up HTML. CSS is used to style that HTML. Javascript is used to interact between the client and server. So in your first example, PHP = Serverside language, Javascript (which is different than Java) is the clientside language.

Now, Java CAN be a serverside language. They are galled JSP or Java Server Pages. It is like ColdFusion, ASP.NET, PHP, etc. (a serverside language)