| What's New? | Search | Site Map | FAQ | Contact |
Studio II.5 Introduction to JavaAuthored by Dr. Lester Yee In order to begin development with Java, one needs to download and configure an appropriate version of a Java Development Kit (JDK) and install it on your system. The following document details the steps necessary to install Suns J2SE JDK v1.3.0 and its corresponding documentation. Instructions for the Sun Java Servlet Development Kit (JSDK) version 2.1 is also presented for web-based applications development. There are numerous Integrated Development Environments (IDEs) (commercial and otherwise) for Java development available to facilitate code writing. However, a simple text editor (TextPad v4.4.1 www.textpad.com) with Java support will be the recommended IDE for this introduction to Java. TextPads simplicity, low learning curve, and small memory footprint makes it an ideal choice to get started in Java programming. Installing the Sun's J2SE v1.3.0 JDKDownload the Sun J2SE v1.3.0 JDK and its documentation from the following site and install both of them. http://www.javasoft.com/j2se/1.3/ The files to download are: 2sdk-1_3_0-win.exe (Install on C: drive) j2sdk-1_3_0-doc.zip (Unzip to C:\)
Figure 1. Options to check for installing the JDK Important Note: Modify your autoexec.batfile to include the following environment variable settings: set PATH=%PATH%;c:\jdk1.3\bin (where %PATH% is your original path) set CLASSPATH=.;c:\jdk1.3\lib\tools.jar;c:\jsdk2.1\servlet.jar Installing the Sun's JSDK v2.1Download the Sun JSDK v2.1 from the following URL: http://www.javasoft.com/products/servlet/archive.html The file to download are: jsdk2_1-win.zip (Install on C: drive) Important Note: Modify your autoexec.batfile to include the following environment variable settings: set CLASSPATH=.;c:\jdk1.3\lib\tools.jar;c:\jsdk2.1\servlet.jar Installing TextPad v4.4.1Download a simple yet powerful text editor that has support for Java. Note that this is a shareware/trial edition. http://www.textpad.com/ The file to download are: txpeng441.exe When installing choose all default options.
Figure 2. TextPad install page Installation Note:Reboot your PC for all the configuration settings to apply to your PC. Writing your First Java ProgramOpen up your TextPad editor and type the following piece of code into your edit window and save the file as Cool.java. (Note: Make sure that you save the file with the file-type as .java) public class Cool {
public static void main(String[] args) {
System.out.println("Java is Cool!");
}
}
Writing your First Java ServletOpen up your TextPad editor and type the following piece of code into your edit window and save the file as HelloServlet.javain the following folder C:\jsdk2.1\webpages\Web-inf\servlets import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String name = req.getParameter("name");
res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
out.println("<b>");
if (name == null) {
name = "Bill";
}
if (name.equals("John")) { // put your name here
out.println("<font color=\"red\">" + "Hello " + name + "</font>");
} else {
out.println("Hello " + name);
}
out.println("</b>");
}
}
Compile it within TextPad. Running your First Java ServletRun (double-click) on the following batch file: C:\jsdk2.1\startserver.bat Start Internet Explorer or Netscape and issue the following URL: http://localhost:8080/servlet/HelloServlet View the source generated from the above request. Issue the following URL request: http://localhost:8080/servlet/HelloServlet?name=John View the source generated from the above request. |
viu.eng.rpi.edu
is hosted by Professor Cheng Hsu. Copyright © 1997-2013. MetaWorld, Nothing on this site may be commercially used without written consent. |