Using Netbeans 7 on Windows XP, I did it as follows:
Create a new Java project:
File -> New Project.
Java -> Java Application.
I named the project HelloWorld. Netbeans autogenerated a 'HelloWorld' main class.
In this class, I added the code as you had it here. It looks like this now:
package helloworld;
class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
It ran just fine.
Some thoughts on what might be going on:
- missing 'package' declaration
- something else (I don't know, it's hard to tell without being able to look in your project
)
Good luck!