wood burning stoves 2.0*
The moose likes JSP and the fly likes How to compile .java for Java-Server-Pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to compile .java for Java-Server-Pages" Watch "How to compile .java for Java-Server-Pages" New topic
Author

How to compile .java for Java-Server-Pages

Akash Badal
Greenhorn

Joined: Feb 07, 2006
Posts: 1
Hello All,

Compile of Java-code (.java) needs "public static void main(String[] args)". In Java Server Pages how do you compile helper .java codes without "public static void main(String[] args)"? I tried to compile .java from the command line but I get error saying "Java uses unchecked or unsafe opertaion. Note: Recompile with Xlint: unchecked for details".
The code looks as follows:
///////////////////////////////////////
import java.util.Iterator;
import java.util.Vector;

public class FaqCategories {
private Vector categories = new Vector();

public FaqCategories() {
categories.add("Dates and Times");
categories.add("Strings and StringBuffers");
categories.add("Threading");
}

public Iterator getAllCategories() {
return categories.iterator();
}
}
/////////////////////////////////////////
Any ideas? Thanks.

Akash-Badal

[ February 07, 2006: Message edited by: Akash Badal ]

[ February 07, 2006: Message edited by: Akash Badal ]
[ February 08, 2006: Message edited by: Akash Badal ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61457
    
  67

You compile them like any other Java class. Since the classes are not intended to be executed from the command line, there's no need for a main method.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Akash

Compile of Java-code (.java) needs "public static void main(String[] args)".

This is required for executing the program using java not for compiling.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Java uses unchecked or unsafe opertaion


This error message is coming because you are compiling with Java1.5, and you are using a Vector, without specifying the types which the Vector accepts. ie using Generics: http://java.sun.com/developer/technicalArticles/J2SE/generics/

The error has nothing to do with the absence of a main method.
Your code will run correctly. Ignore the warning if you so wish.
 
jQuery in Action, 2nd edition
 
subject: How to compile .java for Java-Server-Pages