No results found

Your search did not match any results.

We suggest you try the following to help find what you’re looking for:

  • Check the spelling of your keyword search.
  • Use synonyms for the keyword you typed, for example, try “application” instead of “software.”
  • Try one of the popular searches shown below.
  • Start a new search.
Trending Questions

Set up Java

To set up the Java platform on your computer, you need to download the developer kit, then set up whatever development environment you plan on using. You can also do this in one step by downloading the JDK that comes bundled with the NetBeans IDE.

Step 1: Download the JDK

Once you've installed the JDK download on your computer, set up should be complete. You may, however, want to set the classpath as an environment variable. See the installation notes for directions on how to do that for your operating system.

If you want to develop web applications, you need to use either the NetBeans IDE , Sun Java Studio Creator IDE, or Sun Java Studio Enterprise in addition to the JDK, as these environments provide a web server that's necessary for creating and testing servlets, JavaServer Pages, and database connections.

See Getting Started with an Integrated Development Environment (IDE) if you're unsure which IDE would best suit your development needs.

Step 2: Set Up a Development Environment

If you downloaded the JDK with the NetBeans IDE, start NetBeans, and begin programming.

You can also program using a simple text editor, and compile and run from the command line. Many text editors now come with the ability to run and compile Java files, but you may need to tell the program where javac.exe and java.exe reside on your computer. Use the Windows Find command, if you are unsure where these files were installed. Once, your IDE or text editor is set up, you can begin programming.

Next, copy and paste the following programs, and invoke the compiler and interpreter either at the command line or within the IDE you're using.

The following three examples use the javac and java commands and illustrate how to compile and run an application, applet, and servlet.

When compiling and running from the command line, be sure to cd into the directory where you saved your .java file.


Compile the application with the javac command and run it with the java command.

//A Very Simple Example
class ExampleProgram {

   public static void main(String[] args){

        System.out.println("I'm a Simple Program");

Compile and then run with the following commands:


java ExampleProgram


Copy the applet code, and compile with the javac command:

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;

public class SimpleApplet extends Applet{

  String text = "I'm a simple applet";

  public void init() {
        text = "I'm a simple applet";

  public void start() {

  public void stop() {

  public void destroy() {
        System.out.println("preparing to unload...");

   public void paint(Graphics g){
        g.drawRect(0, 0,
                   getSize().width -1,
                   getSize().height -1);
        g.drawString(text, 15, 25);



You can run the applet in appletviewer (a Java platform tool for running applets independently of the browser) or in the browser. Either way you need an HTML file for the applet.

Here is the HTML file:



To run the applet in the browser, you load the HTML file. To run the applet in appletviewer with an HTML file named simple.html, type this in an MS-DOS window on Windows, or in a terminal window on Solaris:

appletviewer simple.html


As mentioned above, to compile and run a servlet, you need to use either NetBeans or Sun Java Studio Creator. Then compile with the javac command.

  import javax.servlet.*;
  import javax.servlet.http.*;

  public class ExampServlet extends HttpServlet {

      public void doPost(HttpServletRequest request,
                        HttpServletResponse response)
                        throws ServletException, IOException
        PrintWriter out = response.getWriter();
          out.println("<title>Example</title>" +
                       "<body bgcolor=FFFFFF>");

          out.println("<h2>Button Clicked</h2>");

          String DATA = request.getParameter("DATA");

          if(DATA != null){
          } else {
                  out.println("No text entered.");

          out.println("<P>Return to <A HREF=../simpleHTML.html>Form</A>");

To compile:


Servlets can be called directly by typing their uniform resource locator (URL) into a browser's location window after you've started the server.

Servlets can also be invoked from an HTML form by specifying their URL in the definition for a Submit button, for example.

Servlets can be called by any program that can open an hypertext transfer protocol (HTTP) request.