#How to run Java code on terminal

1 messages Ā· Page 1 of 1 (latest)

wheat elbow
#

Can someone explain me why I can not run my Java code on my terminal but I can still run it by vscode ;-;

fleet ginkgoBOT
#

<@&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>.

#
TJ-Bot
Can someone explain me why I can not run my Java code on my terminal but I can still run it by vscode ;-;

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:

  1. Open your terminal and navigate to the directory where your Java file is located.
  2. Compile your Java file by running javac YourFileName.java.
  3. If there are no compilation errors, a new file with a .class extension will be generated.
  4. 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.

wheat elbow
fleet ginkgoBOT
#

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 šŸŽ‰

Eclipse Adoptium provides prebuilt OpenJDK binaries ...

wheat elbow
#

I can not use java and javac

woven cave
#

You likely haven't configured some environment variables, so just follow the above steps.

wheat elbow
#

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

woven cave
#

Some tools contain embedded tools such as maven, gradle, jdk, etc..

wheat elbow
#

Wow, thank you for helping me

fleet valley
#

maybe they are installed when you install extensions in vscode

woven cave
wheat elbow
#

Oke :>