Compiling and running problems with Java files after adding package statements

Source: Internet
Author: User


For beginners, often encountered a problem is to add a package statement after the source file can not compile successfully ;

There are generally two ways to deal with this situation, as shown in the figure;


Here we assume package org.xiazdong;

Hello.java

Package Org.xiazdong;
public class hello{public
	static void Main (String args[]) {
		System.out.println ("Hello world!!!");
	}



The first scenario is to place the Hello.java source files directly in the home directory, and you need to use the

Javac-d. Hello.java

When this command is run, the Org/xiazdong directory is created automatically and the Hello.class is placed in Org\xiazdong;

Use in the home directory again

Java Org.xiazdong.Hello

can be run.

The second scenario is to place the Hello.java in the ${basedir}\org\xiazdong, which only needs to be used under the directory Org/xiazdong

Javac Hello.java

And then use it in the home directory.

Java Org.xiazdong.Hello

Run

The last compiled class file is in ${basedir}\org\xiazdong\hello.class

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.