Commands for creating packages under the Java DOS window

Source: Internet
Author: User

in Java, a package is used to solve a class name conflict problem, which is a set of related classes and interfaces

Advantages of the package: avoid a large number of class name conflicts and enlarge the namespace.

Package embodies the encapsulation mechanism.

 Packagestr;Interfacetemplate{LongFactorial (intm);LongMypower (intMintn);}classToolImplementstemplate{ Public LongFactorial (intm) {        intSum=1;  for(inti=1;i<=m;i++) Sum*=i; returnsum; }         Public LongMypower (intMintN) {        intsu=m;  for(inti=2;i<=n;i++) Su*=m; returnsu; }} Public classfive3{ Public Static voidMain (string[] args) {tool T=Newtool (); System.out.println ("The factorial of 5 is:" +t.factorial (5)); Tool L=Newtool (); System.out.println ("4 of the 1-time side is:" +t.mypower (4,1)); }}

  in this code example, the first line of the required Java file is written package name;

  Package Name: The package you want to create gives it a proper name.

  After adding this statement to save, you can execute this command under DOS window to create the package named Str:

  Javac-d. Five3.java

  

  Note that javac behind the space ,-D after the space, the space behind the dot must be taken, not less!!! , this statement needs to be executed in the Java file directory.

When you're done, you'll find that a folder is generated in your file,

  

  

  

because the first line in the Java code is written to the package str, the str folder is generated, and he is the one that created it.

Because of the three classes created in the Java code, this place will be placed under the created package, so how to execute him, very simple, only need to enter a command to

  Java str.five3

Note: The format for this is:Java package name. Class Name//This class name needs to contain the main method to be executed, generally called the main class.

  The results of the implementation are as follows:

  

  

Commands for creating packages under the Java DOS window

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.