Javac\java Class with package path

Source: Internet
Author: User

Nearly two days since the first entry, belonging to the familiar environment of the stage, the next algorithm (fourth edition), when not using the IDE tool directly using the terminal for Javac compiled with the package class, and then use Java will appear the following error prompt:

Using Google search for a long time, finally found a solution to make a record, lest it will forget

Because the problem occurs because the package path exists in the Binarysearch.java class, I use Eclipse to place the file in workspace.

Package com.sort;

 Public classBinarySearch { Public Static intRankintKey,int[] a) {        returnRank (key,a,0,a.length-1); }         Public Static intRankintKey,int[] A,intLointhi) {        //if key exists with a[], its index will not be less than lo and will not be greater than hi        if(Lo>hi)return-1; intmid=lo+ (Hi-lo)/2; if(Key < A[mid])returnRank (key,a,lo,mid-1); Else if(Key>a[mid])returnRank (key,a,mid+1, HI); Else returnmid; }             Public Static voidMain (string[] args) {int[] a={0,2,4,5,6,7,12,45}; intT=rank (1, a);        System.out.println (t); //stdout.println ("Hello, World");    }}

The package path for this class should be com.sort

When the compilation is complete, the package name of the package still needs to be taken, both Com.sort.BinarySearch and because the edit file is under the sort package, which requires us to navigate to the COM package using a relative path.

Use the command JAVA-CP. /.. / Com.sort.BinarySearch

The command executed successfully.

Javac\java Class with package path

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.