Java and PHP


This article is an ongoing list of the similarities and differences between Java and PHP.

If you learn any programming language, you're at a benefit over a complete newbie, because all languages are similar.

If you know PHP, especially now that's it's object-oriented, you'll have little to no problems learning Java.

Most programming languages are very similar. In fact, most of them are derived from the same language.

PHP and Java are similar because they're both derived from the same language, which is C. Thus, if you know one, it's pretty easy to learn the other.

Below proves how similar they are.

This is an ongoing list, so more functions are going to added regularly.

Function Java Function Java Example PHP Function PHP Example
Break up a string based on a parameter in the string split() string.split(", "); explode() explode("," , $string);
Extracts a substring from a  string substring() string.substring(3); substr() substr($string,3);
Replaces something in a string replaceAll() string.replaceAll("m", "n");

//replaces m with n
str_replace() str_replace("m", "n", $string);

//replaces m with n
Finding the length of a string length() string.length(); strlen() strlen($string);
Finding the position of something in a string indexOf() string.indexOf("m");

// finds position of m
strpos() strpos($string, "m");
Making a string lowercase toLowerCase() string.toLowerCase(); strtolower() strtolower($string);
Making a string uppercase toUpperCase() string.toUpperCase(); strtoupper() strtoupper($string);

So the above list is just a brief list of functions that are somewhat similar in PHP and Java.

Let's not get started on object-oriented programming.

I really think that PHP cloned Java's OOP, so that those already familar with Java will feel right at home with PHP and vice versa. Those familiar with OO PHP will learn OO Java really quickly.

A lot of them even use the same exact name. When I get a chance, I'll go over the specifics of the similarities and differences in object-oriented programming in Java and PHP.

I just wrote this to give you confidence that if you know one of these languages, you can learn the other relatively easily.

And programming all ties in. If you know one programming language, you can most likely learn another.

And even more than the programming language is the programming concepts that you learn. Once you learn a programming concept, you know the concept, so it's just learning how to implement in a specific language. So, in my opinion, learning a programming concept is more powerful than just knowing how to do something in a certain language. So once you know a concept, it's just figuring out how to implement it in a given language.

Related Resources

How to Create a Final Class in PHP

HTML Comment Box is loading comments...