aspose file tools*
The moose likes Beginning Java and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method" Watch "main method" New topic
Author

main method

corey williams
Greenhorn

Joined: Jun 27, 2006
Posts: 26
how many methods can one project have
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
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

Joined: Jun 27, 2006
Posts: 26
a java application project
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
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

Joined: Jun 27, 2006
Posts: 26
i'm useing netbeans
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
corey williams
Greenhorn

Joined: Jun 27, 2006
Posts: 26
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

Joined: Jan 29, 2003
Posts: 8791
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?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
corey williams
Greenhorn

Joined: Jun 27, 2006
Posts: 26
thanks
 
wood burning stoves
 
subject: main method