Getting Started Homepage  « Learn Java6 « Getting Started

In our first lesson on Java6 we download the latest JDK from the Oracle site and setup our environment. We then check that everything is working as it should by running a check to see if the Java compiler can be accessed from the command line.

Getting The Java Software Development Kit (SDK)go to top of page Top

Ok, before we delve into Java6 we need a Java SDK. The SDK contains everything we need to compile and run our Java programs. Even though we are using Java6 I suggest downloading the latest version of the SDK for use in these lessons. The latest version at the time of writing was Java SE 7u25. The download page can be found at this link Oracle SDK Download. The SDK includes the Java Runtime Environment (JRE) which you must have on your system to run Java applications. The JRE includes the JVM and some other library files and as such creates a JVM to run our Java applications at runtime.

The download comes in Windows, Mac, Solaris and Linux flavours, so after accepting the license agreement, just download the appropriate SDK for your system. When you install the download you get the option of choosing where to put the SDK on your hard drive. I am just using the default directory provided by Oracle, which in my case on my Windows 7 system is C:\Program Files\Java\jdk1.7.0_25\. Where you put the SDK is up to you but remember the path for a bit later in this lesson. I put the JRE in the default directory as well when prompted which in my case was C:\Program Files\Java\. You can register with Oracle after the download has completed for product updates etc.

Setting A Classpath For The Java Compilergo to top of page Top

Now we have the SDK installed we need to add a classpath entry to the Path environment variable for where the Java compiler command (javac) resides. First lets open a command line prompt and type in javac. Below is a screenshot of what happens when we do this on my Windows7 system.

java nocompile

The javac command lies within the bin directory of the filepath where the SDK was installed which in my case is C:\Program Files\Java\jdk1.7.0_25\bin\ and so we need to add this classpath to our environment variables. Below is a screenshot of how this is achieved on my Windows7 system and of course other OS will vary. But for Windows From Control Panel, select System >> Advanced System Settings and at the bottom of the window select Environment Variables. Edit the system variable "Path" and add C:\Program Files\Java\jdk1.7.0_25\bin\ (or whatever you selected as your filepath to the SDK) to the end seperating this classpath from the last with a semi-colon.

environment settings

Once you have done this press OK on the windows to close them all and reopen the command line prompt and type in javac. Below is a screenshot of what happens when we do this on my Windows7 system after adding the classpath. As you can see the javac command now brings up a list of options showing it is now on our classpath and can be used to compile our Java programs.

java compile

Are We Going To Use An Integrated Development Environment? (IDE)

You could use an IDE such as Eclipse or Netbeans for developing and compiling your programs in these lessons, but doing so will automate some of the processes that we need to learn to get a real grip of Java. So my suggestion is to use a command-line editor for now so we can see all the processes involved without them being abstracted away beneath the bonnet of an IDE.

Choosing A Text Editor

As we are not using an IDE, we need a simple text editor such as Notepad or Wordpad to write our code. For these lessons we will be using Notepad but the choice is dependant on your preference and OS of course.

The java.lang Packagego to top of page Top

Java comes with collections of classes which are held in namespaces known as packages. We can use these packages in our programs by using the import keyword followed by the namespace. We will talk about packages and how we import them in the Packages lesson of the API Contents section. For now and the next few sections of the site we will only be concerned with the java.lang package which is implicitly imported into all our Java programs for us.

Java Documentationgo to top of page Top

Java comes with very rich documentation that you will go back to time and again. The following link will take you to the online version of documentation for the Java™ Platform, Standard Edition 6 API Specification . I suggest adding this link to your browser's favourites toolbar for fast access.

What's Next?

Now we have the basic environment set up we can take a look at Java code structure and syntax. In the next lesson we will do just that and run our very first simple Java program.

<<  Beginning Java6                    Code Structure & Syntax  >>

go to home page Java6 Tutor Homepage go to top of page Top