Why do i need to use javac to compile my code?

Viewed 65

Let's say i have a code like this :

public class Test {
    public static void main(String args[])
    {
        int x = 5;
        // Widening Casting
        double myNum = x;
        System.out.println(x + " " + myNum);
    }
}

Now i write the following commands in powershell changing the value of x from 5 to 6 once in my code and saving it, it works perfectly fine. But tutorials online suggest me to use javac for compilation. Why so?

enter image description here

1 Answers

From Java 11 onwards, the java command is able to compile and run a single Java source file with a static void main(String[]) entry point method. (This feature was added as JEP 330.)

The online tutorials are correct for Java 10 and earlier, and they are correct for cases where more than one Java source file needs to be compiled.

Related