Compiling the java code

while I try to run the java code through terminal for the variables program in the tutorial, i get the below error.
C:\Users\PraveenKumar\IdeaProjects\MyLearning> javac Main
error: Class names, ‘Main’, are only accepted if annotation processing is explicitly requested
1 error
this is my code:
package com.praveen;

public class Main {

public static void main(String[] args) {
// write your code here
    System.out.println("Hello world!!!");
    int age=24;
    System.out.println("my age is:"+age);
}

}

pls clarify this error on this compilation

You compile the file (so “Main.java” not “Main”) then you run the output program.

javac Main.java
java Main

I see that each time, I have to change the path to compile and get the output.

C:\Users\PraveenKumar\IdeaProjects\MyLearning\src> cd com/praveen
PS C:\Users\PraveenKumar\IdeaProjects\MyLearning\src\com\praveen> javac StringDemo.java
PS C:\Users\PraveenKumar\IdeaProjects\MyLearning\src\com\praveen> cd …/
PS C:\Users\PraveenKumar\IdeaProjects\MyLearning\src\com> cd …/
PS C:\Users\PraveenKumar\IdeaProjects\MyLearning\src> java com.praveen.StringDemo

its like this only or in one path i have to execute like abv u mentioned

Unless you are compiling your output into a different directory, I believe you should be able to run java StringDemo from the praveen directory. If not, you could just stay at the src directory and specify the relative path to the StringDemo.java file:

PS ...\src> javac com\praveen\StringDemo.java
PS ...\src> java com.praveen.StringDemo

Thanks a lot. it helped :slight_smile: