• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
corey williams
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how many methods can one project have
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too vague.
It really depends on the project.
Some projects won't have any main method at all (applets, servlets, common library, etc.).
Please be more specific.
 
corey williams
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a java application project
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to decipher your "java application" answer.
I've seen it on Eclipse.
Are you using Eclipse? Or any other IDE like NetBeans, IDEA, JBuilder, else?
What your java application will do?
If it's a program that will execute stand alone then you need only one starting point so only one main method.
 
corey williams
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm useing netbeans
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey --

Can you write a whole paragraph describing exactly what you're asking? Methods don't belong to projects; they belong to classes. A class can have any number of methods, but only one "main". A project is just an arbitrary collection of classes, and so it can have any number of "main" methods.
 
corey williams
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm sorry i didn't mean methods, i meant main class, how mian classes can you have in a project
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before the days of unit testing tools like JUnit, lots of people wrote a main() in classes to run a few tests or examples. So they might have many, many classes with main methods. There is probably usually just one or very few that are really meant to start up the whole application.

It can get more complex as you reuse components and customize applications. I took a program that already had a main() and wrote another class to set up the environment and configure some things before calling the original main. So now it has two that do slightly different things.

Is that answering the right question?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by corey williams:
i'm sorry i didn't mean methods, i meant main class, how mian classes can you have in a project

As many as you like... If you start a Java program, you have to specify the class that contains the main method to the JVM. You can put any number of classes that contain a main method in your project. When you run the program, you'll just have to specify which one you want to use.
 
corey williams
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic