Create a new folder in your Documents folder (e.g. samples), and open a command prompt window there. Create your source program and save it in that folder. Then in the command window type the following:
javac <your source file name>.java
That will compile the program and show you any errors. Fix the errors and repeat the process until there are no errors. You can then run your program with the command:
java <your source file name>
Make sure that the file name is the same as the class name in your code. For example:
import java.io.*;
import java.util.Scanner;
class Test {
int doTest() {
int rc = 0;
return rc;
}
public static void main(String[] argv) {
Test javaTest = new Test();
int result = javaTest.doTest();
System.out.printf("Java test result: %d\n", result);
}
}
This code must be saved in a file named
Test.java
.
I use Visual Studio Code as my development environment for Java, which provides a command window as standard option.