Computer Science, asked by sureshchand71, 1 year ago

Plz tell me to how to run a program in java as this error is coming.​

Attachments:

Answers

Answered by Hiren5050
0

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.


Hiren5050: please add me brien list
Answered by QGP
0

Running a Java Program on Command Line

Your Command Prompt says this:

 \rule{300}{1}

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

 \rule{300}{1}

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:

\texttt{C:\textbackslash Users\textbackslash User}

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:

\texttt{cd C:\textbackslash Users\textbackslash User\textbackslash Documents}

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:

\texttt{chdir /D E:\textbackslash} \\\\ \texttt{cd Programs}

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.

 \rule{300}{1}

\texttt{javac tanmay.java}

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:

\texttt{java tanmay}

Similar questions