Javadoc

S

SpeedRunner

Guest
Hey, I managed to finish this assignment and have it working properly 3 days before it's due. :)

It's the same one as this thread: http://hardforum.com/showthread.php?t=1016938

My question though, is how do I generate an HTML document for the javadoc? I know I have to work some kind of magic in command prompt but I haven't been able to get it to work. Also if you want to take a look at my program and critique it, thats fine.

Code:
/**
   This simply provides a driver to exercise the exciting
   Student class.

   @see Student
   @author Marshall Harris
   @version StuList
   @since ver 1.0
 */
public class StuList
{
   /**
      Should not instantiate!
    */
   private StuList(){};

   public static void main(String[] args)
   {
      Student[] stus = new Student[4];
      stus[0] = new Student(123,"Fred",3.4);
      stus[1] = new Student(234,"Suzy");
      stus[2] = new Student(345,4.0);
      stus[3] = new Student(456);

      stus[1].setGPA(3.9);
      stus[3].setName("Betty");

      for(int i=0; i<stus.length; i++)
      {
         System.out.println(stus[i]);
         System.out.println(stus[i].getName() + " has number " + stus[i].getNumber() + "\n");
      }
   }
}
/**
The Student class encapsulates a student's name, student number, and gpa.
The student number cannot be changed once the Student object is constructed,
but the other members can be reset by means of "set" methods.
*/
class Student
{
	/**
	*Creates variables
	*/
	private int number;
	private String name;
	private double GPA;

	/**
	Constructs a new Student, given a name, Student number, and gpa.
	*/
	public Student(int n, String m, double g)
	{
		number = n;
		name = m;
		GPA = g;
	}
	/**
	 Constructs a new Student, given Student number and gpa, with the Student's
	 name defaulting to something of the form "Student 123" by means of a "this" call.
	*/
	public Student(int number, double GPA)
	{
		this(number, "Student " + number, GPA);
	}

	/**
	Constructs a new Student, given just a Student number,
	with other values defaulting through a set of chained "this" calls.
	*/
	public Student(int number)
	{
		this(number, "Betty", 0.0);
	}
	/**
	Constructs a new Student, given a name and student number,
	with gpa defaulting to 0.0 by means of a "this" call.
	*/
	public Student(int number, String name)
	{
		this(number, name, 0.0);
	}
	/**
	Changes the Student's gpa.
	*/
	public double setGPA(double g)
	{
		GPA = g;
		return GPA;
	}
	/**
	Changes the Student's name.
	*/
	public String setName(String n)
	{
		name = n;
		return name;
	}
	/**
	Retrieves the Student's name.
	*/
	public String getName()
	{
		return name;
	}
	/**
	Retrieves the Student's number.
	*/
	public int getNumber()
	{
		return number;
	}
	/**
	Retrieves a String represetnation of all the Student's data fields separated by commas.
	*/
	public String toString()
	{
		return (name + ", " + number + ", " + GPA);
	}

}
 
ok, I downloaded the Ant, but I have no idea what it does. I also still have no idea how to use it make an html file out of my program.
 
Ant is a build tool. Odds are your code was simple enough to just to a javac to make the class file. As projects get larger, you often need to compile a bunch of stuff, stuff together war, jar, or ear files, and generate javadocs. Ant provides a 'standard' way to do that, rather than everyone hacking out their own build scripts.
 
first off the proper way to comment for java doc it as follows
/**
* content
* here
*/

on command line type javadoc -d <directory> <filename>

when in doubt: man javadoc
 
GAMMA_BLADE said:
first off the proper way to comment for java doc it as follows
/**
* content
* here
*/

on command line type javadoc -d <directory> <filename>

when in doubt: man javadoc

It says "javadoc is not recognized as an internal or external command, operable program or batch file"

So I take it I'm missing something?
 
Javadoc is not in your path, add the path to the Java bin directory to your Windows path.
 
BillLeeLee said:
Javadoc is not in your path, add the path to the Java bin directory to your Windows path.

ok, how do I do that?

the path to my java bin directory:
C:\Program Files\Java\jdk1.5.0_06\bin

also, this is the file i'm trying to make into an html:
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList.java

Sorry I'm a noob with command prompt, haven't had to use it in years.
 
One way to add a directory to your path:

1.) Right Click My Computer -> Properties
2.) Go to Advanced tab and click "Environmental Variables"
3.) Under the 'PATH' part of this new window, add the path.

So it'll look like this:

Code:
blah blah blah;C:\Program Files\Java\jdk1.5.0_06\bin

Just take care so as to not modify the rest of the path, you just want to append your stuff onto it.

Hope that helps.
 
ok, I think that helped because now when I type javadoc alot of text comes up on the command prompt.

But when I type javadoc -d MyDocuments\JAVA\StuList, it still doesn't generate the HTML file, i gives a whole bunch of text but doesnt do anything.
 
you should be in the directory of the file you are running javadoc on and the -d <directory> command specifies the output of javadoc. sorry i should have been more clear. go into the directory you spec'ed and see if there are a bunch of html files, then open index.html. it also looks like you forgot to put the file you are running javadoc on at the end of that command. refer to my previous post for syntax.
 
Alright, I understand what your trying to tell me but I really don't think I'm typing it right. Here's what I type into the cmd prompt.

javadoc -d C:\Documents and Settings\Marshall\My Documents\JAVA\StuList.java

and press enter.
 
yeah thats wrong the syntax goes javadoc -d <directory where you want the javadoc files to go to> <file you are running javadoc on>
you should be in the folder where the .java file is.
so i think yours should be
javadoc -d doc StuList.java
that says do javadoc on StuList.java and put the files in the doc folder in this folder. that make sense?
 
Ok but how do I get to my directory?

It's C:\Documents and Settings\Marshall\ at default

my directory is:
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList.java
 
SpeedRunner said:
Ok but how do I get to my directory?

It's C:\Documents and Settings\Marshall\ at default

my directory is:
C:\Documents and Settings\Marshall\My Documents\JAVA\StuList.java

If your command prompt starts at the "C:\Documents and Settings\Marshall" directory, just use the cd command.

Code:
cd "My Documents\JAVA"
 
Back
Top