Return-Path: <env_38349913-1765623209@hermes.sun.com>
Received: from po10.mit.edu (po10.mit.edu [18.7.21.66])
	by po10.mit.edu (Cyrus v2.1.5) with LMTP; Tue, 22 Jul 2003 21:00:13 -0400
X-Sieve: CMU Sieve 2.2
Received: from fort-point-station.mit.edu by po10.mit.edu (8.12.4/4.7) id h6N10BNQ007124; Tue, 22 Jul 2003 21:00:11 -0400 (EDT)
Received: from hermes.sun.com (hermes.sun.com [64.124.140.169])
	by fort-point-station.mit.edu (8.12.4/8.9.2) with SMTP id h6N0xeZX002941
	for <alexp@mit.edu>; Tue, 22 Jul 2003 20:59:53 -0400 (EDT)
Date: 22 Jul 2003 16:01:35 -0800
From: "SDN - Core Java Technologies Tech Tips" <sunmail@hermes.sun.com>
To: alexp@mit.edu
Message-Id: <38349913-1765623209@hermes.sun.com>
Subject: Core Java Technologies Tech Tips, July 22, 2003 (Custom Taglets, Compiling Source)
Mime-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Mailer: SunMail 1.0
X-Spam-Score: 0.3
X-Spam-Flag: NO
X-Scanned-By: MIMEDefang 2.28 (www . roaringpenguin . com / mimedefang)

<!DOCtype HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Core Java Technologies Technical Tips</title>

<style type="text/css">

code {color: #333333; font-family: verdana, courier, monospace; font-size: 10pt}
pre {color: #333333; font-family: verdana, courier, monospace; font-size: 10pt}
body, div, span {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
td, th {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
tr {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
table {font-family: arial, helvetica, sans-serif; font-size: 10pt}
p {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
li {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
br {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
div {color: #666699; font-family: arial, helvetica, sans-serif; font-size: 10pt}
sup {font-family: arial, helvetica, sans-serif; font-size: 5pt}
h3 {color: #666699; font-family: arial, helvetica, sans-serif; font-size: 11pt}
h4, b {color: #666699; font-family: arial, helvetica, sans-serif; font-size: 10pt}
blockquote, input, select {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
ul, ol {color: #333333; font-family: arial, helvetica, sans-serif; font-size: 10pt}
a:link {font-size: 10pt; font-family: arial, helvetica, sans-serif; color:#666699 }
span.purple {font-weight: bold; color: #666699; font-family: arial, helvetica, sans-serif; font-size: 10pt}
span.small {font-size: 8pt; font-family: arial, helvetica, sans-serif; color:#333333 }
span.link {font-size: 8pt; font-family: arial, helvetica, sans-serif; color:#666699 }
</style>

</head>

<body bgcolor="#ffffff">
<a name="top"></a>
<table border="0" cellpadding="0" cellspacing="0" width="611">
<tr>
<td colspan="3" bgcolor="#cccccc" width="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" border="0" alt="."></td>
</tr>

<tr>
<td bgcolor="#cccccc" width="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" border="0" alt="."></td>

<td>
<table border="0" cellpadding="0" cellspacing="0" width="611">
<tr>
<td colspan="2"><a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285690"><img src="http://developer.java.sun.com/images/headers/core_ttips_hdr.jpg" width="611" height="160" alt="Core Java Technologies Technical Tips" border="0"></a></td>
</tr>

<tr>
<td colspan="2" bgcolor="#cccccc" width="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" border="0" alt="."></td>
</tr>

<!-- ================== -->
<!-- Start Main Content -->
<!-- ================== -->

<tr>
<td height="20">&nbsp;&nbsp;&nbsp;<a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285710" style="text-decoration:none;">View this issue as simple text</a></td>
<td align="right" height="20"><span class="purple">July 22, 2003</span>&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>

<tr><td colspan="2">

<table border="0" cellpadding="10" cellspacing="0" width="100%">
<tr>
<td>
     
<form method="get" action="http://search.java.sun.com/search/java/">   
<table border="0" cellpadding="3" cellspacing="0" width="100%">
<tr> 
<td align="left" valign="middle" width="20%"><h3>In this Issue</h3></td>
              
<td valign="middle" align="right" width="70%">
<font size="2">
<input type="text" size="15" maxlength="128" name="qt"></font></td>

<td valign="middle" width="55">
<input type="image" src="http://developer.java.sun.com/images/v4a_search.gif" alt="Search" value="search" border="0" width="55"></td>
</tr>
</table>
</form>

<p>
Welcome to the Core Java Technologies Tech Tips, July 22, 2003. Here you'll get tips on using core Java technologies and APIs, such as those in Java 2 Platform, Standard Edition (J2SE).
</p>

<p>
This issue covers:
</p>

<p>
<a href="#1"><img src="http://developer.java.sun.com/images/anchor.gif" border="0" alt="-">Generating Custom Taglets</a><br>    
<a href="#2"><img src="http://developer.java.sun.com/images/anchor.gif" border="0" alt="-">Compiling Source Directly From a Program</a>
</p>

<p>
These tips were developed using Java 2 SDK, Standard Edition, v 1.4. 
</p>

<p>
This issue of the Core Java Technologies Tech Tips is written by John Zukowski, president of <a href="http://www.jzventures.com">JZ Ventures, Inc.</a>
</p>

<p>
See the Subscribe/Unsubscribe note at the end of this newsletter to subscribe to Tech Tips that focus on technologies and products in other Java platforms.
</p>

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">

<!-- Grey Horizontal Line Begins Here -->

<tr>
<td bgcolor="#cccccc" height="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td>
</tr>
</table> 

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">

<!-- Grey Horizontal Line Begins Here -->

<tr>
<td bgcolor="#cccccc" height="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td>
</tr>
</table> 

<!-- Grey Horizontal Line ends Here -->

<a name="1"></a>

<h3>GENERATING CUSTOM TAGLETS</h3>

<p>
The <a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285632">May 20, 2003 issue</a> of Core Java Technologies Tech Tips described how to generate custom doclets for use with the <code>javadoc</code> tool. The tip below expands on the earlier tip -- it shows how to extend <code>javadoc</code> by creating custom taglets.
</p>

<p>
When you write <code>javadoc</code> comments for classes and methods, you can include special keywords preceded by an &quot;at&quot; sign (<code>@</code>). For instance, <code>@return</code> allows you to describe what a method is supposed to return. When the <code>javadoc</code> tool sees an <code>@</code> command, it adds the necessary text to the generated output. &quot;<code>@return</code>&quot; is an example of a <code>javadoc</code> tag, one of 17 predefined <code>javadoc</code> tags in J2SE 1.4. See the <code>javadoc</code> tags section of the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/javadoc.html"><code>javadoc</code> reference guide</a> for the complete list.
</p>

<p>
Although there are a set of predefined <code>javadoc</code> tags, they might not meet all your needs. Fortunately, you have the ability to define custom tags for use with the standard doclet. For example, if you want to keep a log of things to complete in the source code, you could create a custom tag named <code>@todo</code>. You could use the tag as a reminder of things you need to add to the code. When you run the <code>javadoc</code> tool, the <code>@todo</code> tag could generate highlighted text -- perhaps in a large font or with a special background color. Suppose too that you want to include a real working example in <code>javadoc</code> comments, but you don't want to actually code the example in the <code>javadoc</code> comments. In this case, you might create an <code>@example</code> tag that &quot;includes&quot; the working example class definition into the <code>javadoc</code> comments. You could then compare the source code to the working example to ensure that!
  the source &quot;looks right&quot;. Also, because the source file is separately compileable, you can ensure that it successfully compiles and runs.
</p>

<p>
Use the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/javadoc/taglet/com/sun/tools/doclets/Taglet.html"><code>Taglet</code> API</a> to create your own custom tag. You can find it in the <code>com.sun.tools.doclets</code> package. The <code>Taglet</code> interface consists of a series of methods that allow you to say here the tag is valid and how to generate a string representation for the tag contents. (There is also a method for getting a tag's name.) Here are the methods:
</p>

<pre>
   public boolean inField()
   public boolean inConstructor()
   public boolean inMethod()
   public boolean inOverview()
   public boolean inPackage()
   public boolean inType()
   public boolean isInlineTag()
   public java.lang.String getName()
   public java.lang.String toString(
                               com.sun.javadoc.Tag tag)
   public java.lang.String toString(
                            com.sun.javadoc.Tag[] tags)
</pre>

<p>
Implementations of the <code>Taglet</code> interface must also provide a registration method:
</p>

<pre>
   public static void register(Map tagletMap)
</pre>

<p>
The registration method adds an instance of the custom taglet to the map, with its name as the key.
</p>

<p>
Note that you can override taglets, for instance, you can replace a taglet provided by the system. You should delete any overridden taglet before you add one. To avoid a name conflict, you should name your taglets similar to your packages, using the reverse DNS ordering for your domain. This means naming a taglet <code>com.example.MyTaglet</code> if your domain is <code>example.com</code>.
</p>

<p>
Before looking at the interface, there is one other concept that needs to be explained: block vs. inline tags. You can think of a block tag as one that stands alone. It must appear at the beginning of a line (ignoring asterisks and white space), and goes on to either the next block tag or the end of the <code>javadoc</code> comment. By comparison, inline tags are specified within <code>{}</code> characters, and can exist within any <code>javadoc</code> comments (including, but not limited to, block tags). For example, the following inline <code>@link</code> tag generates a link to the <code>yourMethod</code> method in the <code>myMethod</code> description.
</p>

<pre>
   public class Example1 {
     /**
      * Your method is at {@link #yourMethod()}
      */
     public void myMethod() {
     }
     public void yourMethod() {
     }
   }
</pre>

<p>
Now let's examine the actual interface. All the <code>inXXX</code> methods in the interface allow you to control where the tag is valid. For example, if a tag is valid only in the constructor, then <code>inConstructor</code> returns true and all the other methods return false. The <code>toString</code> methods return the generated string. If multiple block tags for the same taglet are present, the array version of <code>toString</code> is used.
</p>

<p>
At this point you might wonder how to access the text after an<code>@taglet</code>. The answer is through the <code>text()</code> method of the <code>Tag</code> interface. See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/javadoc/doclet/com/sun/javadoc/Tag.html">description of the <code>Tag</code> interface</a> for information about <code>text()</code> and other <code>Tag</code> interface methods.
</p>

<p>
Let's demonstrate creating a taglet. The program that follows creates an <code>@javapedia</code> block tag. The tag allows someone to specify a keyword that automatically links into the <a href="http://wiki.java.net/bin/view/Javapedia">Javapedia</a>. For example, the &quot;<code>@javapedia Struts</code>&quot; tag is converted to the link http://wiki.java.net/bin/view/Javapedia/Struts/. If multiple <code>@javapedia</code> tags are present, each gets its own link. Note, there is no validation that a definition exists for the keyword in the Javapedia. This is left for the writer of the <code>javadoc</code> comment to verify before including the link in the <code>javadoc</code> comments.
</p>

<pre>
   import com.sun.tools.doclets.Taglet;
   import com.sun.javadoc.*;
   import java.util.Map;

   public class JavapediaTaglet implements Taglet {

     private static final String NAME = &quot;javapedia&quot;;
     private static final String HEADER = &quot;Javapedia:&quot;;
  
   public String getName() {
     return NAME;
   }

   public boolean inField() {
     return true;
   }

   public boolean inConstructor() {
     return true;
   }

   public boolean inMethod() {
     return true;
   }

   public boolean inOverview() {
     return true;
   }

   public boolean inPackage() {
     return true;
   }

   public boolean inType() {
     return true;
   }

   public boolean isInlineTag() {
     return false;
   }

   public static void register(Map tagletMap) {
    Taglet tag = new JavapediaTaglet();
      tagletMap.put(tag.getName(), tag);
   }

   public String toString(Tag tag) {
       return &quot;&lt;DT&gt;&lt;B&gt;&quot; + HEADER + &quot;&lt;/B&gt;&lt;DD&gt;&quot;
         + &quot;&lt;a href=\&quot;http://wiki.java.net/bin/view/Javapedia/&quot;
         + tag.text()
         + &quot;\&quot;&gt;&quot; 
         + tag.text()
         + &quot;&lt;/a&gt;&quot; 
         + &quot;&lt;/DD&gt;\n&quot;;
   }

   public String toString(Tag[] tags) {
     if (tags.length == 0) {
       return null;
     }
     String result = &quot;\n&lt;DT&gt;&lt;B&gt;&quot; + HEADER + &quot;&lt;/B&gt;&lt;DD&gt;&quot;;
     for (int i = 0; i &lt; tags.length; i++) {
       if (i &gt; 0) {
         result += &quot;&lt;/DD&gt;&lt;DD&gt;&quot;;
       }
       result += &quot;&lt;a href=\&quot;http://wiki.java.net/bin/view/Javapedia/&quot;
       + tags[i].text()
       + &quot;\&quot;&gt;&quot; 
       + tags[i].text()
       + &quot;&lt;/a&gt;&quot;;
     }
     return result + &quot;&lt;/DD&gt;\n&quot;;
   }
 }
</pre>

<p>
After you've written the <code>Taglet</code>, you need to compile it. Similar to the way you create a custom doclet, you need to use the <code>-classpath</code> option when you compile. That's because the <code>tools.jar</code> file where the <code>Taglet</code> interface and related classes are located is outside the default classpath. To compile the taglet, issue the following command (although shown on two lines, the command needs to go on one line).
</p>

<p>
In Windows:
</p>

<pre>
    javac -classpath 
        c:\j2se1.4.2\lib\tools.jar JavapediaTaglet.java
</pre>

<p>
In Unix:
</p>

<pre>
    javac -classpath 
        /homedir/jdk14/j2sdk1.4.2/lib/tools.jar JavapediaTaglet.java
</pre>

<p>
Replace <code>homedir</code> with your actual home directory.
</p>

<p>
Then, to use the taglet when running <code>javadoc</code>, you need to specify the <code>-taglet</code> option. Also, you might need to specify the <code>-tagletpath</code> option to tell <code>javadoc</code> where to find the taglet. You don't have to specify the <code>tools.jar</code> file in the classpath when you run the taglet.
</p>

<pre>
   javadoc -taglet JavapediaTaglet Example2.java
</pre>

<p>
Just be sure to include the <code>@javapedia</code> tag in your example source.Otherwise, the new taglet code won't don't anything. Here is the example source.
</p>

<pre>
   public class Example2 {
     /**
      * Your method is at {@link #yourMethod()}
      * @javapedia Struts
      * @javapedia MVC
      */
     public void myMethod() {
     }

     /**
      * @javapedia MVC
      */
     public void yourMethod() {
     }
   }
</pre>

<p>
After you've run <code>javadoc</code>, open the generated HTML file (you can start with index.html) to see the new taglet in action.
</p>

<p>
For more information about the <code>javadoc</code> tool and the API for taglets, see the resources listed on the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/javadoc/">Javadoc 1.4 Tool page</a>.
</p>

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<div align="right">
<a href="#top">back to top<img src="http://developer.java.sun.com/images/back_to_top.gif" border="0" alt="image"></a>
</div>
</td>
</tr>

<tr>
<td bgcolor="#ffffff" height="2"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td>
</tr>

<!-- Grey Horizontal Line Begins Here -->

<tr>
<td bgcolor="#cccccc" height="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td>
</tr>
</table> 

<!-- Grey Horizontal Line ends Here -->

<a name="2"></a>

<h3>COMPILING SOURCE DIRECTLY FROM A PROGRAM</h3>

<p>
Imagine being able to compile code directly from a Java application without the need to issue a <code>javac</code> command. This would allow you to do things like enter code into a <code>JTextArea</code> and have it compiled simply by pressing a button. In fact, you have this capability. By putting the <code>tools.jar</code> file in your classpath, you can compile directly from a Java application.
</p>

<p>
The command line-based <code>javac</code> compiler is simply a wrapper to the <code>com.sun.tools.javac.Main</code> class. Using the class's static <code>compile</code> method, you can pass (in a <code>String[]</code>) the name of one or more files to compile, and you don't need to use the command line for the compilation.
</p>

<p>
To demonstrate, this tip presents a program that displays a text field, a text area, and a button. You enter the name of a program (that is, the one you want to compile) in the text field, the program's source code in the text area, and then click the button. The source code is compiled and if the compile is successful, the program runs. Note however that the API demonstrated here is unsupported and dependent on an installation similar to the one shipped by Sun. Apple's, for example, is organized differently. With the 1.5 (Tiger) release of J2SE, the introduction of a portable API is planned.
</p>

<p>
Here is the demonstration program, <code>RunIt</code>:
</p>

<pre>
   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import java.io.*;
   import java.lang.reflect.*;

   public class RunIt extends JFrame {
     JPanel contentPane;
     JScrollPane jScrollPane1 = new JScrollPane();
     JTextArea source = new JTextArea();
     JPanel jPanel1 = new JPanel();
     JLabel classNameLabel = new JLabel(&quot;Class Name&quot;);
     GridLayout gridLayout1 = new GridLayout(2,1);
     JTextField className = new JTextField();
        JButton compile = new JButton(&quot;Go&quot;);
  Font boldFont = new java.awt.Font(&quot;SansSerif&quot;, 1, 11);

     public RunIt() {
       super(&quot;Editor&quot;);
       setDefaultCloseOperation(EXIT_ON_CLOSE);
       contentPane = (JPanel) this.getContentPane();
       this.setSize(400, 300);
       classNameLabel.setFont(boldFont);
       jPanel1.setLayout(gridLayout1);
       compile.setFont(boldFont);
       compile.setForeground(Color.black);
       compile.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           try {
             doCompile();
           } catch (Exception ex) {
             System.err.println(
                   &quot;Error during save/compile: &quot; + ex);
             ex.printStackTrace();
           }
         }
       });  
       contentPane.add(jScrollPane1, BorderLayout.CENTER);
       contentPane.add(jPanel1, BorderLayout.NORTH);
       jPanel1.add(classNameLabel);
       jPanel1.add(className);
       jScrollPane1.getViewport().add(source);
       contentPane.add(compile, BorderLayout.SOUTH);
     }
     public static void main(String[] args) {
       Frame frame = new RunIt();
       // Center screen
       Dimension screenSize =
         Toolkit.getDefaultToolkit().getScreenSize();
       Dimension frameSize = frame.getSize();
       if (frameSize.height &gt; screenSize.height) {
         frameSize.height = screenSize.height;
       }
       if (frameSize.width &gt; screenSize.width) {
         frameSize.width = screenSize.width;
       }
       frame.setLocation(
         (screenSize.width - frameSize.width) / 2,
         (screenSize.height - frameSize.height) / 2);
       frame.show();
     }
     private void doCompile() throws Exception {
       // write source to file
       String sourceFile = className.getText() + &quot;.java&quot;;
       FileWriter fw = new FileWriter(sourceFile);
       fw.write(source.getText());
       fw.close();
       // compile it
       int compileReturnCode =
         com.sun.tools.javac.Main.compile(
             new String[] {sourceFile});
       if (compileReturnCode == 0) {
         // run it
         
         Object objectParameters[] = {new String[]{}};
         Class classParameters[] = 
                     {objectParameters[0].getClass()};
         Class aClass = 
                   Class.forName(className.getText());
         Object instance = aClass.newInstance();
         Method theMethod = aClass.getDeclaredMethod(
                              &quot;main&quot;, classParameters);
         theMethod.invoke(instance, objectParameters);
       }
     }
   }
</pre>

<p>
Note that better exception handling could be done by the <code>doCompile</code> method. However, because this isn't an exercise in exception handling, exception handling improvements are left to the reader.
</p>

<p>
Most of the code in the <code>RunIt</code> program is in support of creating a graphical user interface. The part of the code that processes the entries into the GUI is the <code>doCompile</code> method. The method performs the following actions:
</p>

<ol>
<li>
Save the source to disk. The method saves the source in a file whose name is taken from the class name entered in the <code>JTextField</code> of the GUI. 

<pre>
    String sourceFile = className.getText() + &quot;.java&quot;;
    FileWriter fw = new FileWriter(sourceFile);
    fw.write(source.getText());
    fw.close();
</pre>
</li>

<li>
Compile the source. This is where the <code>com.sun.tools.javac.Main</code> is used. The method creates a <code>String[]</code> for the source files (only one is used in the demonstration), and compiles them using <code>Main</code>'s <code>compile</code> method. The method returns an error code of 0 if the compilation is successful, and non-zero if not.

<pre>
    int compileReturnCode =
      com.sun.tools.javac.Main.compile(
          new String[] {sourceFile});
</pre>
</li>

<li>
As with any class, running involves calling the class's <code>main</code> method. So, reflection is used to find the appropriate method and invoke it.

<pre>
    if (compileReturnCode == 0) {
      // run it
      Object objectParameters[] = {new String[]{}};
      Class classParameters[] = 
                       {objectParameters[0].getClass()};
      Class aClass = Class.forName(className.getText());
      Object instance = aClass.newInstance();
      Method theMethod = aClass.getDeclaredMethod(
                               &quot;main&quot;, classParameters);
      theMethod.invoke(instance, objectParameters);
    }
</pre>
</li>
</ol>

<p>
For more information on invoking methods with the Reflection API, see the Tech Tip &quot;<a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285645">Using Reflection to Test Methods and Classes</a>&quot;.
</p>

<p>
To compile the <code>RunIt</code> program, you need to add the <code>tools.jar file</code> to your classpath. This file contains the compiler classes. You can use the <code>-classpath</code> option when you compile. That's because the <code>tools.jar</code> file is outside the default classpath. To compile the program, issue the following command (although shown on two lines, the command needs to go on one line).
</p>

<p>
In Windows: 
</p>

<pre>
    javac -classpath 
        c:\j2se1.4.2\lib\tools.jar RunIt.java
</pre>

<p>
In Unix: 
</p>

<pre>
    javac -classpath 
        /homedir/jdk14/j2sdk1.4.2/lib/tools.jar RunIt.java
</pre>

<p>        
Replace <code>homedir</code> with your actual home directory.         
</p>

<p>
You also need to include the <code>tools.jar</code> file in your runtime classpath. That's because you want to use the compiler at runtime. To run the program, issue the following command (although the Unix command is shown on two lines, it needs to go on one line). 
</p>

<p>
In Windows: 
</p>

<pre>
    java -classpath c:\jdk1.4.2\lib\tools.jar;. RunIt
</pre>

<p>
In Unix: 
</p>

<pre>
   java -classpath 
      /homedir/jdk14/j2sdk1.4.1/lib/tools.jar:. RunIt
</pre>

<p>
Notice the &quot;.&quot; indicating the current directory in the classpath. New class files will be created by the compiler. The &quot;.&quot; makes these class files accessible.
</p>

<p>
Running the program displays the GUI. Then you can:
</p>

<ol>
<li>
Enter the name of the class, such as <code>Sample</code>, to be compiled in the <code>JTextField</code>.<br><br></li>

<li>
Enter the source code in the <code>JTextArea</code>. Here's the source code 
   for <code>Sample</code>:

<pre>
    public class Sample {
      public static void main(String args[]) {
        System.out.println(new java.util.Date());
      }
    }
</pre>
</li>

<li>
Click the Go button.
</li>
</ol>

<img src="http://developer.java.sun.com/developer/JDCTechTips/images/tt072203_Sample.gif" width="400" height="300" border="0" alt="Sample">

<p>
Output is sent to the console. For example, <code>Sample</code> should produce output that looks something like this:
</p>

<pre>
   Tue Jul 22 11:25:16 PDT 2003
</pre>

<p>
<code>RunIt</code> allows you to create any class. if the program you enter is Swing-based, you would see a new window appear.
</p>

<p>
See the <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/tools.html">Java 2 SDK Tools and Utilities documentation</a> for further information about Java 2 SDK tools and capabilities.
</p>

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">

<tr>
<td>
<div align="right">
<a href="#top">back to top<img src="http://developer.java.sun.com/images/back_to_top.gif" border="0" alt="image"></a>
</div>
</td></tr>

<tr><td bgcolor="#ffffff" height="2"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td></tr>

<!-- Grey Horizontal Line Begins Here -->

<tr>
<td bgcolor="#cccccc" height="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td>
</tr>
</table> 

<!-- Grey Horizontal Line ends Here -->

<form method="POST" action="http://developer.java.sun.com/servlet/jdc.survey.TabulationServlet">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td bgcolor="#ffffff" height="2"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td></tr>

<tr><td>
<h3>Reader Feedback</h3> 

<input type="hidden" name="survey_id" value="2600">
<input type="hidden" name="anonymous" value="True">
<input type="hidden" name="answer_count" value="3">
<input type="hidden" name="answer1" value="JulCore_tt072203">
<input name="answer2" type="radio" value="2">&nbsp; Very worth reading&nbsp; 
<input name="answer2" type="radio" value="1">&nbsp; Worth reading&nbsp; 
<input name="answer2" type="radio" value="0">&nbsp; Not worth reading&nbsp; 
 
<p>
If you have other comments or ideas for future technical tips, please type them  here: 
</p>
 
<p>
<textarea name="answer3" rows="6" cols="50"></textarea> 
</p>
 
<p>
<input type="Submit" value="Submit"> &nbsp; <input type="Reset"> 
</p>

<p> 
Have a question about Java programming? Use  
<a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285721">Java Online Support</a>. 
</p>

</td></tr></table>
</form> 

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<div align="right">
<a href="#top">back to top<img src="http://developer.java.sun.com/images/back_to_top.gif" border="0" alt="image"></a>
</div>
</td></tr>

<tr><td bgcolor="#ffffff" height="2"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td></tr>

<!-- Grey Horizontal Line Begins Here -->

<tr>
<td bgcolor="#cccccc" height="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" alt="." border="0"></td>
</tr>
</table> 

<!-- Grey Horizontal Line ends Here -->

<br>

<span class="small">IMPORTANT: Please read our Terms of Use, Privacy, and Licensing policies:<br>
<a href="http://www.sun.com/share/text/termsofuse.html"><span class="link">http://www.sun.com/share/text/termsofuse.html</span></a><br>
<a href="http://www.sun.com/privacy/"><span class="link">http://www.sun.com/privacy/</span></a><br> 
<a href="http://developer.java.sun.com/berkeley_license.html"><span class="link">http://developer.java.sun.com/berkeley_license.html</span></a>
</span><br><br>


<span class="small">
Comments? Send your feedback on the Core Java Technologies Tech Tips to: <a href="http://developers.sun.com/contact/feedback.jsp?category=sdn"><span class="link">http://developers.sun.com/contact/feedback.jsp?category=sdn</span></a>
</span><br><br>

<span class="small">
Subscribe to other Java developer Tech Tips:
</span><br><br>

<span class="small">
- Enterprise Java Technologies Tech Tips. Get tips on using enterprise Java technologies and APIs, such as those in the Java 2 Platform, Enterprise Edition (J2EE).<br>
- Wireless Developer Tech Tips. Get tips on using wireless Java technologies and APIs, such as those in the Java 2 Platform, Micro Edition (J2ME).<br><br>
</span>
   
<span class="small">
To subscribe to these and other JDC publications:<br>
- Go to the JDC Newsletters and Publications page, choose the newsletters you want to <a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285662"><span class="link">subscribe</span></a> to and click &quot;Update&quot;.<br>
  - To unsubscribe, go to the <a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285662"><span class="link">subscriptions page</span></a>, uncheck the appropriate checkbox, and click &quot;Update&quot;.
</span><br><br>

<span class="small">ARCHIVES: You'll find the Core Java Technologies Tech Tips archives at:<br>
<a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285734"><span class="link">http://java.sun.com/jdc/TechTips/index.html</span></a>
</span><br><br>

<span class="small">Copyright 2003 <a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285752"><span class="link">Sun Microsystems, Inc.</span></a> All rights reserved.
<br>4150 Network Circle, Santa Clara, CA 95054 USA.
</span><br><br>

<span class="small">This document is protected by copyright. For more information, see:
<br><a href="http://java.sun.com/jdc/copyright.html"><span class="link">http://java.sun.com/jdc/copyright.html</span></a>
</span><br><br>

<span class="small">Java, J2SE, J2EE, J2ME, and all Java-based marks are trademarks or registered trademarks (<a href="http://www.sun.com/suntrademarks/"><span class="link">http://www.sun.com/suntrademarks/</span></a>) of Sun Microsystems, Inc. in the United States and other countries.</span>
<br><br>

<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->

<center>
<a href="http://bulkmail2.sun.com/CTServlet?id=38349913-1765623209:1058914285752"><img src="http://developer.java.sun.com/images/lgsun.gif" border="0" alt="Sun Microsystems, Inc."></a>
</center>

</td>
</tr>
</table>

</td></tr>
</table>
</td>

<td bgcolor="#cccccc" width="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" border="0" alt="."></td>
</tr>
<tr>
<td colspan="3" bgcolor="#cccccc" width="1"><img src="http://developer.java.sun.com/images/pixel.gif" width="1" height="1" border="0" alt="."></td>
</tr>
</table>

<br><br><table bgcolor = "#efefef"><tr><td><a href="http://subscriptions.sun.com/unsubscribe?38349913-1765623209">Please unsubscribe me from this newsletter.</a></td></tr></table><br><br><img src="http://bulkmail2.sun.com/OTServlet?id=38349913-1765623209" width=1 height=1></body>
</html>


