This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Move implemenation out of main(String[ ] args)

 
Aretha Clark
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im looking for some guidance as to how i would go about moving implemenation out of main(String[ ] args). I have tried to do this a few times and all i seem to do is mess up my code.

 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Aretha Clark:
I have tried to do this a few times and all i seem to do is mess up my code.


Could you be more specific? How is it messing up your code? Are you getting compile time errors? Runtime errors/exceptions? Is it just not doing what you want it to do?

If you can post the code for what you have tried, and what errors you are getting, it'd be a little easier to assist you.
 
Norm Radder
Rancher
Posts: 1220
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you move all your code out of main() to a Constructor for the class and insert a call to that constructor in main()?
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally you want to create a constructor for Dvdinventory and a function, something like process().

In your main, do something like
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic