Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
4

Changing the main class name in Java -- is it possible?

LisaKossiver
LisaKossiver

In Java there is no way to change the class name or the java file away from Main, and give it a meaningful name?

2 years ago

Voters

Comments

TopNew
2
DynamicSquid
DynamicSquid

In the console, type rm Main.java, then hit the "new file" button, and rename the file whatever you like. Then create a new file called .replit, and type this:

run="javac filename.java; java filename"

I don't do java, so that may be wrong

2 years ago
3
PattanAhmed
PattanAhmed

@LisaKossiver
Hi,
By reading all of these websites, I came to the conclusion that You cannot rename the main file in any of Programming Language.
The sources that I referred were:-
Click here
Click here
Click here

But

You can create a new file and rename it with your choice...
Unfortunately, you cannot rename the original (main.java) to somewhat other.

If

you wanted to run your second file, then write this code into your main file:-

otherfile.main(args);

If

You wanted to rename your file on Desktop then, You can download it as a zip and extract it, and then you can rename it.

That's probably unrelated here :D

Hope this helps

Please mark my answer if this helps

2 years ago
6
Coder100
Coder100

You can delete the main file and then create a new java file using shell commands: (hit ctrl+shift+s)

rm main.java

but then you will also have to configure the run button: (create a .replit file)

run="sh main.sh"
# main.sh javac NewClass.java # whatever that file is java NewClass
2 years ago
1
BANDBeefy
BANDBeefy

@Coder100
But what if it is in a package?

10 months ago
1
Coder100
Coder100

@BANDBeefy
a package is something you use not run lol?

10 months ago
1
BANDBeefy
BANDBeefy

@Coder100
I mean what if the class is in a package

10 months ago
Load more