This chapter is all about getting you up and running with Java development on a PC. It's hardly enterprisey, and I imagine that the material will be old news to most readers, but I'd have gladly done [insert bad thing here] for one of these guides when I was learning Java. Feel free to skip to the next chapter, I won't mind.
You will need...
I'm using Windows for this book, but since we're doing Java you could choose any OS. I like Windows because it comes with a lovely picture of a hillside. Does a Mac come with that? I didn't think so :o)
Before you can develop Java software on a computer you need a JDK, which stands for Java Development Kit. It consists of the JRE (Java Runtime Engine) the Java virtual machine software that comes bundled with most computers, the Java API source code, the Java compiler, and some other stuff that nobody uses. It comes in 3 flavours:
Download the latest Java EE JDK from http://java.sun.com/javase/downloads. Make sure you select the "with Java EE" option. As of mid 2006 the options you want were “JDK 5.0 Update 6 with Java EE”, and the downloaded file should be called “java_ee_sdk_5_windows.exe”. Sun are very good at maintaining backwards compatibility so any future version will work fine. Do a default install and continue.
All projects need version control. For this book I'll be using Subversion (often called SVN), which is free and one of the best systems available. There is a very good book about Subversion available for free online that covers installation and use. In fact, it's the same book that O'Reilly sell a paper copy of.
The normal way to install Subversion is to install an Apache web server and then add Subversion as a module. I however am using Google's free hosted Subversion service at http://code.google.com/p/berniecode-ejfs.
Once you have finished installing Subversion you will have a repository URL. This is an address where you access your repository using a Subversion client over HTTP. You can visit and browse this repository with a web browser, but for a much richer interface you should download TortoiseSVN, which extends the Windows explorer to turn it into a Subversion client.
Throughout this book I'm going to be using the Eclipse IDE, which you can download here. My heart bleeds that I couldn't choose IntelliJ IDEA, which is a beautiful piece of software. The half-price personal licenses for developers ($250 from jetbrains.com) makes it excellent value for money. There's absolutely nothing you can do in IDEA that you can't do in Eclipse, but as an editor, IDEA is without parallel. What swung it in the end was Eclipse's support for the spring framework, which we'll use extensively in a few chapters time.
Go to the eclipse downloads page and download the latest stable version. When you start eclipse for the first time it will ask you to select a 'workspace'. This is a folder where you keep several related projects. Create a workspace somewhere sensible on your computer and continue to the first example I've ever seen of Mystery Meat Navigation used on a software product don't worry, you need never see this screen again.
The basic install of eclipse has not much more than a Java editor and compiler much more functionality is made available through plugins. Eclipse has a mechanism to download updates and plugins called "update sites" - web addresses that contain descriptions of plugins and their dependencies. It makes life very easy for you:
In the Package Explorer panel to the left of the Eclipse workbench, right-click and add a new project called HelloWorld. Call it Magical Schnitzel for all it matters. Select the "Java Project" type. If Eclipse hasn't guessed where your Java JDK was installed you'll have to click the "Configure JREs" link and enter the JDK you just installed earlier.
Right-click on the project and add a new class with a main method that prints something. Mine looked like this.
Click the Run icon (the green arrow) and you will be asked to configure a run configuration. This is the eclipse equivalent of deciding what arguments to pass in if you were compiling and running the program from the command line. Add a "Java Application" configuration like this.
When you run the project, you should see Hello World! in the console panel.
Finally, right-click on the project, and select Team > Share Project > SVN and enter the URL of your Subversion repository. Once this is set up you will be able to submit and diff files from the IDE.
OK, bored now, let's do something more fun...