Helloworld.java:1: Error: Class HelloWorld is public and should be declared in a file named Helloworld.java HelloWorld

Source: Internet
Author: User

After building and configuring the JDK environment, prepare to test for success.

So I copied and pasted a piece of code with Notepad.

 Public class HelloWorld {    /**    * Output line string "Hello world!"     @param args     */     Public Static void Main (string[] args) {    System.out.println ("Hello world!" );    }}

Save as Helloworld.java file.

Then, in the cmd command line, using Javac compile (input Javac Helloworld.java), this prompt error occurs:

Helloworld.java:1: Error: Class HelloWorld is public and should be declared in a file named Helloworld.java HelloWorld

At that time do not know what this error means, always thought that the program inside what is missing a statement. (then the brain emerges similar to a microcontroller program that needs to be declared again).

Because a year did not touch the Java, then learned a little fur also forget. It was later remembered as if the class name in Java would be consistent with the file name.

Then locate the Helloworld.java file, change the file name to Helloworld.java, and then compile and run.

There was an expectation:

Hello world!

Helloworld.java:1: Error: Class HelloWorld is public and should be declared in a file named Helloworld.java HelloWorld

Related Article

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.