Java tutorial-CMD manual compilation and running failure cause (Master skipped), java failure cause

Source: Internet
Author: User

Java tutorial-CMD manual compilation and running failure cause (Master skipped), java failure cause

(This is only for beginners and masters) when we use cmd to manually compile a Java program at the early stage of learning java, we will encounter a successful compilation, but the running will always prompt a failure. The java configuration environment has been ruled out. The Path settings for Path, ClassPath, and % JAVA_HOME are all correct, and the file name for compiling and running is case-insensitive. So why? See the following brief analysis. For example

The source code is as follows:

1 package lee; 2 public class Hello3 {4 public static void main (String [] args) 5 {6 System. out. println ("HelloWorld !"); 7} 8}

We do not have a package concept for new users, but we will be confused at the beginning of the program.Package lee;

The cause of this error is here. Our Hello class is stored under the package lee, so the compiled Hello. the class should be stored in the lee folder, but during practice, we usually compile and save it in the same directory, as a result, the system prompts "cannot be found or the main class Hello cannot be loaded" during running ".

Solution:

Method 1: DeletePackage lee;This line.

Method 2: place the generated Hello. class file in the lee folder.

 

After the change, the system runs normally.

 

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.