Since the MAC is already installed in the Java environment, it is convenient to run the Java command directly from the class.
Compile a Java file: javac/users/username/desktop/helloworld.java (after running will get a Helloworld.class file, store directory in Desktop)
Run: First to CD to Helloworld.class directory, then: Java HelloWorld (HelloWorld is the class name without suffix).
Add edits
Recently look at the design pattern, the inside of the code is java. So I started compiling Java code with the command line, but there were a variety of errors. It took a lot of time to solve. Here to record, in case
The same problem occurs again.
Problems:
1, coding error, the source file changed to Utf-8 encoding is good;
2, when multiple classes are placed in a source file, do not declare public before the class, otherwise the compilation does not pass;
3, a source file contains multiple classes, compiled with multiple. class files. With the Parkage keyword, all classes can be automatically packaged into a directory using the javac-d command
4, contain pakege keyword, must first CD to the directory where pakege, compile will not error. (for example, Parkage is called ABC, under the Deskop directory.)
The Packgede directory is ~/desktop/abc. Then to CD ~/desktop).
5, when running, the same CD to the Pakage directory. In the example above, the CD ~/desktop. At run time, "Java Abc.xxxclassname". Note that you must add the package name.
From: http://www.cnblogs.com/wangrui-techbolg/archive/2012/12/29/2839047.html
MAC Terminal commands run Java