close

[Solved] How to fix “error: class found on application class path: Main” in java for visual studio code

Hello Guys, How are you all? Hope You all Are Fine. Today I am facing the following error How to fix “error: class found on application class path: Main” in java for visual studio code in Java. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How to fix “error: class found on application class path: Main” in java for visual studio code Error Occurs?

Today I am facing the following error How to fix “error: class found on application class path: Main” in java for visual studio code in Java.

How To Solve fix “error: class found on application class path: Main” in java for visual studio code Error ?

  1. How To Solve How to fix “error: class found on application class path: Main” in java for visual studio code Error ?

    To Solve How to fix “error: class found on application class path: Main” in java for visual studio code Error I solved it – my mistake. While executing the program using the terminal I was typing java Main.java, whereas the correct execution method was to type java Main.

  2. How to fix “error: class found on application class path: Main” in java for visual studio code

    To Solve How to fix “error: class found on application class path: Main” in java for visual studio code Error I solved it – my mistake. While executing the program using the terminal I was typing java Main.java, whereas the correct execution method was to type java Main.

Solution 1

I solved it – my mistake. While executing the program using the terminal I was typing java Main.java, whereas the correct execution method was to type java Main.

Solution 2

With Single-file source-code programs which is a new way of executing 1 File Java programs is only available since Java 11. You can run the command: java (Java File Name without .java extension)

java Main.java

Though please take into consideration that this way of executing only works if your Java project is only 1 Java File.

FYI: This single-file source code will be executed fully in memory and you can only import code that came with the JDK you are working. Finally if you want your code to run as fast as possible compile with javac before executing you program.

javac Main.java

java Main

Just be careful that there is no Main.class already in the folder, this may cause a confusion to the compiler.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read