Plz tell me to how to run a program in java as this error is coming.
Answers
Answer:
1 Answer
Open a command prompt window and go to the directory where you saved the java program (MyFirstJavaProgram.java). ...
Type 'javac MyFirstJavaProgram.java' and press enter to compile your code. ...
Now, type ' java MyFirstJavaProgram ' to run your program.
You will be able to see the result printed on the window.
Running a Java Program on Command Line
Your Command Prompt says this:
C:\Users\User>javac tanmay.java
javac: file not found: tanmay.java
Usage: javac <options> <source files>
use --help for a list of possible options
Understanding the Error
The Error thrown was file not found. The simple reason for this is that the file tanmay.java does not exist at the path where you are executing your command.
Your Command Prompt tells us that right now you are at the following folder path:
Your file tanmay.java is not in this Folder. That is why, the command javac returned an errror.
Tackling the Error
First, Go to the path where your file is created.
Suppose your file is in the Documents Folder. Then you could go to the path by entering the following command:
The cd command changes the directory to the path entered after it.
Suppose, instead, your file is in E Drive in some folder named Programs. Then, you could enter the following commands one by one:
The first command changes the Drive to E:\
The second command changes the directory to Programs
Learn the use of cd and chdir commands to navigate through the files in Command Prompt.
Finally, when you have reached the folder where your file tanmay.java is stored, you can compile and run it.
This command compiles the Java Source Code File.
If there are no Compilation Errors, the file will compile and a tanmay.class file will be created. This is the Java Bytecode file which will be run by the Java Virtual Machine (JVM).
Then the Java program can be run with the simple command: