• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Remove Main()

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Let nothing stop you! Not even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic