Confused in Netbeans

I'm monkeying around a bit in Java. I downloaded both Eclipse and Netbeans to compare the two. I like the Netbeans interface more, but I don't understand what it's doing. From what I've seen on the web to write a simple Java console program you would type the name of the class followed by the familiar public static void main, and then after that you would start typing in your source code. So it might look like this:

publicclass AddTwoIntegers

{

publicstaticvoid main( )

{

int x = 4;

int y = 3;

int sum = x + y;

System.out.println("The sum of x + y is " + sum);

}

}

That's what I've seen anyway. But in Netbeans you got this "Main class" thing. If you let the program put it in, your program works okay. If you de-select that option, it does not work. It says "No Main class set." So then if you type it in manually, it still does not work. It still says "No Main class set." I don't get it. What is this extra class doing here? And I thought that every Java program had to have the first class the exact same name as the name of your program. So if the name of your program is Add Two Integers, then the name of the class in your program must be AddTwoIntegers. But Netbeans is doing this:

package addingnumbers;

publicclass Main{

publicstaticvoid main(String[] args){

int x = 5;

int y = 3;

int sum = x + y;

System.out.println("The sum of x + y is " + sum);

}

}

I don't understand that public class Main because this is the first I've seen of it. And Eclipse doesn't even have that in there, but Netbeans does.

[2492 byte] By [357maga] at [2007-11-27 9:43:34]
# 1
it works fine on my netbeans I always use netbeans..create a new project, uncheck create main class, then right click on the newly created project and create new class... works fine.
Yannixa at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 2
this confuses me as well, i believe the main class is the class with the main method in it. If you uncheck that when it asks if you want it as a main class, it wont add a main class.
pberardi1a at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 3

If I do that, then the new class opens up in a new window. Isn't the class supposed to be right above the public static void main( ) method? Least that's my understanding of it. If I right-click on the newly created project, and go into new Java class, yeah I can create a new class and call it whatever I want, but it doesn't put it in where the main method is.

357maga at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 4
When you check the Main class thingee...its creating a class called main and will provide you with the main method. If you uncheck it you have to type in the main method for yourself. Dont overcomplicate it..its easy to do.
pberardi1a at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 5

Well what I did was start a new project called Add Two Integers, and I left the create Main class box unchecked. Then I went into the File menu, and went into Java Main Class, went through that and I gave it the name I wanted, AddTwoIntegers. Then it seemed to work okay. But when I ran the program when I was ready, a dialog box came up saying something about choosing a Main class. And it listed Add Two Integers as a possible answer so I chose it and then I was done. But is this box going to come up every time?

357maga at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 6
no
pberardi1a at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 7
Then how do you prevent that dialog box from coming up every time you start a new project?
357maga at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...
# 8
When I run my program that dialog box comes up every time asking me to choose a main class. Is there a way to shut it off?
357maga at 2007-7-12 23:49:07 > top of Java-index,Java Essentials,New To Java...