I am trying to compile one file in a java project, but I am seeing other result (result of another file ) in console. I even tried Ctrl + F11 but the same thing happened
In the dropdown of Run button of Java I am not finding the current file name but if I start a new project and run the file it is compiling. Note:I am a beginner in Java.
Your class has to define a public static void main(String[] args) method. Then find the Java file in the project explorer, right-click on it, and choose "run as Java application". The file name has to be the same (+ extension ".
You will need to go to Project->Clean...,then build your project. This will work, even when your source code does not contain any main method to run as an executable program. The . class files will appear in the bin folder of your project, in your workspace.
One way to do this would be to add a method public static void main(String[] args) containing the code you want to run. Once you've done this, you can right-click on it, choose the "Run as..." option, and select "Java application" to run the program you've written.
Starting with Java SE 11 and for the first time in the programming language's history, you can execute a script containing Java code directly without compilation. The Java 11 source execution feature makes it possible to write scripts in Java and execute them directly from the *inx command line.
In addition to the info in the answer already selected, others having this or a similar problem should chech the "Run Configurations" panel to make sure the setting are correct for the app you are launching. Check
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With