Section 2.4. Gathering Your Tools

   

2.4 Gathering Your Tools

There are a number of things you'll need to get started writing and running Java programs. The first thing to do is download the most recent Java SDK, which, at the time of this writing, is 1.4.0. You can download the SDK from http://java.sun.com. You are likely to see a prominent link to download it on this page. If not, click on Products and APIs, and get the Java 2 Platform, Standard Edition.

Note

A Java compiler is included with the SDK downloadable from Sun. However, there are other Java compilers on the market, including the Jikes compiler from IBM alphaWorks. Originally a project of the Tom Watson Research Center, it is now exclusively an OSI Certified Open Source project. You may ask, why bother fiddling with another compiler when Sun's compiler ships with the SDK? Jikes offers high performance and includes analysis tools.


2.4.1 Installing the SDK

In order to use Java, your computer must meet the minimum requirements, which are 32 MB RAM and 180 MB hard drive space for 32-bit systems, and 48 MB memory for NT. You can download Java for free from http://java.sun.com. Click on Download and follow the instructions for the type of computer you have.

The SDK will come in a compressed file. Extract it to an easily accessible location on your disk. I will extract it to C:\jdk1.4 . There is no need to restart your machine.

Note

When JAVA_HOME is referred to throughout the book, it means the root directory of your particular Java installation, whether that is usr/local/java or F:\sdk1.4.0 or C:\jdk1 .4 or whatever you have called it.


There are two programs in Java that are central to your development. The first program is the compiler ( javac.exe ). When you write a Java program (class file definition), you save your file with a . java extension. You then run the compiler on it, which performs the translation into bytecode. The bytecode is output to a new file that the compiler creates. This file has the name of your Java program, but is saved with a . class extension. This is an executable file, which you run by passing the name of the program as an argument to the second important program in the SDK: the Java interpreter ( java.exe ).

Generally, Java developers write programs in different packages. A package is a namespace used to minimize name conflicts and to promote organization of code. Each package basically corresponds to a directory on your hard drive. So, for instance, to create a package called "JavaForCF," we just create a regular directory of that name under the place that we are keeping our project class files. We assign a particular class file to a package using the package keyword within the class definition. We will discuss packages in greater depth later. For now, create a folder under your JAVA_HOME location called "JavaForCF" (for example, C:\jdk1.4\JavaForCF ) ; we will put all of our code in here.

At this point, you could compile and run a Java program that you place in the JAVA_HOME\bin directory. Because this is where the Java binaries are kept that make Java work, this is obviously not a very safe or portable place to put your code. In order for Java to be able to find your programs and execute them wherever you place them, you need to do a little bit of configuration. The configuration is slightly different for different platforms. Once Java is up and running, however, the rest of the material in the book should work about the same, regardless of platform.

2.4.2 Setting the Execution Path

After you have installed the JDK as discussed above, you need to do just one more thing: You need to set the execution path. The execution path is the list of directories that your operating system traverses to find executables. This is an environment variable that will make the location of your Java executables accessible wherever you are in the directory structure.

2.4.2.1 ON WINDOWS XP

Go to Start > Control Panel > System > Advanced > Environment Variables. Find the PATH variable. Double click on it to add JAVA_HOME\bin to the beginning of the path (for instance, you might add C:\jdk1.4\bin ; to this string). Semicolons are used to separate variable entries. Click Apply and Save. Once you open a new command window, it should have the correct path settings. You do not have to reboot.

2.4.2.2 ON WINDOWS 2000 AND NT

Go to Start > Control Panel > System > Environment. In the User Variables window, find the variable called PATH. Double click on it to add JAVA_HOME\bin to the beginning of the path (for instance, you might add C:\jdk1.4\bin ; to this string). Semicolons are used to separate variable entries. Click Apply and Save. Once you open a new command window, it should have the correct path settings. You do not have to reboot.

2.4.2.3 ON WINDOWS ME/98

Find your AUTOEXEC.BAT file. Open the file with a text editor and place the following line at the end of it:

 SET PATH=c:jdk1.4\bin;%PATH% 

where c:\jdk1.4 is the path where you've installed Java (what we're calling JAVA_HOME ).

2.4.2.4 ON UNIX, LINUX, AND SOLARIS

Setting the execution path is different depending on what shell you are using.

If you use the C shell (Solaris default), open your ~/. cshrc file and add a line such as this:

 set path=(/usr/local/jdk1.4/bin $path) 

If you use the Bourne Again shell (Linux default), open your ~/.bashrc or ~/.bash_profile file and add a line such as this:

 export PATH=/usr/local/jdk1.4/bin:$PATH 

2.4.3 Testing Your Installation

You can perform a quick test to see if you set the execution path correctly. Open a command prompt and type

 java -h 

This invokes the Java executable with the "help" option. If a list of arguments prints out, you have done everything correctly. If you get a response such as "The name specified is not recognized as an internal or external command, operable program, or batch file," or "Bad command or file name," or other similar message, something is wrong and you need to go back and check your work. Make sure that there are no spaces in the text when you set the variable as described above.

2.4.4 IDEs

There are a great number of Integrated Development Environments (IDEs) that can make it easier to write, compile, and deploy Java applications. These include Borland's JBuilder, Forte for Java, IntelliJ's IDEA, WebGain's VisualCaf , and many more.

Note

As a ColdFusion developer, you may be familiar with related products by Macromedia, such as JRun Studio and Kawa. Kawa is an IDE for creating JSPs, EJBs, and Java code. This product is currently in EOL (end of life) in favor of Macromedia's partnerships with other, more popular IDE vendors . JRun Studio 3 is another IDE (like ColdFusion Studio) that uses HomeSite as its codebase . If you are used to using ColdFusion Studio, then you will find that JRun Studio is essentially the same product with the added benefit of seamless access to your Java compiler and a couple of buttons for writing JSP directives. JRun Studio has been discontinued in favor of Dreamweaver MX.


Full-featured Java IDEs are typically expensive. While an HTML or Web app code editor typically costs between $100 and $400, enterprise Java code editors with support for JSP and servlets, easy GUI tools, and XML support often run in the thousands of dollars. There are excellent tools that are less expensive than this, and some are even free. For instance, IntelliJ runs about $300, and there are some excellent free IDEs such as Forte, Eclipse, and NetBeans. We can use a simple text editor to write Java programs for now.

Tip

If you use Notepad on Windows 2000 or earlier, remember that your Java source files need to have the file extension .java . If you try to save your source code file for "MyProgram," you might end up with a file called MyProgram.java.txt , which wouldn't compile. You can solve this problem by including quotes around your file name when you save it or by choosing Save as Type: All Files. You do not need to do this on Windows XP.


Some of the more popular IDE products and how to use them will be discussed in Chapter 6, "IDEs."


   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net