Java - new Java (note)

Franic_ wy 2022-01-26 13:51:13 阅读数:909

java new java note

One . New to Java

1.Java The file name suffix is   . java

2. When saving, the file name must be consistent with the class name ,Java The basic unit of a program : class (class)

3. stay Java There are the following ways of annotation in :
        Block annotation :/* */    Line notes ://   ( and C The way of annotation in language is the same )
        Javadoc notes :
            /**
             * @author
             * @param
             */

4. Program entry   :  The main function :main()

 5. stay Windows in java How the program compiles :
        First, make sure that the file name and class name are consistent : javac Hello.java ---> Hello.class  

6. stay Windows in java How the program works :
      java Hello[.class] ---> function Hello.class file

Be careful : stay 5. 6. Need to know in the process Windows Terminal tool entry and usage .

## Terminal tools
    win + R --> cmd
    Basic instructions
    cls  ---> clear screen Clear the screen
    dir  ---> directory List the files in the current directory
    cd   ---> change directory Toggle directory
        .   Current directory         (cd.)
        ..   Previous Directory     (cd..)
        Root switch :C: D: E: F:  ( Input the drive letter directly + The colon :  d:    e:)

Two . build Java Development ring

1. Build a writing environment
        1. Notepad
        2. recommend :vscode
        3. install :https://code.visualstudio.com/
        4. Add right click menu : perform "VsCode Right-click menu .reg"
            modify reg In file vscode Installation path for
  2. Build a terminal enhancement environment
        1.win+R -> cmd
        2. recommend :cmder
        3. install :https://cmder.net/
        4. Add right click menu :
            1. Get into cmder The installation directory
            2. Run as administrator cmder.exe
            3. Enter... In the pop-up window
            cmder.exe /register all                                                                                                           3. install JDK
        JDK: Java Development Kit
            JRE            (JDK contain JRE)
                JVM       (JRE contain JVM)
        JRE: Java Runtime Environment
        JVM: Java Virtual Machine

        1. download :https://www.oracle.com/java/technologies/downloads/#java8-windows
        2.java8->windows->x64
4. add to Java Related environment variables ( Optional )
        newly build :JAVA_HOME = C:\Program Files\Java\jdk1.8.0_151
        newly build :CLASSPATH = .
        edit :PATH = %JAVA_HOME%\bin
        Computer -> Right click in the blank space -> Advanced system setup -> senior -> environment variable
        User variables
        System variables
5. Verify the correctness of the environment installation
        use java -version

3、 ... and . The first program  

public class Hello{
/**
* can @
*/
public static void main(String[] args){
//Print Line( Output line feed ) amount to C:\n
System.out.println("Hello World");
}
}

Four . Second procedure ( The concept of a package ) 

project
    class
    package:
        class1
        class2
    package:
        class1
        class2
The full name of a class : Package name . Class name
    com.zhongbei.Angle
constraint :
1. The class name must be the same as the file name
2. The package name must match the file level / The structure is consistent
   class: com.zhongbei.Angle
   dir:   com/zhongbei/Angle.java

How to compile / function
1. Compilation is not affected , Just find the corresponding file
2. function
    java com.zhongbei.Angle
    You must switch to the top-level directory of the package :com At the same directory

package com.zhongbei;
public class Angle{
public static void main(String[] args){
System.out.println("This is main function.");
double res = sin(30);
System.out.println("sin(30) = " + res);
}
public static double sin(int angle){
double result = 0.0;
switch(angle){
case 30:
result = 0.5; break;
case 45:
result = 0.7; break;
case 60:
result = 0.8; break;
default:
break;
}
return result;
}
}

5、 ... and . The representation of numbers
    0 1
    Low level 0
    High level 1

    'a': ascii, 97
    'b'
    'c'
    'd'
    ' chinese '  unicode

1.ASCII
    'a' - 'z'   97 - 122   0x61 - 0x7A
    'A' - 'Z'   65 - 90    0x41 - 0x5A
    '0' - '9'   48 - 57    0x30 - 0x39
    '\0'        0
    "hello",'h','e','l','l','o','\0'
2. Base number
    Decimal system                   764
    Binary system      [0-1]        b1101 0111
    octal      [0-7]        0764
    Hexadecimal    [0-9A-F]     0x764

    Binary system --> Decimal system
    b0000 0001 1
    b0000 1111 15
    b0000 1011 11
    b0000 0111 7

    Decimal system --> Binary system ( except 2 Remainder reverse order )
    60/2  30  0
    30/2  15  0
    15/2  7   1
    7/2   3   1
    3/2   1   1
    1/2   0   1
    60 == b111100

    octal -> Decimal system
    0641 -> 6 * 8^2 + 4*8^1 + 1*8^0 = xxx
    octal -> Binary system (1 individual 8 Base bit == 3 individual 2 Base bit )
    0641 -> b110 100 001
    Binary system -> octal
    b010 110 110 -> 0266

    Hexadecimal -> Decimal system
    0xA38F = 10 * 16^3 + 3 * 16^2 + 8 *16^1 + 15 * 16^0
    Hexadecimal -> Binary system (1 individual 16 Base bit == 4 individual 2 Base bit )
    0xA38F = b1010 0011 1000 1111
    Binary system -> Hexadecimal binary
    b1001 1100 = 0x9C
    Hexadecimal -> octal

3. Integer representation ( A signed 、 Unsigned )
    1byte = 8bit
    b1010 0111

    unsigned:
        b0000 0000 ~ b1111 1111  0 ~ 255
    signed:
        The highest bit is the sign bit 0+  1-
        1 Sign bit + 7 Digit
    Complement operation :
        A complement to a positive number = Original code
        A negative complement = Inverse code + 1
    eg(8bit):
    3 The binary representation of :
    Original code = b0000 0011
    Complement code = b0000 0011

    -3 The binary representation of :
    Original code :1000 0011
    Inverse code :0111 1100
    Complement code :1111 1101

4. Floating point type means
    127.1234
    Scientific enumeration

    32bit: 1 Sign bit + 8 Exponential position + 23 Significant digit bit
    64bit: 1 Sign bit + 11 Exponential position + 52 Significant digit bit

copyright:author[Franic_ wy],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201261351106768.html