So
you want to develop in Java for the web and you’ll be getting to do just that
in the near future (or so the powers that be keep saying…), but you find
yourself hopelessly confused in conversations with experienced Java
developers. Terminology, environment,
setup, which is what? What do I need?
What’s a servlet and why do I want to know about that stuff? I must not be cut out for this, as I can’t
even get Hello World or the tutorials
to work. Heeeelllp!
If
you’ve ever felt that way, as I have been recently, I’m here to say you need to
break things down into what you really need to know and keep it simple. After much struggling with just getting a
solid understanding and my environment set up, I thought sharing my lessons
learned with you might help those of you experiencing similar stress. That is, you already understand how the web
works, you’ve done programming, and you’re PC savvy, but you just can’t wrap
your mind around the whole Java thing.
What do I need to get started?
Java
is an incredibly robust object oriented programming language that has many
different facets to it. From the
Standard Edition to the Enterprise Edition to the Micro Edition, additional API’s,
and all the technologies incorporated within such as Java Server Pages (JSP)
and servlets, JDBC, and many more - why its enough to make your head spin. All things Java, a veritable online tome,
can be had at http://Java.sun.com. This is the site to go to for any downloads,
online tutorials and documentation. I
have found this site essential, however, if you don’t know what you’re looking
for, it can be very overwhelming and add to your confusion. Be patient with it and get advice from other
real live people when you can.
My
biggest confusion with all the terminology and different pieces was that I just
wanted to know – what are the basics I need to get set up and start working on
web applications? I finally got my
answer through trial and error, and guidance by an experienced Java guru. Here’s what I learned….
Platform
Requirements:
·
JDK
– the latest Java Development Kit (currently version 1.3.1) that consists of
the compiler, interpreter and other executables, the Java Runtime Environment
(Java Virtual Machine), and the standard class libraries.
·
Web
Server with a servlet engine (example: Iplanet, Tomcat, Weblogic, JRun)
Once
you have these 2 pieces, you can essentially write, compile, and run Java code
in a web environment (servlets and JSP).
(You can also run applications and applets, but for the sake of my
story, I am focusing on web development and Java to mean JSP and
servlets.)
Some
additional platform requirements that, for all practical purposes, you will
need include:
·
An
Integrated Development Environment (IDE) such as JBuilder or Visual Café just
to name a few. Keep in mind, though,
that you can do everything you need to with a text editor and the tools in the
JDK. In fact, as with all languages, it
is best to learn either in textpad or with little assistance from an IDE until
you are thoroughly versed in the language.
·
JavaMail
– a Java mail application (you can download from the Sun Java site) that
provides an API for you to send e-mail through your Java programs.
Once
you’ve gotten your software installed, you will need to make some
configurations to your environment to make things work. Assuming a Windows
environment, these include (the same types of configurations are required on
UNIX as well):
·
Set
the PATH variable to include the path to the JDK executables (ex:
c:\jdk1.3.1\bin). This will allow you
to access the Java executables from anywhere in your environment without typing
the fully qualified path.
·
Set
the CLASSPATH variable to include any classes and JAR files you will be using
throughout your standard environment.
For example, if you were using JavaMail, you would include its JAR files
in the CLASSPATH (ex: C:\JavaMail-1.1.3\mail.jar;C:\JavaMail\activation\jaf-1.0.1\activation.jar;
C:\JavaMail-1.1.3\smtp.jar;). If you
keep getting errors like “Class Undefined” when you try to compile things, the
CLASSPATH is the place to solve your problem.
·
Set
up a default directory structure for your web server. For example c:\www as your default web root, c:\www\servlet for
your default servlet directory and so forth.
·
Add
the mail.jar files to the Java Runtime Environment under the JDK
(jdk1.3.1\jre\lib\ext directory).
·
Configure
your web server to work with your JDK, point it to your servlet default
directory, and enable JSP support.
Once
you have these settings completed, you want to test a simple servlet and JSP
page such as Hello World in order to
make sure all is working before you start into development. In addition, before you start using your
IDE, you will need to configure its project properties to utilize the proper
directories in your structure and to include any additional required libraries
(such as JavaMail for example).
What is What?
By
no means will I be able to tackle the universe of terminology associated with
Java, but I would like to shed some light on a few of the terms I heard over
and over about which I was initially confused.
For instance, the term Java tends to be used to refer to anything Java
related. Java itself is really like an
umbrella encompassing its many flavors.
Java can be simply defined as
a high level object oriented programming language that is platform
independent. JavaBeans are objects written in Java whose implementations conform
to conventions that allow it to be modular and reusable. JavaBeans encapsulate its data,
functionality, and behavior so that it can be used in a variety of contexts
without the developer having to know its inner workings (the developer only
need know its implementation). Servlet is a Java program that runs on
the server and is similar to CGI scripts in that it is given HTTP requests from
a web browser as inputs, and it outputs data to the browser as HTTP
responses. Servlets do not spawn new
processes with each request as CGI scripts do which makes them more efficient
for higher volume applications. Java Server Pages are an extension to
the servlet technology (they are actually compiled into servlets at run
time). Similar to Active Server Pages,
JSP have dynamic scripting capabilities that work in tandem with HTML code,
separating code from the static elements that form the presentation layer. The Java source code and its extensions
embedded within the HTML in a JSP enable the page to be more functional
performing such functions as dynamic database queries and interacting with
JavaBeans and servlets.
What Now?
Okay,
so maybe that wasn’t the easiest thing on the planet to read, but it will get
you started. Perhaps it will even get
you up and running with some trials and tribulations. My best recommendation, especially to anyone new to object
oriented programming (like myself) is to take a class. Believe me, there is nothing like 5 days of
Java training with people who read Java code in their spare time to get you
primed. If you don’t have the dough and
the company isn’t paying, though, I recommend finding a good book and a few
good web sites to work through tutorials to get you started. Try http://java.sun.com, http://www.wrox.com,
http://www.jguru.com
to start. There is definitely a
learning curve, but once you start learning the functionality and the powerful
potential of the language and platform, you will understand what all the fuss
is about (and be itching to get a chance to really delve into using it
hands-on).
I
am hoping to become immersed in working with this technology over the next few
months. As I learn from real world
experience guided by a Java guru I will share more tidbits with you.