MAC Terminal commands run Java

Source: Internet
Author: User

Link Address: http://www.cnblogs.com/wangrui-techbolg/archive/2012/12/29/2839047.html

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.

MAC Terminal commands run Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.