Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Remove Main()

 
TR Shaw
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic