Java Import Custom Class

Source: Internet
Author: User

Eclipse import is easy, yesterday in class learned to write Java with Notepad, import custom classes, which is troublesome.

Code paste, easy to operate:

 PackageTom.jiafei; Public classsquareequation {DoubleA,b,c; DoubleRoot1,root2; BooleanBoo;  PublicSquareequation (DoubleADoubleBDoublec) { This. A =A;  This. B =b;  This. C =C; if(a!=0) Boo =true; ElseBoo =false; }         Public voidSetcoefficient (DoubleADoubleBDoublec) { This. A =A;  This. B =b;  This. C =C; if(a!=0) Boo=true; ElseBoo =false; }         Public voidgetroots () {if(Boo) {System.out.println ("Shi er yuan Fang Chen Shi"); DoubleDisk = b*b-4*a*C; if(disk>=0) {root1= (-b+math.sqrt (disk)/(a)); Root2= (-b-math.sqrt (disk)/(a)); System.out.println ("The Roots is" +root1+ "" +Root2); }            ElseSystem.out.println ("Mei You Jie"); }        Else{System.out.println ("Bu shi er yuan fang Chen Shi Gen"); }            }                                }
View Code
import tom.jiafei.*;  Public class SunRise {    /**     @param  args     * /     Publicstaticvoid  main (string[] args) {        new squareequation (4 , 5, 1);        Equation.getroots ();        Equation.setcoefficient (-3, 4, 5);        Equation.getroots ();    }}
View Code

Direct:

C Disk has a two-yuan equation of the packet class, package name Tom.jiafei, compile, put the. class file into the Tom\jiafei directory.

D disk has a main function to use this class, first reset Classpath. hit a set classpath = .... \jre\lib\rt.jar;.; C:\1000

Then modify the environment variable set classpath = .... \jre\lib\rt.jar;.; C:\1000

Compile and run the main function.

Install Java, system default Classpath =....\jre\lib\rt.jar;.;

Indicates that the application can use the Nameless package class under the current directory, and the named Package (and corresponding) under the subdirectory.

If the application is to use a class that does not meet the above criteria, it is necessary to reset the classpath. Add a parameter, which is the top-level directory of the package name.

Conversely, if you meet the conditions, you don't have to be so troublesome, you can compile the main function directly.

Java import custom 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.