Tutorials

How To Do It!

In most people's experience we all have run into areas where a little extra insight would have smoothed the learning curve of a new subject. The information below is meant to provide that insight, hopefully identifying the common pitfalls more experienced people have struggled against. These are not meant as replacements for existing, comprehensive documentation (where it may already exist), but are meant more to serve as guideposts on the path toward enlightenment.

Note: Please endure with me as I build this section. Once the content is complete, it will be formatted more betterer. Thanks!

Title Summary
My First Java Environment How to set up a Java environment on a Windows system for free
From Zero to Applet in 60 Minutes How to write your first Java applet
Graphics Files Coming Soon
VGA Compatibility Requirements Coming Soon
Protecting Yourself Against Viruses And Other Malware Coming Soon




My First Java Environment

Who is this written for?

It is expected that you have at least some technical background, with at least a remedial understanding of web pages, the Internet, and your operating system (i.e. Windows). For example, I will assume that you know how to copy files from one folder to another. However, if you don't know the difference between a file extension and a hair extension, perhaps this isn't the appropriate tutorial for you.

Still with me? Excellent. Let's get your Java development set up. Here are the key points I will cover:


The Java Runtime Environment

Before starting on any Java development, it is essential that your machine already have the most current Java Runtime Environment installed. Note that the Java Runtime Environment is sometimes called the JRE for short. Under Microsoft Windows, Internet Explorer and most other browsers require a third-party plugin to execute Java. If you're not sure if your browser is Java-enabled, try this quick test: Java Runtime Test.

The latest version of the JRE is available from Oracle/Sun Microsystems at: Java Runtime Environment. You'll need to install this before going any further. Once it's installed, try the Java Runtime Test again to verify your browser is Java enabled.


The Java Development Kit (JDK)

Downloading

Now it's time to get to the real, hard-core stuff. There are many versions of the JDK to download (and usually several bundling options), so you'll have to choose the one that best suits the types of applications you'll be developing. Since we're focusing on applets, we should get the Java SE Development Kit.

Caveat: Please note that version numbers and web pages are at the discretion of Oracle/Sun and therefore are subject to change without notice.

The JDK we're most interested in can be found on this page: Java SE Downloads. Look for the latest release of the "Java SE Development Kit (JDK)". It's usually a standalone item, not a bundle. Click the "Download" button and save it to your hard drive.

JDK Selection

Make sure to choose Windows as the platform before pressing Download. Note that older versions required you to check a box to accept the license agreement terms and conditions, but that seems to have morphed into an implicit agreement now when you click Download.

JDK Platform

Next, if you have not logged in using a Sun Online Account, a popup appears to allow you to enter your name and password. While membership can certainly be beneficial, it is not necessary for this download, so just click on Skip this Step to continue.

The download should begin immediately; if it doesn't start, you may have to right click on the filename (e.g. jdk-6u18-windows-i586.exe) and save it to your local hard drive. Remember where you save it, because you'll have to find it later to run it! Note that if you have a slow connection (i.e. modem), then you should consider using the Sun Download Manager in case you get disconnected during the download. Otherwise, using a broadband connection which downloads in less than ten minutes, it's probably not necessary.

JDK File

Once the download starts, hit the BACK button a couple times until you return to the original download page. Just under the download button is a "Docs" link. Click that to download the Java SE Documentation. It's convenient to grab it now, because you're there already, but I'll explain installing it in the next section.

JDK Documentation

Select the language ("English" would probably be a good choice) and check your agreement with the license agreement before pressing "Continue".

JDK Documentation Platform

Next you right click on the filename (in the example it's jdk-6u18-docs.zip) and save it to your local hard drive. Note that if you have a slow connection, then you should probably use the Sun Download Manager.

Java Documentation File
Installation

So far, so good? You should have two downloaded files now. One is the executable used to install for the JDK (e.g. jdk-6u18-windows-i586.exe) and one is the zipped documentation (e.g. jdk-6u18-docs.zip). We'll concentrate on the JDK installation, and save the documentation installation for the next section. The first thing you need to do is to find and open the folder that you've downloaded the files into.

Download File Folder

Double click the executable file to begin the installation of the Java Development Kit. It will do some housekeeping, then present you with the the license agreement. Accept it to continue (declining it will end the installation).

Next it'll give you the option of what you want installed, just accept the defaults, which should be "install everything", by clicking Next. It will then install the JDK onto your system into a folder like C:\Program Files\Java\jdk1.6.0_18.

When the JDK has been installed, it will attempt to install the latest version of the Java Runtime Environment (JRE). Allow it to do that by clicking Next again. Note that if any browsers are open, it will ask you to close them. You may wish to bookmark this page before closing your browser so you can resume after installation is complete. Follow all instructions to the end, then follow the instructions in the next section to install the documentation.

Setting the PATH Environment Variable

One last manual step, and it's an important one! Failure to do this may result in your tools not running: set the environment path to include the JDK binaries.

What to set depends on the version you've downloaded, and where the JDK installed to. You will need to append the \bin subdirectory name to the installation directory name before adding it into your path environment. Using the version in this example, and taking the default installation path, I added C:\Program Files\Java\jdk1.6.0_18\bin to the end of my environment path. If you need more information on how to set your environment path, go here: How do I set or change the PATH system variable?

Registration

Oracle/Sun will prompt you to register the JDK with your Sun Online Account. Membership and registration is purely optional. I won't suggest whether it would be or would not be beneficial to you, the developer, but here's the blurb from their web site:

After you register your Java Development Kit (JDK), you will receive these benefits:


The Java Documentation

Installation

This section will explain how to install the Java documentation that you downloaded with the Java Development Kit in the previous section. It's pretty straightforward, but it's a manual installation.

Find the ZIP file you downloaded earlier (e.g. jdk-6u18-docs.zip). It's compressed, so you'll need to use WinZip, WinRAR, or whatever you use to read compressed files to open up the file. Double click on it to open it and you'll find a doc folder inside.

You'll need to copy that folder over to where the JDK was installed. Since the Java Development Kit installs into a version specific directory, you'll have to copy the documentation into the appropriate folder. Note that this is only an issue if you have previous versions of the JDK installed. For example, if you took the defaults, the folder you are looking for is something like C:\Program Files\Java\jdk1.6.0_18.

Simply extract the doc folder from the ZIP file into the JDK folder, so that there is a doc folder in the JDK directory (e.g. C:\Program Files\Java\jdk1.6.0_18\doc), and the documentation is installed.


Text Editors

Introduction

A text editor is necessary for editing the source code of a program, editing the source of the HTML files necessary to make web pages, and for a myriad of other purposes. Where a word processor is good for creating beautifully formatted text with tables and various fonts, a text editor is used to create the files that can be read by programs that require flat ASCII files, such as compilers, interpreters, and browsers.

Feel free to use your own text editor, just be sure it can save text into a non-document or flat ASCII format. A word processor, like Microsoft Word, is not well-suited to that task because it adds proprietary formatting information to the text. In the next section, I describe installing TextPad, which is a fairly popular and feature packed shareware text editor.

Installation

Open up TextPad.com and click on download. A page is presented with various language options. Choose the appropriate language and method of download (both FTP and HTTP should work with most browsers). Remember where you save the file, because you'll have to find it later to run it! Depending on the language and current version, the file will be called something similar to txpeng531.exe.

Download TextPad

Find the file you just downloaded (e.g. txpeng531.exe) and double click on it to run it. Follow the instructions on screen and TextPad will install itself. I like to associate .txt files with TextPad since it is a better editor than NotePad, but I'll leave that as an exercise for the reader.

Registration

Like any shareware, if you find the software to be useful you have a moral obligation to pay for it. Though it will remain completely functional, after a period of use, TextPad will periodically remind you to register it.


The Integrated Development Environment (IDE)

Download

An Integrated Development Environment (IDE) simplifies the creation of programs by providing most of the programming resources a software developer needs in one neat, little package. One well-known IDE is Microsoft Visual Studio. However, since Microsoft no longer supports Java, that is probably not a really good option for Java development. I recommend using an IDE that you are comfortable with, familiar with, and supports Java editing, compiling, and debugging. One such IDE, is Eclipse, an open source IDE provided by the Eclipse Foundation.

Open up the Eclipse Download page and select the Eclipse IDE for Java Developers package for download.

Select Eclipse Package

When the download page appears, select the site to download from. Remember where you save the file, because you'll have to find it later to install it! The file will be called something similar to eclipse-java-galileo-SR2-win32.zip.

Download Eclipse
Installation

Find the ZIP file you downloaded earlier (e.g. eclipse-java-galileo-SR2-win32.zip). It's compressed, so you'll need to use WinZip, WinRAR, or whatever you use to read compressed files to open up that file. Click on it to open it and you'll find an eclipse folder inside.

There is no installation program, but the manual install is pretty straightforward. You'll need to extract that folder onto a hard drive. If you use your C: drive for most of the tools, then I recommend that you use that. It takes about 100MB of space, so make sure there is enough room first. Simply drag the eclipse folder into your C:\ folder.

I recommend one final step, just to make things easier later. Create an Eclipse shortcut for the eclipse.exe that's in the C:\eclipse\ folder, and move it to your desktop. To do this, right click on the Eclipse executable, eclipse.exe, and then select Create Shortcut from the popup menu. Drag the newly created shortcut to the desktop, and installation is complete.

IDE Setup

Double click on the Eclipse shortcut icon (if you created one as recommended in the previous section, or double click on the executable directly, otherwise) to start Eclipse. When Eclipse is first run, it needs to know where you want to create your work directory, and will prompts you for workspace folder immediately. This can be changed later, but the default choice is probably good enough - at least to start with.

Eclipse Workspace

There should be no need to set up Eclipse for Java if you set up the JDK path correctly in the previous section. Eclipse automatically uses the first JDK it finds in the path.

Furthermore, the first time it starts, Eclipse presents a Welcome screen. You'll have several choices in the form of strange icons, but the two most important are the Tutorial and the Workbench. If you wish to learn many of the facets of the IDE, or if you are unfamiliar with IDE's in general, I recommend going through the tutorial.

Eclipse Tutorial Eclipse Workbench
Testing The Setup

The following sequence can be used to test your setup. I won't attempt to explain the steps along the way, nor will I attempt to debug any problems that occur. It is meant only as a quick yes/no verification that your setup is working.

If you do find you are running into trouble, Eclipse has a good help system. Click on the Help menu, select Help Contents to pull up the help window. Then select Java development user guide. There is an article called Java development overview; clicking Basic tutorial should walk you through the setup in more detail than I have provided here.

Start Eclipse up, and click on the Workbench icon of the Welcome screen. Click on the File menu, select New, and click on Java Project. Enter a Project Name of GetVersionApp and then click the Finish button.

Eclipse New Project

Next, find the GetVersionApp project in the Package Explorer tab (below the File menu), and clicke [+] box to expand the contents of the list. Right click on the src folder, select New, and click on File.

Eclipse New File Menu

Enter a File Name of GetVersionApp.java and click the Finish button.

Eclipse New File

Next enter the following text into the editor:

class GetVersionApp
{
   public static void main (String[] args)
   {
      System.out.println ("This version of Java is: " +
         System.getProperty ("java.version"));
   }
}

Finally, click on the Run menu, and select Run. If prompted, run it as an Application, not an Applet. If you've completed the setup and entered in the above program correctly, then the Console Window should display the version number!

Eclipse New File

Links - For Further Study


Definitions - Useful Terms Related To This Tutorial

Eclipse IDE
Initially built for Java developers, it is now considered a multi-language software development platform; currently the IDE of choice for many Google Android developers.
GlassFish
Application server for the Java EE platform. Typically not used in standard Java application development.
IDE
Integrated Development Environment - used as a complete soup-to-nuts development platform that includes editor, compiler, linker (when appropriate), and debugger. Examples of IDE's include Microsoft Visual Studio, NetBeans, and Eclipse.
Java EE
Java Platform, Enterprise Edition - used to build Java applications that are typically server based. Additional libraries are provided to create fault-tolerant, distributed applications with modular components.
Java ME
Java Platform, Micro Edition - used to build Java applications that are typically executed on mobile phones or set-top boxes.
Java SE
Java Platform, Standard Edition - used to build Java applications for general use.
JavaFX
Scripting language that executes on top of Java.
JavaScript
Interpretted language used in many web browsers, mostly unrelated to the Java language, though it may be used in communicating between Java applets and the web page itself.
JDK
Java Development Kit - tools used to build Java applications.
JRE
Java Runtime Environment - the interpreter that runs in your browser.
NetBeans IDE
Popular IDE for many Java developers.



From Zero to Applet in 60 Minutes

Under construction.




Graphics Files

Coming soon.




VGA Compatibility Requirements

Coming soon.




Protecting Yourself Against Viruses And Other Malware

Coming soon.