How to get started with Java

Java
A friendly guide on how to get the Java development kit, a good IDE, and a great book.

Java is a powerful but easy to use programming language (not to mention that it’s the language used in most computer programming courses.) Java is a great language and fairly easy once you get everything set up – but getting everything set up is difficult. That’s what this guide is for.

Getting the SDK

Before you do anything, you have to get the JDK – the Java Development Kit or Java SDK (Software Development Kit). You need the SDK to write Java programs. Go to this page and click on the JDK download button.

Click on the cup of Java (the JDK download.)
Click on the circled button and download the proper file for your platform.

Download the installer and run it. Congrats! The Java SDK has now been installed on your computer.

Getting an IDE

Now that you have the JDK, you can start programming, but you’ll have to do it the old-fashioned way: write code in a text editor and compile it using the command line.

Unless, of course, you have an Integrated Development Environment, which is a fancy term for a program that helps you code. Believe me, it’s much, much easier coding using an IDE.

So which IDE should you use? Most people will recommend a couple to you:

  • BlueJ is a very simple IDE that’s good for educational purposes, but not very useful for large projects. Chances are you’ll be aiming a little higher than BlueJ will afford you. Not a bad IDE though.
  • JCreator is slightly more powerful, but it’s expensive, and the free version is barely better than coding the old-fashioned way (I’ll tell you, I have to use JCreator in school.) It’s clunky and lacks a lot of the neat features that the next 2 IDEs have. You might want to pass on this one.
  • Eclipse is a powerful, professional editor that a lot of pros use (and don’t worry, it’s free.) It’s very useful, if a little unintuitive, and regarded as one of the best IDEs out there. Definitely worth a look.
  • Netbeans isn’t as well-known as Eclipse, but it’s just as powerful and useful. It’s very similar to Eclipse, except it’s slightly easier to use and it has a very nice GUI builder. I personally recommend it, and I’ll be showing you how to use this IDE in this guide. You should use either Netbeans or Eclipse.

Go ahead and download and install and IDE (just click on the links to go to their sites.)

Making a project

Fire up Netbeans (you can register, but you don’t need to) and click on the box button with a plus sign on the toolbar. That’s the new project button. I’ll just be showing you how to make a new project – each Java app you make will be its own project. NetBeans will keep all the files in one central place for you.

Create a Java - Java Application.
Choose to create a Java > Java Application.

Create the Java > Java Application, then enter the name of your project – call it anything you like. You can change the other fields but that isn’t really necessary.

And voila! Your project is created. It’ll look a little like this…

The main screen of a NetBeans project
You’re viewing the main file of your project.

You can type what I typed (the line highlighted in blue; click on the image to view it full size) in that space and then click the green arrow button in the toolbar to run your application. (Don’t worry if none of this makes sense to you; you’ll be learning the language soon.)

If you see some output at the bottom of your screen, then everything’s worked – you can now write Java to your heart’s content.

If you want to add a new file, click on the page with a plus sign on the toolbar and select Java > Java Class. (Again, don’t worry if you have no idea what a class is, just go with it.) Enter the name of the file in the next step (if you want to create SomeFile.java, enter SomeFile in the text box.)

Now your screen will look a little like this:

The main screen of NetBeans
What your workspace will look like once you have multiple files

Notice the list of files in the left panel – just click on a file’s name to open it in a new tab. You can have many files – and thus many tabs – open for editing at once. Running your program still works as normal.

That’s all well and good, you say, but I have no idea how to write this Java thing. Do I need a coffee machine?

Getting a book

Obviously, you can’t write Java unless you learn it. If you’ll be taking a course on Java, you can stop right here. If not, you’ll need a good book to learn Java.

Trouble is, most of the books on Java are either incredibly boring, too complicated, or just flat-out bad. Thankfully, there’s an excellent book on Java by an excellent series – Head First Java. (Get it on Amazon.)

Head First Java
Head First Java is the most awesome Java book ever written.

If you’ve ever read a Head First book, you’ll agree that Head First books are great. They’re engaging, fun, and packed with useful exercises. No more boring lectures or drab textbooks that are heavier than dictionaries. No, Head First Java is actually useful and makes Java fun and easy. I used it myself and it was far better than a 9-month course (not to mention that the entire content of the course fit into about 100 pages of this book.)

Seriously, I can’t stress how great Head First is. Go ahead and buy it, and you can jump right in. When you start a new exercise, make a new project and add as many files as you need to.

Head First assumes you’re writing code the old-fashioned way by using manual compilation from the command-line. No need to do that – when they tell you to compile and run an exercise, just run the project on NetBeans. You can do all the exercises from the safety of NetBeans.

Goodbye

Thanks for your interest, and good luck with Java! I’m no Java expert but if you have questions feel free to comment on this post, email me, or ask me on Twitter.

Published by

Neel Mehta

Harvard College. Web developer. Sometime philosopher. Baseball junkie.

Leave a Reply