
In this article, we will learn about some basics of the java program. hare we will learn how to run java program manually using command prompt. There are a lot of IDE (Integrated Development Environment) like Eclipse, Netbeans, STS, etc, where we can write a code and execute our java program. But before that, we have to understand how to java program executes to our system manually.
JAVA is a general-purpose class-based object-oriented programming language and java was created in 1995 at Sun Microsystems by James Gosling.
JAVA is used for developing web applications, mobile applications, game consoles, windows applications, etc.
After writing JAVA code at compile time it will covert source code into Byte code. After that, it will convert into machine code by JVM(java virtual machine).
Let's Start from begaining and all the procedure will discuss below:
1) JDK(Java Development Kit) and JRE(Java Runtime Envirinment) must have installed in computer.
2) After installing the JDK and JRE we have to set path bacause without seting up this path we can not access java and javac tools.
3)Download and install any editor like notepad, notepad++, sublime text, VS Code etc. Hare we will write code in notepad++.
After successfully installing jdk and jre we need to set a path. hare we are using operating system windows 10. The whole process for the creating a path are given below.
1) After successfully creating a path we have to open a command prompt by pressing the "windows+R" button. Then the black screen will display what is called the command prompt interface.
2) After opening a command prompt type a java.
3) After typing a java we will see some kind of command over there then we will understand that java has been installed.
In this section, we will learn how to execute a java program using a command prompt. There are some following steps. we have to follow the all steps.
Step 1: First we have to write a program on notepad++.
hare we are writing a program about the addition of two numbers. the programs are given below.
in this program, we are trying to do the sum of two numbers. here we took two-variable "a" and "b" with integer data type in the main method. and assign a value of "a+b" in the "sum" variable. after that we use the command "System.out.println()" to print the value for showing the output.
Step 2: After that make a folder in any drive and save this file inside this folder. But the file should be saved by the class name of the program. and after that put an extension " .java ".
in this article, I create a folder with the name "manual console " inside the "E:" drive.
Step 3: Now we have to open the command prompt. by pressing "windows+R", a pop-up window will open and type "cmd". and click the "ok" button.
Step 4: After that, a command prompt window will open. and we have to put some command over there. the comment is given below.
if we want to enter another drive then we have to put the drive name with a colon. for example, I have written hare "E:+enter".
next, we have to enter into that folder where the file has been saved. for that we have to write "cd+spece+foldername". after that we will enter that folder. hare we have written command "cd e2ehiring" and after that again written "cd manual console". then we will enter that folder where we saved that java file as I discussed before.
Step 5: If we want to see all the folders inside the "manualControl" folder then we have to put the command " dir ". then we can see the all folder or files inside it.
Here we can see the file in the red circle which we saved before inside the manualconsole folder with a program class name. Hare in this article program class name is "SumOfTwoNumbers.java".
Step 6: After finding the file name then we have to execute the program. follow the steps which are given below.
Step 7: First we have to compile the program. for that we have to use the command "javac+space+filename.java", hare we used the command "javac SumoftwoNumbers.java".
hare compiler can not find any error in this program. if the compiler finds any error then it will generate on the screen.
Step 8: After compilation of this program we can see a class file in the folder class name with the ".class" extension.
Step 9: Now we have to execute the program. for execution we have to write "java+space+programname". hare no need to write the ".java " extension. hare we have written a command "java SumOftwoNumbers"
In this diagram, we can see that compiler executed the program. and also we can see the output in a marked red circle. we have already discussed before that we took two variables a and b and stored value 10 in variable a and also store value 20 in variable b. and also assign a+b into the sum variable. and print it by System.out.println method. and we can see the output is 30.