The basic design of the program structure 01_Java 1

3.1 A simple Java application

public class FirstSimple
{
    public static void main(String[] args);
    {
        System.out.println("hello world!")
    }
}

  1.Java case sensitive

  2. Keyword called public access modifier (access modifier)

  3. The keyword class indicates that the entire contents of a Java program are included in the class. the entire contents of the java application must be placed in the class. It is followed by the class name. Class names recommended by the hump law to write.

  4. The file name and the name of the source code must be the same as the class public, and with the end of .java.

  5.System.out.println () indicate the use of System.out object and call his method println. The general syntax of java is obj.method (para)

  6. begins with / ** to comment * / at the end of the document can be automatically generated. Specific methods, see Chapter 4

 

3.2 Data Types

public  class the Main 
{ 
     public  static  void main (String [] args)   
    { 
    Double X1 =. 3-0x1.0p ; 
    of System.out.print (X);   // 0.125 the without / n- 
    System.out.println (2.0-1.1);   // 0.1250.89999999 
    int I = 1; // 'I' can be used as a variable, I Unicode characters belonging to the java "letter" 
    IF (Character.isJavaIdentifierPart (I)) System.out.println (I);   / / . 1 
    char L = 'I' ;
     IF (Character.isJavaIdentifierStart (L)) System.out.println (L);   // I 
    } 

}

  1. In java, integer range regardless of the machine running java code.

  2. Long followed by l or L, or a 0X hex 0x, octal front is 0, the binary representation 0b or 0B

  3.java in no form unsigned int, long, short or byte type.

  4.java default decimal form double, float if it is necessary to add the suffix f or F, because the note is a binary representation, the decimal point can not be accurately expressed in numbers other than 5 ends. As Example

  5. Using the floating-point value in hexadecimal notation. 0.125 == 0x1.0p-3, wherein p represents a base 2 exponential

  6.Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY Double.NaN represent the three special value. Which is not a NaN value can not be detected using == Double.NaN, may be used Double.isNaN (x) method.

  7.java the 'A' value is coded character constants 65 (char), and "A" is a string (String).

  . 8 .java boolean type has two values are not interchangeable between the false and true, integer and Boolean values.

  9. python different and, after java declared variables must be explicitly initialized, additional C ++ and can, without distinction java definitions and declarations.

  10. If you want to know what the Unicode character belongs to java in the "letters" can be used isjavaIdentifierStart and isjavaIdentifierpart character classes

  11. In java with the final indication constant . final double PER = 1.2; final keyword indicates that the variable can only be assigned once. In java, a variable is often desirable to use a plurality of methods in a class, generally referred to as class constants these constants. You can use the keyword static final to set up a class constant .

    Note: The definition of the class constant is located outside the main process. Thus, in other methods of the same class may also be used in this constant. And this constant is declared as Public, then the methods of other classes can also use this constant.

 

Operators 3.3

 

    public static strictfp void main(String[] args) {
        double x = 4;
        double y = Math.sqrt(x); // public static double sqrt(double a)
        System.out.println(y);  // 2.0 public static final PrintStream out = null;
        System.out.println(-15%6);  // -3
        int a = Math.floorMod(-15,6);  // like % ,but a little different
        System.out.println("a is " + a);  // a is 3
        System.out.println("π is" + PI);  // here PI = Math.PI
        int b = 123465789;
        float c = b;
        System.out.println("b is " + b + '\n' + "c is " + c);  // b is 123456789 c is 1.234567892E8是 10的8次但是多了一个2?
        double d = b +c;
        System.out.println("d is "+ d);  // d is 2.46931584E8
        x = 9.997;
        int nx = (int) x;
        System.out.println("nx="+nx);
        nx+=3.5;
        nx++;
        System.out.println("nx ="+nx);  // 9+3.5 = 9+3=12 nx = (int)(nx +3.5),but nx = nx + 3.5 will error!

 

 

 

 

 

 

1. For floating point arithmetic is very difficult to achieve portability. By default, the virtual machine allows the designer to intermediate results in extended precision. However, the method using strictfp keyword tag must use strict floating-point calculations to generate reproducible results.
For example public static strictfp void main (String [ ] args)

2. In Math class contains a variety of mathematical functions. In the preparation of different types of programs, functions that may be required are different. Wherein the Math.sqrt different () method and a System.out.println () method. The former is a static method. The latter process System.out object. Further a method of power Math class there POW (x, a) find x, methods floorMod integer remainder, the effect equivalent%, but for the remainder of the absolute value of the negative.

3.Java used Math.PI Math.E and π and e represent an approximation.

4. Do not boolean values ​​between any type of cast types, so that errors can be prevented. (So ​​the question is, how to convert between int String boolean it?)

5. If the operator to get a value, which is a different type as the left-hand operand, casts occur. E.g. int x = 1; x + = 3.5; // 1 + 3.5 = 4 [ This and different binary operator! ]

6. The increment and decrement, cpp, there are also points of prefixes and suffixes, and then adding a prefix to use a variable; the variable plus a suffix to use. In Java and relational operators in the same cpp, according to "short" computationally, && and || represent logic or logic, if the first operand has a value of the expression can be determined, the second operand You do not have to calculate.

   eg x! = 0 && 1 / x> x + y // no division by 0. If x is equal to 0, then the second portion will not count. Thus, if x is 0, it will not calculate 1 / x

7 and Cpp different , java >>> be filled with 0's, >> filled with the sign bit.

8. Operator Priority

 

Guess you like

Origin www.cnblogs.com/SsoZhNO-1/p/11569404.html