Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rename my main class in the NetBeans IDE?

Tags:

java

netbeans

I am using NetBeans IDE and have created a new project. The new project includes a Main.java.

Is it necessary to have it named Main.java, or can I rename the Main.java into another name? If so, how can I do this? When I try to right-click Main.java, there is no rename option. I thought it was possible.

like image 800
O_O Avatar asked Dec 30 '25 11:12

O_O


2 Answers

There should be a menu item called

Refactor --> Rename

Link from NetBeans Wiki

Your name can be anything, as long as you have a

public static void main(String[] args) 

in it (This is only if you want this class to be the entry point when you run your application).

like image 176
Kal Avatar answered Jan 02 '26 03:01

Kal


You can call the file <whatever you like>.java, but the name of the class in that file must match the new name you give to the file.

So if you rename the file to MyCoolClass.java, you also have to change the class from public class Main to public class MyCoolClass.

like image 24
dlev Avatar answered Jan 02 '26 02:01

dlev