Create a file with extension .java, for example Hi.java.
Inside your Hi.java file, create something like:
public class Hi { public static void main(String[] args) { System.out.println("Hi"); } }
Open a terminal in the directory where your Hi.java file is located (in your example in the desktop).
In the terminal, run the command:
javac Hi.java
The file Hi.class should be created in your current directory (Desktop).
In the terminal, run the command:
java Hi
Note that:
In Java files should terminate with .java, and it is best practice that a file name should start with a capital letter. You cannot use a file with extension .txt or any other extension. If you want to run a Java class then a .java filename extension is required and is not optional.