How to Compile a Java Program in Command Prompt in a Terminal: In this JAVA tutorial, we are going to see how to write a simple JAVA program, and compile and run the JAVA program in a command prompt.
public class SeleniumJavaProgram { public static void main(String[] args) { System.out.println("This Is My First Program"); } }
if we run this program, then the output should come as: This is my first program in the JAVA selenium series
How to Run the JAVA program in the Command prompt
- Before writing the program, there is some prerequisite there, like installing Java in your system and setting JAVA_Home Variable on your system.
- You Can copy and paste in an editor like Notepad or TextEdit, or you can write in any IDE like Eclipse, NetBeans, or IntelliJ IDEA like editors which are available online for free download.
- After writing the program, save that program as “SeleniumJavaProgram.Java”.
- The next step after saving the program is to compile the program. for compile, you can open the command prompt and terminal in case if you are using the Mac operating system.
- For compile the program you can type the below command and hit enter
javac SeleniumJavaProgram.Java
Open Command Prompt in Folder
Note: After hit enter if you are getting any error like this “Javac’ is not recognized as an internal or external command, operable program or batch file” that means the path is not set in your system, from here you can learn how to set Java path in windows?
Check Also: Core Java Tutorial
- Once you set the path after that if you compile the java program then you are not getting any error and after a successful compilation, the java file is converted into a .class file which is byte code.
- Now we can run the java program in command prompt. to run the program type the below command and hit enter.
Java SeleniumJavaProgram
How to Compile a java program in Command Prompt:
Please write comments if you find anything incorrect, or you want to share more information about this topic discussed above then you can use our contact us page.
Leave a Reply