How do I move from PHP to JSP/Spring without a J2EE background?
October 20, 2008 12:05 AM   Subscribe

Anyone have experience moving from PHP to Spring/JSP? What approach made the change easiest for you?

I'm comfortable in PHP. I know Java from a college classroom setting, but I've never had to help develop a J2EE app. I've looked at Spring tutorials (done the MVC step by step one), but the toy examples that they give just don't do it for me, probably because it seems like a lot of extra work for something I can write in PHP in a fraction of the time. I don't have a current project to work on, I just don't want to be caught with my pants down when the time comes when I'm required to use Spring and JSP. Anyone learn from sample Spring apps that aren't toys but also not ridiculously complex? Any other suggestions for the transition?

posted by secret.osha to Computers & Internet (1 answer total) 3 users marked this as a favorite
Best answer: I switched from PHP to "Enterprise Java" apps about four years ago. I had dabbled in Java before, but always treated learning it like I had other formal languages like C and (gulp) Pascal. Java has to be compiled, there's a certain structure that classes have to take, then you've got to configure your application server, get your environment variables playing correctly... all this work before you can even see your "Hello World" application.

PHP is like crack because most web servers are already configured to execute the scripts without any real intervention. Write a little code inside some brackets, and all of a sudden you get database connectivity out-of-the-box. You can get data-driven pages from a handful of database tables and two or three pages of code. It's simply remarkable the speed at which you can get started with PHP.

But that's simple data sets. What happens to PHP when you start adding additional data layers to the mix? Well, it starts to become unwieldy. If you've ever worked on a large-ish PHP app (like PHPNuke or phpsqladmin) you'll know what I'm talking about. Debugging problems with ECHO statements. Having to manually trace through dozens of dense include files... with Java you have so much more control during debugging than the needle-in-the-haystack approach of PHP. It just doesn't scale.

probably because it seems like a lot of extra work for something I can write in PHP in a fraction of the time

I used to think that way. I never would have made the transition if I hadn't started doing what I'm currently doing (financial services). When you've only got 5 tables in your database schema, Java looks too big for the task. When you've got hundreds of tables in your database, the situation rapidly changes. If your "application" is just a blog, for example, you've got a table with journal entries, a table for comments perhaps, maybe a table for users. When your application is a web interface for your company's customer service, collections, and financial summaries of a hundred thousand-odd accounts, each account having potentially thousands of transactions, then I can tell you that you do not want to be messing around with SQL.

Even a simple web page showing a customer's credit line can involve dozens of SQL queries. You don't want your programmers having to think about the database schema when they're writing a simple web page. You want them to be able to treat the data like an object. "Over here I'll have the Customer's account name, and over here their account number, and over here a little table with their last ten transactions." You don't want them thinking, "OK, I have to SELECT from the Customer table, JOIN on the User table so people can only view their own accounts, JOIN again on Transactions, do a LEFT JOIN on the Contact table to get their Physical Contact's phone number, ORDER it in descending by the TRX date...

As the complexity of your data increases, you reach a point where you are simply more efficient when you're given a stronger structure to hold things together. PHP is like scaffolding. There's nothing better for making quick models. But you get to a certain point, and you don't want to be dealing with the shit. Especially if you're working in a large business--there's too much room for error and the consequences more dire. I don't want to have to think about queries. I don't want to have to think about form validation. I want to write things that work, quickly.

And if the "Business" decides it wants another table, or wants to change a column from one data type to another, we don't have to re-write the entire application and all those hundreds of page-specific queries. When it's just YOU, you don't necessarily care if you have to start over from scratch. A team of people will care. :)

I've looked at Spring tutorials (done the MVC step by step one), but the toy examples that they give just don't do it for me

Spring is just an IoC layer (Inversion of Control)--you might end up using it, but there's no real need for it. A lot of popular frameworks don't even ship with Spring (though most can be hooked into it or, like Tapestry, come with their own flavors).

I would strongly advise you to take a look at the Stripes Java web framework. It comes with plenty of examples that should work right out of the box under Tomcat or Jetty. I think you should also look into some EL expression tutorials--they should make you feel more at home with their PHP-like inline style.

Once you've gotten a couple of simple web pages working, I would take a look at hooking up Hibernate to a simple database and learning about ORM (Object-Relational-Mapping). Also, while it's not imperative that you get a good Java editor, a good one can make working in Java a whole lot easier. I'm a huge fan of IntelliJ, and wouldn't you know it, it's free (well, technically a 1-month trial, which you can keep renewing for as long as you like... I know because I did for more than a year before finally biting the bullet! Eclipse is another popular IDE.)

Don't be daunted by the initial learning curve. A lot of this stuff is simply not intuitively obvious. I've found it's often very useful to try the sample web applications. Get Tomcat running, throw a WAR file into /webapps and fire it up. Then decompress the source and start poking around. Learn how to use your IDE, how to debug, and you'll be on your way.

PHP can become stifling when complexity increases. With Java, I instead find myself looking at businesses from a 10,000 ft. view. What are the large business objects, how do they subdivide, how easily could I represent the structure and its operations? Fun stuff that I never would have attempted tackling without Java.

Anyway, good luck.
posted by Civil_Disobedient at 3:46 AM on October 20, 2008 [7 favorites]

« Older Were you a social-climbing, Mercedes-driving...   |   You must be THIS nerdy to enter. Newer »
This thread is closed to new comments.