#How to run Java code on terminal
1 messages Ā· Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question š¤. Maybe it helps! In any case, a human is on the way š. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
To run Java code on the terminal, you need to compile the code first using the javac command. After compiling, you can run the compiled Java class file using the java command.
Here's a step-by-step guide:
- Open your terminal and navigate to the directory where your Java file is located.
- Compile your Java file by running
javac YourFileName.java. - If there are no compilation errors, a new file with a
.classextension will be generated. - Run the compiled Java file using
java YourFileName.
If you are able to run your Java code in vscode but not in the terminal, it could be due to different configurations or environments. Make sure that you have set up your system's PATH variable to include the location of your Java installation. Additionally, check if there are any compilation errors or if you are using any external libraries that need to be included in the classpath.
If you continue to experience issues running your Java code on the terminal, consider seeking help from online forums or communities like this one for further assistance and troubleshooting tips.
Download latest Java from https://adoptium.net/, run the installer.
Open a CMD and type java -version and javac -version, if both show your new Java version, you have successfully installed Java! š
https://i.ibb.co/X8Kms8q/CurMujt.png
In order to prevent issues with old installations you may want to remove them. Type where java and where javac. They should only show the new and no old entries:
https://i.ibb.co/fkKHv0b/x5k1GxG.png
If that is not the case, you may want to clean up. Therefore, type "environment variable" into the Windows search and follow the dialog. You will see two entries for a variable called Path, one for your user and one for the system. This variable tells Windows where to look for commands, like java and javac.
https://i.ibb.co/BwvMpM6/3bN9QE2.png
Edit both. Make sure that they only list the entry to your new Java installation and remove all the old entries you have seen with the where command before:
https://i.ibb.co/9GTnHsm/JAYog1U.png
Confirm and close all dialogs. Restart your CMD window and try where java and where javac again. It should only list the new installation now and nothing else.
Congratulation, your Java is now finally ready, happy coding š
I can not use java and javac
You likely haven't configured some environment variables, so just follow the above steps.
Oh, thanks
Wow, I can run my code now
But I dont know why I use run java code in vscode, it still runs
It should be both run or both can not run
Some tools contain embedded tools such as maven, gradle, jdk, etc..
Wow, thank you for helping me
maybe they are installed when you install extensions in vscode
You're welcome. You can close a topic by using /help-thread close.
Oke :>