Page 1 of 1

java vs php

Posted: Mon Oct 31, 2005 7:30 am
by shiznatix
ok im learning more about classes and objects by learning java but do the same rules apply like private and static and everything? i have not really used php as very OO but have just used classes to group functions and then make things a little more organized for myself but if this java stuff applies then things might make a lot more sence to me.

Posted: Mon Oct 31, 2005 7:39 am
by Chris Corbyn
Alot more so in PHP5 yes.

Java is pure OO so it's not the same but a lot of the concepts still apply.

In PHP5 you can use overloaded methods, declare interfaces, assign properties/methods as private, public or protected, create abstract classes etc.

Don't forget PHP isn't natively an object oriented language so it's far from perfect.

Posted: Mon Oct 31, 2005 7:54 am
by Jenk
They have different abilities :)

Java creates standalone apps, as well as applets/weblets/serverlets. Where as we should all know, PHP is limited to Webservers, or more specifically, HTTP Requests :)

Posted: Mon Oct 31, 2005 8:15 am
by Chris Corbyn
Jenk wrote:They have different abilities :)

Java creates standalone apps, as well as applets/weblets/serverlets. Where as we should all know, PHP is limited to Webservers, or more specifically, HTTP Requests :)
Ohhh noo... you're wrong my friend. PHP is capable of creating Command line applications too. It can even use ncurses and stuff. It does more than you may think. I regularly write command line apps for linux using PHP.

I believe it won't be long before we can start compiling it into machine code too ;)

Posted: Mon Oct 31, 2005 9:19 am
by Moocat
Java tends to be more memory intensive and have a steeper learning curve as well. The initial is all fine and dandy but it ramps up sharply as you get into building actual "useful" applications. I've found PHP to be FAR simpler to integrate as well, Java having more compatability issues than you can shake a tree full of monkeys at.

Posted: Mon Oct 31, 2005 9:45 am
by foobar
Moocat wrote:Java tends to be more memory intensive and have a steeper learning curve as well. The initial is all fine and dandy but it ramps up sharply as you get into building actual "useful" applications. I've found PHP to be FAR simpler to integrate as well, Java having more compatability issues than you can shake a tree full of monkeys at.
Definitely, which is one of the reasons I've migrated from Java to PHP. PHP gets the job done fast. It may not always be totally OO, but if you separate display from business logic, you're fine.

Posted: Mon Oct 31, 2005 9:59 am
by Moocat
Java isn't totally useless though, it has it's part in large applications, but unless it's something that's REALLY big, like an airport control center, that's going to take a few years to develop, I find PHP to be far easier, faster and more efficient, even in the long run (if coded properly).

Posted: Mon Oct 31, 2005 10:04 am
by Weirdan
d11wtq wrote: Ohhh noo... you're wrong my friend. PHP is capable of creating Command line applications too. It can even use ncurses and stuff. It does more than you may think. I regularly write command line apps for linux using PHP.
Moreover, it's possible to create standalon GUI apps (using php-gtk)
I believe it won't be long before we can start compiling it into machine code too ;)
It's possible to compile php into byte-code and encapsulate it into executable file (using bcompiler). It isn't "machine code" exactly, but it's as close as compiled java applications are.

Posted: Mon Oct 31, 2005 12:23 pm
by timvw
shiznatix wrote: ok im learning more about classes and objects by learning java but do the same rules apply like private and static and everything?
You might want to precise which php version against wich java version you want to compare.
Basically, the basic OOP concepts in PHP5 and Java5 are very alike.

If you're learning about classes and objects (=instances of classes), i would advise not to focus on language specific/syntax details. Instead focus on inheritance and composition. Just as you've learned to recognize repeating stuff and to put it in a functions you should now learn to recognize stuff that shares the same behaviour. Once you can do this, you can take it a step further and try to recognize patterns. Patterns are even more abstract, they are about the behaviour between objects.