Java Foundation (object-oriented before)

development tools:

  JDK (JavaDevelopmentKit): Java Development Kit (contains JRE + development tools)

  JRE (Java runtime Environment): a collection of Java Runtime Environment environment necessary to run Java programs (java program can only run if just download JRE), contains the JVM and Java core libraries

  JVM (Java Virtual Machine): Java Virtual Machine, Java cross-platform key (for different systems have different versions of the JVM)

Java programs run process:

  Hello.java --- compiled ---- Hello.class --- --- Run on JVM execution

The basic structure of a Java program:

  

. 1  public  class the Hello class {// Start
 2    // process begins
 . 3    public  static  void main (String [] args) {
 . 4  
. 5      System.out.println ( "the HelloWorld" );
 . 6  
. 7    } // End Method
 8 // Class end
 9 }

 

  The basic unit is a program in Java class (class)

  Class Requirements:

    Class names must start with an English letter, followed by a combination of letters, numbers and underscores (used to begin with a capital letter)

    Class can have a plurality of methods but the main method is the entry of all programs (in a class must be the main method begins execution start)

  Comment:

    Java annotations in three ways: documentation comment, single-line comments, Multiline comments

    Format are as follows:

        /**

          * Notes can be used to create a document that can be used to automatically create documents

          */

        / * Multi-line comments start

          Notes content

          Multi-line comments End * /

        // a single line comment

Variable (variable):

  The first variable is defined must specify variable type, can not be assigned, but before using the assignment (defined variables can not be repeated)

  Try to follow the action when defining variables to minimize principle

  Variable name = value data type variables;

  The basic types of variables:

    byte: Byte 1 Byte 2 . 8

    short: Short Integer 2 bytes 2 16

    int: Integer Byte 2 4 32 (default integer int)

    long: Long 8 byte 2 64

    char: character (defined single quotes) bytes 2 2 16

    float: 4 single precision floating point byte 2 32

    double: double precision floating point (decimal default double) 8 byte 2 64

    boolean: a value of True / False (typically allocates 4 bytes)

 

  Other variables:

    String Type:

      The definition of double quotes, such as "123", "you and me", "eini"

      There are of type String participate in the "+" will become a string of splicing

    array array:

      Data Type [] = new Array name Data type [array length]

      Without assignment, integer default to 0, floating point by default to 0.0, Bulmer considered false

      Data Type [] = new Array name Data type [array size] {val1, val2, val3, val4, ...}

      Data Type [] array name = {val1, val2, val3, val4, ...}

      Address array name is stored (JVM allocated memory address) assignment starting pointing to the array element

      arr.length: Get length of array

      import java.util.Arrays

      One-dimensional array output is available: System.out.println (Arrays.toString (arr));

      Multidimensional array output is available: System.out.println (Arrays.deepToString (arr));

      Array traversal can be used for ... each 

Constant (constant):

  When you define a variable front plus final qualifier, the variable becomes constant,

  Such as: finale PI = 3.14

cycle:

  

. 1        // IF Format 
2    IF (Analyzing expression) {
 3  
. 4      statement. 1;
 . 5  
. 6    } the else  IF (Analyzing expression) {
 . 7  
. 8      statement 2;
 . 9  
10    } the else {
 . 11  
12 is      statement 3;
 13 is  
14    }
 15  
16    / / Switch format, attention case switch penetration 
. 17  
18 is    Switch (condition) {
 . 19  
20 is      Case . 1 :
 21 is  
22 is        the statement. 1;
 23 is  
24        BREAK ;
 25  
26 is     Case 2 :
 27  
28        Statement 2;
 29  
30        BREAK ;
 31 is  
32      default :
 33 is  
34 is        the statement. 3;
 35  
36        BREAK ;
 37 [  
38 is    }
 39        // the while format 
40    the while (Analyzing expression) {
 41 is  
42 is      the statement;
 43 is  
44 is    }
 45        / / do format the while 
46 is    do {
 47  
48      statement;
 49  
50    } the while (Analyzing expression)
 51       //for格式
52   for(int i=0;i<=10;i++){
53 
54     语句;
55 
56   }
57       //for each格式
58   int[] arr = {1,2,3,4,5}
59 
60   for(int a:arr){
61 
62     System.out.println(a);
63   } 

 

Guess you like

Origin www.cnblogs.com/nanhua097/p/11224080.html