How to run Java Program in cmd step by step
Java Logic & Code

How to run Java Program in cmd step by step

Now we are Learning “ How to run Java Program in cmd step by step Let’s Start.

When I was learning java, we were forbidden to use the IDE in the lab, all of the programs were made in notepad and had to run them from the console. If this is the case with you, then learn to run a Java program from the console.

Compiling and Running Java Programs


Before running the Java program, we have to compile the Java source code in the bytecode. Computing makes the javac compiler. Java’s bytecode is platform independent. Survival of the platform means that it does not matter which computer you are running, Windows, Unix or make.

In the mind of any of you people, this question must have been raised that how can a Java language platform (Java can run easily in any machine)?

How to run Java Program in cmd step by step

The direct answer is


  • Java Virtual Machine. Which we call the JVM and the Cremation Machine. By the name of this machine, it would have been clear that this is a delicate machine
  • Which is only made to relieve Java from the platform. Java’s bytecode is written for this machine. And this machine works equally on all platforms. In different words
  • We can say that JVM is a layer between our machine and Java.

Now we will see how to compile Java programs. Suppose the name of the program is Abc.java (the first letter of the program will always be Capital).


How to run Java Program in cmd step by step

 


class Abc
{
public static void main(String args[])
{   
System.out.println(“Hello World”);
}
}      // How to run Java Program in cmd step by step.

  • Step 1: Write the following Steps to run Java Program using the command prompt in notepad.
  • Step 2: Now Second step to Save it as the same class name like HelloWorld.java ( * When you save your java program, then you know that the first letter is always the Capital letter ).
  • Step 3: This is the third step, where you can Set the environment variable.

For Example:-

Now click it your right side button in Mouse on [ then go to, MyComputer – Properties -Advanced System settings – Inside Advanced tab ]

Then Click Environment variables – Inside System Variables click it New key -> Give the variable name (For example var) – Give variable value. This is your path in the system where java compiler is available (For example variable value:- C:\Program Files\Java\jdk10.0.2\bin ). Inside bin, javac is Java compiler.

Then Click Ok & Next.

  • Step 4: And next open your command prompt by using start or search->Run->cmd OR start-> type cmd in search program and file.

Press Enter.

  • Step 5: Now Use the following command prompt to go the folder where your previous Java program is stored.

Press Enter

  • Step 6: Here Set path of Compiler. It is the path in your system where java compiler is available.

For example, set your path=C:\Program Files\Java\jdk10.0.2\bin;

Press Enter

  • Step 7: Write the following command for the compilation of the java program.
Now see the command to compile it.
  • Windows
  • C:/> javac Abc.java
  • In Linux
  • % javac Abc.java

If there is no error in the source code, then Java will create one or more class files. Each class file will be for a class of the program as if the program has two classes, it will create two class files. For the above program, it will create a file named Abc.class.

How to run the Java program

Once you have successfully compiled the Java source code, you can give the command of Java to the Running machine by running the program’s bytecode.

  • Windows
  • C:/> java Abc
  • In Linux
  • % java Abc

for example:- C:\> javac Abc.java

C:\> java Abc

Output:- Hello World


Now Click Here to read other Blog Posts Such as Latest Technology News, Gadgets, Mobile, Logic & Code etc.

How to run Java Program in cmd step by step

Manish Mishra
* Manish Mishra *:- A Blog Scientist By the Brain & a Passionate Blogger By Heart💟 Life Motto:-'Do my best, so that I can't blame myself for anything.'
https://www.cybermarquee.com/

2 Replies to “How to run Java Program in cmd step by step

Leave a Reply