Skip to content
← Back to Community
how to run java files.
Profile icon
strangeLanguage

Hello, I was wondering how I can run the main.java and any other .java file in replit. In python I am able to import the os and pass in the file on os.system() but I am unable to do it with Java and I noticed that new files are created that I have no idea what they are. I will be doing a java bootcamp course and I want to make sure I am able to run java code without problem.

Answered by theangryepicbanana [earned 5 cycles]
View Answer
Voters
Profile icon
annnnang
Profile icon
jsj0718
Profile icon
SpaceManx3
Profile icon
Allizon14
Profile icon
ayunas
Profile icon
rainamehra
Profile icon
AlexanderPayne1
Profile icon
strangeLanguage
Comments
hotnewtop
Profile icon
theangryepicbanana

Just click the Run button

Profile icon
strangeLanguage

the run button run the main.java but what about the other files? how do i run those? I have a HelloWorld.java file and I will be creating many others but I don't know how. @theangryepicbanana

Profile icon
HackermonDev

@strangeLanguage I don't know java, but I'm guessing there is a way to run other files from the main java file

Profile icon
strangeLanguage

well in python I can do: os.system('python3 file_to_run.py') and it will run and here with Java I can't even type in the interpreter. @PDanielY

Profile icon
HackermonDev
Profile icon
theangryepicbanana

@strangeLanguage Just make another repl? you can make more than one

Profile icon
strangeLanguage

yeah I can do that or decide not to learn Java which I am now considering after some research and how ridiculously hard it is to just print 'hello world'. @theangryepicbanana

Profile icon
theangryepicbanana

@strangeLanguage it's not exactly "hard", it just requires some setup. Once you learn why it works, you may like it a bit more. Also, many companies hire java devs, as it is the most widely used language next to C/C++ in application development

Profile icon
mwilki7

@strangeLanguage repl doesnt appear to be as lenient in terms of compiler options, you'd typically do javac yourprogram.java but repl streamlined it to always be javac main.java ...otherfiles.java so your main program always has to have a main.java iirc

Profile icon
ayunas

@theangryepicbanana I teach web development for a living, and I will vouch that it is HARD to print hello world in Java, unless you have fundamental understanding of how Object Oriented Programming works, which obviously will not be the case to the code newbie.

Profile icon
TimothyAlex

you can do that by,

first compiling your myfile.java (make sure your main class which contain void main and your myfile name is same, else wont work) by typing in your console:
javac myfile.java

then run your myfile.java:
java myfile

Profile icon
DoulatKhan

It's 2 step process in repl editor(Compile and Run)

Step 1: Click Run button (main.java runs repl also compile your other.java class and creates other.class)

Step 2: java other (in command prompt, this will run your other.java file).

Java is object oriented robust language and Platform-Independent. Java only has Android development. It needs some learning to enjoy this language and it has future.

Profile icon
AdamZitouni

i only know how to do it on windows: go to the command prompt, go to the directory of the file, type 'javac' and then the program. then, you will see another file. type in 'java' and then the new file's name. then you should see something in the command prompt (for example, 'Hello, world!') (this is if you want to run from the windows terminal, as a file)

Profile icon
Etperfere

I just started learning Java, I want to develop games with java. I was wondering the answer to the question above. https://basketballlegends.club/basket-random

Profile icon
YenPham10

Basket Random so loved by so many people https://basketrandom.com