To compile Java code, follow these steps:
-
Open your terminal or command prompt.
-
Navigate to the directory where your Java file is located. For example:
cd ~/project -
Use the
javaccommand followed by the name of your Java file to compile it. For example:javac YourFileName.javaThis will generate a class file with the same name as your Java file.
-
To run the compiled Java program, use the
javacommand followed by the name of the class (without the.classextension). For example:java YourFileName
Make sure to replace YourFileName with the actual name of your Java file.
