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;