May 24 2006

HOWTO: Getting started with Java

Tag: HOWTO, JavaDan @ 7:22 pm

This is a rough quick start guide. It was written to help a relative of mine who was starting to learn Java.

  1. Get the Java Development kit here: Java Platform, Standard Edition (Java SE). The current version at the time of writing is Java 5
  2. Once installed set the following environment variable in order to ease use of the development tools on the command line. This environment variable is used by various tools including Ant and Tomcat also.

    JAVA_HOME=[set this to the path you installed Java in]

    The default install location for Java 5 on Windows is C:\Program Files\Java\jdk1.5.0_06.

    To set permanent environment variables on Windows XP/2000:

    1. Right-click on My Computer icon
    2. Select Properties from the context menu
    3. In the dialog that appears click on the ‘Advanced’ tab
    4. At the bottom of this tab there is a button labelled ‘Environment Variables’ click it
    5. In the dialog that appears create the new environment variable in the bottom box labelled ‘System variables’ - that will set the variable for all users of the system.

    This process is completely different on Unix/Linux systems, I can describe the setup process for Redhat and Ubuntu systems in a comment if someone needs it.

  3. Next make sure the Java executable binaries are on your system path, this is so that you can use the Java tools to compile your code. On Windows modify the definition of the Path environment variable to include this at the very end (semi-colon at the beginning is required):

    ;%JAVA_HOME%\bin

    When the system loads %JAVA_HOME% will expand to the value you defined in point 2.

  4. Test the setup from above by opening a command console (Start > Programs > Accessories > Command Prompt) and type:

    java -version

    You should see the following output:


    java version "1.5.0_06"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
    Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

    If you don’t get that type set to list the environment variables and check that the two variables you set in steps 2 and 3 are ok.

  5. Now you are all set to start learning. I recommend starting with the Java Tutorial.
  6. For alternate/advanced coverage see Bruce Eckel’s free book “Thinking In Java”.

Advice

  • Don’t use an IDE to start coding Java. It may get you started quickly but IDEs hide a lot of the real details of how a technology works. Eventually all good developers need to understand these details; it’s quicker and easier to do this from the start. Get yourself a decent text editor and learn to use the command line tools. Once you understand how Java works an IDE such as Eclipse can be very empowering.
  • Decent editors are (IMHO on Windows): JEdit, Notepad2, Vim, of course there are many others ;)
  • When you get fed-up typing javac to compile your code learn to use Ant
  • Learn as much as you can about Object Orientated Programming

Enjoy.

This was written quickly so if you notice any mistakes or things which could be improved please add a comment and I’ll fix it.