Java serialization 49- constant format, package package introduced

First, the constant

1. Definition of constants: final modifications are immutable instance variables, and static variables are generally of such combined use, referred to as "constant"

2. constant syntax:

 

public  static  Final type constant name = value;

 

 

java specification requires that all constants names in all caps, use an underscore between each word connection

 

Package com.bjpowernode.java_learning; 

public  class D49_Constant { 

  public  static  void main (String [] args) { 

    System.out.println (Chinese49.GUO_JI); 

    System.out.println (Math49.PI); 

  } 
} 



class Chinese49 { 

  // nationality 

  // requirements: every Chinese nationality is Chinese, and nationality will not change, in order to prevent citizenship being modified, the proposed modification plus final 

  public  static  final String GUO_JI = "China" ; 

} 

class Math49 { 

  public  static  final  Double the PI = 3.1415926 ; 

}

Two, package

 1. With regard to the java language package mechanism:

(1) package, also known as package, java syntax in this package as the main mechanism to facilitate the management of the program. Type different functions are separated and placed in different packages, easy to find, relatively easy to manage, easy to maintain.

(2) how it is defined package?

i. to prepare a package statement on the first line of java source code

ii.package can only write a statement

. Iii grammatical structure: package package name;

(3) the package name naming convention:

The company reverse domain name + + project module name + function name

In this way a lower risk of the same name, because the company has a globally unique domain name

E.g:

com.bjpowernode.oa.user.service;

org.apache.tomacat.core;

(4) requires all lowercase package name, the package name is the identifier must follow the naming rules for identifiers

(5) a packet corresponding to a future directory.

After (6) using the package mechanism so how to compile, how to run it?

Or normal compiler compiler

But the operation, after using the package mechanism, the class name is no longer the name of the original file, the class name is "the package name. Filename", and the folder where it had built in advance, the class files manually into under the corresponding directory, if it is not so much with the IDE, you can compile and run directly.

Note: Another way:

i compiler: java source path storage path after compiling java -d

E.g:

javac -d D:  D:/java/test.java

The D: /java/test.java compiled into class files into the D: drive under

javac -d .  *.java

All the java files in the current directory are compiled into class files into the current directory

ii run:. JVM ClassLoader default class loader to load from the current path. Guarantee DOS command window to switch to the path where the path com, execute: java com.bjpower.javase.day11.Test01

V. Source:

D49_Constant.java

address:

https://github.com/ruigege66/Java/blob/master/D49_Constant.java​

2.CSDN: https: //blog.csdn.net/weixin_44630050 (Xi Jun Jun Moods do not know - Rui)

3. Park blog: https: //www.cnblogs.com/ruigege0000/

4. Welcomes the focus on micro-channel public number: Fourier transform public personal number, only for learning exchanges, backstage reply "gifts" to get big data learning materials

 

 

Guess you like

Origin www.cnblogs.com/ruigege0000/p/11832484.html