directory

  • Learning materials

  • Type conversion

  • variable

  • The operator

    • Arithmetic operator
    • Increment and decrement operators
    • Logical operator
    • An operator
    • Ternary operator
  • Package mechanism

  • JavaDoc generates documentation

Learning materials

B station crazy god said: www.bilibili.com/video/BV12J…

Type conversion

Casts.

/ * * *@ProjectName: JavaSE
 * @PackageName: PACKAGE_NAME
 * @Author: zy7y
 * @Date: 2020/8/14 10:17 am *@Description: type conversion; Syntax (type) variable */
public class TypeConversion {
    // From low to high
    // byte -> short,char -> int -> long -> float -> double

    public static void main(String[] args) {
        int intValue = 128;
        // If int is converted to byte, the memory will overflow and the precision will be lost
// byte byteValue = intValue;
        byte byteValue = (byte)intValue;
        System.out.println(byteValue); / / - 128

        // When the bottom turns high, it will automatically convert
        double doubleValue = intValue;
        System.out.println(doubleValue); / / 128.0


        // No conversion is required when the level is consistent (except for char types)
        short shortValue = byteValue;
        System.out.println(shortValue);

        // Memory overflow, and resolution instance
        // new JDK7 feature that separates numbers with underscores
        int money = 10 _0000_0000;
        int years = 20;
        int total = money * years;// -1474836480 Memory overflow
        System.out.println(total);

        // Resolve memory overflow; Convert something in an expression to a high point type
        long total1 = (long)money * years;
        System.out.println(total1); / / 20000000000}}Copy the code

variable

/ * * *@ProjectName: JavaSE
 * @PackageName: PACKAGE_NAME
 * @Author: zy7y
 * @Date: 2020/8/14 10:37 am *@Description: * Define a variable; Grammar; Type variable name = value * Local variable: a variable defined ina method whose value must be declared and initialized * Class variable: defined ina class, using the static modifier, belonging to a class * Instance variable: defined ina class * Constant: Final Type constant name */
public class Variable {
    / / constant
    static final double PI = 3.14;

    // Class variable: static, belongs to the class
    static String job = "Software testing";

    // Instance variables: belong to objects
    String adder;

    public static void main(String[] args) {
        // Local variables: variables in a method must be declared and initialized
        String name = "Xiao Ming";
        char sex = 'male';
        int age = 23;
        double height = 1.57;
        System.out.println(name +', ' + sex+', ' + age+', ' + height + 'm');

        // Use instance variables
        Variable variable = new Variable();
        System.out.println(variable.adder);

        // Use class variables
        System.out.println(job);    // Used by the current class
        System.out.println(Variable.job); // Other classes can be used this waySystem.out.println(Variable.PI); }}Copy the code

The operator

Arithmetic operator

package operator;

/ * * *@ProjectName: JavaSE
 * @PackageName: operator
 * @Author: zy7y
 * @Date: 2020/8/14 10:58 am *@Description: the arithmetic operator */
public class BaseOperator {
    public static void main(String[] args) {
        // CTRL + d; Copy the current line to the next line
        int a = 10;
        int b = 20;
        int c = 30;
        int d = 40;
        System.out.println(a + b);
        System.out.println(c - b);
        System.out.println(b * d);
        System.out.println(d / a);
      	// Take remainder: modular operation
        System.out.println(c % a);
        
        // Automatic upgrade
        double e = 23;
        System.out.println(e + a); // The result type is automatically upgraded to double}}Copy the code

Increment and decrement operators

package operator;

/ * * *@ProjectName: JavaSE
 * @PackageName: operator
 * @Author: zy7y
 * @Date: 2020/8/14 11:07 am *@Description: Autoincrement, autodecrement */
public class SelfCalculation {
    public static void main(String[] args) {
        int intValue = 3;

        / / since the increase
        int selfCalculation = intValue++; // intValue = intValue + 1, set the value first, and then execute intValue = intValue + 1
        System.out.println(selfCalculation); / / 3

        int intValue1 = 3;
        int selfCalculation1 = ++intValue1; // intValue = intValue + 1;
        System.out.println(selfCalculation1); / / 4

        / / the decrement
        System.out.println(intValue); / / 4
        selfCalculation = intValue--;
        System.out.println(selfCalculation); / / 4

        System.out.println(intValue1); / / 4
        selfCalculation1 = --intValue1;
        System.out.println(selfCalculation1); / / 3

        // The power operation
        System.out.println(Math.pow(2.3)); }}Copy the code

Logical operator

package operator;

/ * * *@ProjectName: JavaSE
 * @PackageName: operator
 * @Author: zy7y
 * @Date: 2020/8/14 11:16 am *@Description: logical operator */
public class LogicalOperators {
    public static void main(String[] args) {
        boolean booleanTrue = true;
        boolean booleanFalse = false;

        // And: &&, both values are true, the result is true
        System.out.println(booleanTrue && booleanFalse); // false

        // or operation; If one of the two variables is true, the result is true
        System.out.println(booleanFalse || booleanTrue); // true

        // non-arithmetic; If it's true, it's false, if it's false, it's trueSystem.out.println(! (booleanTrue || booleanFalse));// false}}Copy the code

An operator

package operator;

/ * * *@ProjectName: JavaSE
 * @PackageName: operator
 * @Author: zy7y
 * @Date: 2020/8/14 11:23 am *@Description: bit operator; Binary uses */
public class BitOperation {
    public static void main(String[] args){
        * * A/B = = 0011, 1100 * 0000 * 1101 * & and | or, ^ or, to take the * A & B: if the two are 1 to 1 or 0, 0000, 1100 * A | B: If one digit is 1, the result is 1, 0011 1101 * A ^ B: if they are both 0, otherwise, 0011 0001 * ~B: If they are 0, the value becomes 1, and the value becomes 0:1111 0010 * * << : * 2 * >> : / 2 * */
        0000 0001:1 in decimal; 0000 0010:2 in decimal; 0000 0100:4 in decimal; 0000 1000 8
        // Convert to base 2; Move 2 bits to the right: 0000 0010
        System.out.println(8 >> 2); / / 2
        // Convert to base 2; 0000 1000 2 bits to the left: 0010 0000
        System.out.println(8 << 2); / / 16}}Copy the code

Ternary operator

package operator;

/ * * *@ProjectName: JavaSE
 * @PackageName: operator
 * @Author: zy7y
 * @Date: 2020/8/14 11:41 am *@Description: ternary operator; The syntax x? y :z; Expression? True: */ is executed if false
public class TernaryOperation {
    public static void main(String[] args) {
        int score = 50;
        String type = score < 60 ? "Fail" : "Pass"; System.out.println(type); }}Copy the code

Package mechanism

Naming: usually use company domain name inversion; com.zy7y.cnblogs

// Import all classes in the package (.class file)
import com.zy7y.cnblogs.operator.*;
Copy the code

JavaDoc generates documentation

javadoc -encoding UTF-8 -charset UTF-8 Variable.java 
Copy the code

Idea generation Javadoc:blog.csdn.net/cai45469259…