Steps to create, compile and execute a simple Java program after the Java installation, which can be done immediately after the path variable is updated with Java bin location to make sure Java is accessible across any location on the system.
Check out the article on our website for more details.
Website:
Article:
======================
As soon as we install Java on our machine and set up the required environment variables, we have to make sure if Java is accessible from anywhere on our machine. In order to ensure that, we have to create, compile and execute a simple Java program without an IDE.
In this video, let's take a look at how we can compile and execute a simple Java program using a command prompt.
Before we proceed, we have to make sure we have Java installed on our machine and the environment Path variable is set up as needed.
NOTE: We have separate videos on why to set up and how to set up the Path environment variable, which can be referred to for more details.
1. Verify the installed Java version
Open the command prompt and verify if we have Java installed using the command prompt.
Command to verify installed Java version
- java -version
Command to verify installed Java compiler version
- javac -version
2. Create a sample Java program
We have created a simple Java program "HellowWorld.java", which will just print "Hello World" as shown in the video.
3. Compile the Java program
We can use the below command to compile the program from the command prompt, where "HelloWorld.java" is the java class file containing the main method.
- javac HelloWorld.java
Once we compile the program, it should create the compiled version of the java file, which is "HelloWorld.class".
So, now we have both "HellowWorld.java" and "HelloWorld.class" after successful compilation.
4. Execute the Java program
We can use the below command to execute the program from the command prompt, where "HelloWorld" is the program name.
We just need to provide the program name and file extension ".java" or ".class" is not required.
- java HelloWorld
Once we execute the program, it should execute the main method and print the value from the print statement we have in the main method.
======================
Happy Learning!!
Team,
Random Codez
Смотрите видео Create, Compile and Execute a Simple Java Program онлайн без регистрации, длительностью 02 минут 29 секунд в хорошем hd качестве. Это видео добавил пользователь Random Codez 25 Август 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 9 раз и оно понравилось людям.