File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to Remove Main() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to Remove Main()" Watch "How to Remove Main()" New topic
Author

How to Remove Main()

TR Shaw
Greenhorn

Joined: Dec 17, 2004
Posts: 1
I've written a simply stand alone program and now wish to remove the main main method. Is there a java expert in here that can show this using acutal code that compiles?

Details: I've written ReadFileIn that reads comma-delimited, ascii files. However, I now wish to remove the main method and use this program from another class called ReadFileInTestDrive. This is similar to what is done in the book :HeadFirst Java.

Kind Regards, TR.

Here's the standalone:

Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
I hope I understand your question correctly...

You should only have to delete the main function, and I don't see any reason why it should compile. Then in your other class - ReadFileInTestDrive - you'd need to import ReadFileIn, construct an instance of it and use that instance to call readit(some_str)

e.g:

ReadFileIn rfi = new ReadFileIn();
rfi.readit(string);

Hope that helps...
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

There's no real reason to remove the method -- it just sits there like any other method. You just need to make sure that whatever class you invoke from the command line (or however) has a main method -- there's nothing prohibiting other classes from also having a main method.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
How do you remove main()? With the Delete or Backspace key!

Okay, seriously, though. I'm not quite sure what you are asking. As Joel points out, you can have a main() method in every class in your program. There is nothing wrong with this. In fact, it is quite common in order to test individual classes. However, you still need at least one class with main() in order to run your application.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Remove Main()