Reputation: 209
How do you run code in a .txt file?
I know you're supposed to use a terminal, but it keeps giving this message:
javac: file not found: hii.java
Usage: javac <options> <source files>
use -help for a list of possible options
I saved my .txt file on the desktop.
Upvotes: 0
Views: 2666
Reputation: 382
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.
Upvotes: 4
Reputation: 589
After reading this, I cannot even think of where to start.
Just try something like JCreator Lite Edition (LE), and try to work in it for a bit.
While it is loading, I suggest reading something like this. You have to be in the same working directory as your file when you run that command.
Upvotes: 0