From PHP to Java

So I’m a Java developer for some time now and I’d like to share with you few things about the process I went through. I want to point few differences in the process, libraries and way of working between the languages.

A bit of background

I’m a senior developer and I was writing Java for some time already before I switched. Usually side projects but not that small. Turns out, as I was already writing quite complicated code structures in PHP 5.6/7 there was no big change when compared PHP to Java.

Another nice surprise was Symfony and Doctrine to be PHP clones of Spring and Hibernate. Knowing both frameworks helped me a lot with catching up with RAD in Java.

To be hones a lot of currently hyped tools for PHP (not Laravel) are based on Java tools. Just like composer being replacement for Maven/Gradle.

So what’s the difference?

First is deepness of the language. There is way more than associative array. Java, for each collection, has multiple implementations with different characteristics so you need to learn what is what.

OO model has also way more to offer. At the beginning you can play with PHP style of composing classes but when you have enum as first class citizen of the language you just want to use it :) Inner classes, static classes and I haven’t event started talking about streams or generics. On top of that there is concurrency, parallelism and need, or lack of need, of being thread safe.

A lot of stuff and I’m still discovering new keywords of the language from time to time.

Is it that bad?

Not really. Writing PHP in Java is very easy. It works a bit worse the other way around. Simple Spring apps are easy and fast to write. As I landed in the team of experienced developers it took me few weeks to learn what I was missing and is used in day to day work.

I think the biggest change for me was move from Composer to Maven. As PHP don’t require a lot of build features Composer is nice and simple. Maven on the other hand is a 20 years old monster with XML configuration. It’s not bad but it takes a while to get used to. After some time and few mistakes it’s pretty straight forward in use and there is a lot of tutorials.

Documentation

At the beginning of every journey into new language you’ll follow the Stack Overflow Driven Development methodology. And it’s working very well in Java as it’s one of the most popular languages in the world. 99.9% questions you may ask will be answered there.

When it comes to libraries it’s more hit and miss. Sometimes documentation is amazing and you can use it to basically copy/paste base solutions. Otherwise you end with digging through big manuals written in very corporate way and without many examples. From time to time you’ll probably end up reading the code as well. In my opinion tho, it’s the best solution anyway. I learn a lot faster by reading other people code than by reading dry manuals or books.

Tooling

As I mentioned before, Maven and Gradle are monsters of build. You need them as it’s not only about FTP files to the server ;) You need to compile your code and run it as binary package. Learning curve is steep but in few weeks of daily tasks you’ll learn a lot. Or at least enough to know where to look for template for new project.

IDE is great help. As you have a lot to choose from for free, like Eclipse of Netbeans, I say inteliJ from JetBrains is simply the best. Community Edition let you work on Java for free as well but without some features. I own my own licence for Ultimate version and it’s the best £20 I’m spending a month. Especially as a polyglot, where I’m using quite few languages supported by it.

What next?

Kotlin! You probably heard about it when Google made it one of officially supported languages for Android. It will soon be supported fully in Spring. With full interop with Java and more Scala-like markup it’s amazing tool to code. And it’s fun.

JVM has also Groovy, Clojure, Scala and a lot of other languages to play with. They will let you learn more about coding and still use your new favourite platform.

Summary

It’s more a journey than travelling from place to place. As I learned quite few things about language and libraries there is still a lot to do. Stay tuned. I’ll post another part in few moths on the next iteration of my learnings.