New Package : Upper left corner-new-Package
Naming conventions (usually from large to small, easy to integrate and not easy to conflict) For example: Com.itnba.maya.test
The package must be in the top row, and no more code can be
Using packages:
Shortcut: Use a variable name in the package alt+/
Import package name. class name; Reference only one of the import package names in the package. *; Refer to all examples in the package import com.itnba.maya.*;
Constants : Final (There are no true constants in Java.) Only the final type of variable can be used as represented. One definition, multiple use, cannot be changed)
Public final String ssss= "Hello World"; Constant names are all capitalized
The assignment of a constant can only be assigned at the time of the constructor or definition, and can only be assigned once
static member static corresponds to static, "instance"
private static String zhuren;//private static type variable;
Static members include: Static variables and static methods (functions)
Static variables and methods are shared by all objects (belonging to the Class) static methods can be invoked with the class name advantages: Save space
Example: Suppose we set up a class with the following code
Package Com.itnba.maya.ceshi;public class Cat {private String mingzi= "Xiao Huan"; Member variable private static String zhuren= "Harry"; Static member variable private String daxiao= "very small"; Member variable public static String Getzhuren () { //get get return zhuren;} public static void Setzhuren (String zhuren) { //set change cat.zhuren = Zhuren;}}
Then we call
Package Com.itnba.maya.ceshi;public class Jiao {public static void main (string[] args) {//TODO auto-generated method stub cat Mao =new Cat ( ); Cat mao1=new Cat (); Cat mao2=new Cat (); System.out.println (Mao.getzhuren ()); The default value is mao1.setzhuren ("Zhang San"); System.out.println (Mao1.getzhuren ()); Mao2.setzhuren ("John Doe") after assigning "Zhang San"; System.out.println (Mao2.getzhuren ()); System.out.println (Mao.getzhuren ()) After assigning "John Doe"; Finally, we output the default value again}}
The output is as follows
Why does the last output default become John Doe? The default value changes the properties of static members and static methods as each change changes: Static and static methods are shared by all objects
Static variables when storing data must be careful to prevent sharing conflicts.
Static methods can only manipulate static variables and static methods of the current class, cannot manipulate instance variables and instance methods, and call static methods in instance methods
In Java, the concept of a package, constants, static members, inheritance