★ wanayoo — archive 1999 http://java.sun.com/developer/onlineTraining/new2java/programming/learn/Nouvelle recherche | Portail wanayoo
Skip Masthead Links developers.sun.com   » search tips  |  Search:     
The Source for Java Developers
Sun Microsystems
 
 
Article
Setting Up and Getting Started in Java Programming
 

New to Java Programming Center Programming Center




Java Platform Overview | Getting Started | Step-by-Step Programming
Learning Paths | References & Resources | Courses & Certification Newsletters

To write a Java program, you need to download the development kit for J2SE for Windows, Linux, Solaris, or Mac users.

Development kits are also available in other languages.

Next set up the software, and then configure your system.

Next you need to learn how to invoke the compiler and interpreter.

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, be sure to cd into the directory where you saved your .java file.

Application

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

  javac ExampleProgram.java
  java ExampleProgram

Applet

Compile the SimpleApplet.java applet with the javac command.

  javac SimpleApplet.java

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:

<HTML>
<BODY>
<APPLET CODE=SimpleApplet.class WIDTH=200 HEIGHT=100>
</APPLET>
</BODY>
</HTML>

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

Servlet

To compile the ExampServlet.java servlet you will also need to install the JavaServer Web Development Kit and add it to your class path as you did for the J2SE. Then compile with the javac command.

  javac ExampServlet.java

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.

Subscribe to the New to Java Programming Center Supplement to learn the basics of the Java programming language and keep up-to-date on additions to the JDC's New-to-Java Programming Center.