Command line form, understand the Java package access rights, and the relationship with the. java file, familiar with the Java file storage relationship;

Source: Internet
Author: User

Everyone, while learning Java, mostly use the IDE environment such as Eclipse, but this is not good, and the package access rights, is also a key step of framework control in Java,

Only if you really have to master. The relationship between Java files and the package can really grasp the relationship, and help to write a good framework;

Less nonsense, first on the code;

This is with the package com.xuyaowen.demo; File, which represents the location of the Jack.java file;

Package Com.xuyaowen.demo;public class Jack{jack () {System.out.println ("I am jack!");}}

What about generating files like this?

With the command line:

Enter the folder where the Jack.java file is located, at this time should only you have just written, Jack.java file;


Enter the command:

Javac-d. Jack.java
At this time in the same directory Jack.java, COM folder Open is Xuyaowen folder and then the Demo folder to open is the Jack.class file,
What's up, smart you already understand?
The analogy, in turn, to achieve a project package, belongs to their own.
Below I also have an article to the article in the material, made into jar package, for us to use;
Reprint Please specify source: Http://blog.csdn.net/happylaoxu
The rest of the code is less nonsense:
<pre name= "code" class= "java" >package com.xuyaowen.demo;import com.xuyaowen.data.*;import com.xuyaowen.son.*; Import static com.xuyaowen.statics.static.*;p Ublic class Use{public use () {System.out.println ("This is the entrance to the program you have entered! "); Jack user_1 = New Jack ();//In order to differentiate the same class name in different treasures tom;com.xuyaowen.data.tom user_2 = new Com.xuyaowen.data.Tom (); Com.xuyaowen.son.Tom  user_3 = new Com.xuyaowen.son.Tom ();//If all the methods of a class in a package are static type, then you can use static import; Add (); Sub ();} public static void Main (string[] args) {System.out.println ("This is the entrance to the program, you have entered!" "); Jack user_1 = New Jack ();//In order to differentiate the same class name in different treasures tom;com.xuyaowen.data.tom user_2 = new Com.xuyaowen.data.Tom (); Com.xuyaowen.son.Tom  user_3 = new Com.xuyaowen.son.Tom ();//If all the methods of a class in a package are static type, you can use static import; Add (); Sub ();}}


<pre name= "code" class= "java" >package Com.xuyaowen.statics;public  class static{public Static void Add () { System.out.println ("This is the addition of mathematics!") ");} public static void Sub () {System.out.println ("This is the subtraction in mathematics!") ");}}


Package Com.xuyaowen.statics;public  class static{public Static void Add () {System.out.println ("This is the addition of mathematics! ");} public static void Sub () {System.out.println ("This is the subtraction in mathematics!") ");}}



Package Com.xuyaowen.demo;public class Jack{jack () {System.out.println ("I am jack!");}} Reprint please indicate the source

Hope will help everyone!



Command line form, understand the Java package access rights, and the relationship with the. java file, familiar with the Java file storage relationship;

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.