Basic Java language knowledge

Source: Internet
Author: User
Tags arithmetic arithmetic operators binary to decimal bitwise bitwise operators logical operators naming convention

  First, what is a computer

Based on Baidu Encyclopedia

  1. Introduction

Computer (computer), commonly known as computers, is a modern computer for high-speed computing, can be calculated numerically, and can be logical calculation, but also has memory function. is able to operate according to the program, automatic, high-speed processing of massive data of modern intelligent electronic equipment.

  2. Composition

A computer is made up of hardware systems (hardware system) and software systems (software system).

The hardware unit of traditional computer system can be divided into input unit, output unit, arithmetic logic Unit, control Unit and Memory unit, in which arithmetic logic Unit and control unit collectively referred to Central processing Unit (center processing UNIT,CPU) hardware system: 1), Power 2) Motherboard 3) CPU 4) Memory 5) hard 6) sound card 7) graphics 8) Modem 9) optical drive 10) Monitor 11) keyboard 12) mouse 13) speaker 14) printer 15) video device 16) flash drive 17) mobile memory card and card reader

Software system:

      • System software
        • Operating system--a. Processor management, B. Job Management, c. Memory management, D. Equipment management, E. Document management
        • Language processing program (translator): Two kinds of translation methods, interpretation, compilation
        • Service Program
        • Database management Program
      • Application software

  Ii. Overview of the Java language

  founder : James Gosling

  Java language features : simplicity, interpretive, object-oriented, high performance, distributed processing, multi-threading, robustness, dynamics, structural neutrality, security, open source, cross-platform

  Java language Cross-platform principle : Install the Java Virtual machine (JVM Java VM) on the operating system that needs to run the Java application, the JVM is responsible for the Java program running in the system

  Overview of JRE and JDK :

What is the core class library required for JRE:JVM + Java programs, and so on. If you run a well-developed Java program, you only need to install the JRE in your computer

What is the development tool for Jdk:jre+java

  JDK installation : 1. Download the corresponding version http://www.oracle.com 2. Installation, the process of selecting the path, do not have Chinese or special symbols such as Space 3. Configure the Java_home, corresponding to the installation path, modify the path, Corresponds to the bin directory in the JDK installation directory.

  the difference between path and classpath : The 1.path configuration is executable file. exe, which can be configured to access the Java class file under path path under different drive characters under the executable 2.classpath configuration. Class

  Comment Overview and its classification : 1. Single-line comment//Multiline Comment/* * * * Text Comment/** */2. Comment Function: Explain the program, help debug error

  Keywords are outlined and used : 1. Keywords are words that are given a specific meaning by the Java language 2. Keyword features: the letters that make up the keywords are all lowercase 3. Common keywords: public static void Class 4. Keyword considerations: Goto and Const exist as reserved words and are not currently used

  Overview and composition rules for identifiers :

1. An identifier is a sequence of characters used to name a class, interface, method, variable, etc.

2. Rules for the composition of identifiers: English uppercase and lowercase letters, numeric characters, $ and _

3. Identifier considerations: You cannot use keywords, you cannot start with a number

4. Common naming conventions: see Names and meanings

Package-All letters lowercase, domain name inverted

Class or interface-the first letter of a word capitalized, multiple words hump logo

method or variable-one word all lowercase, multiple words capitalized from the first letter of the second word

Constant-a word with all letters capitalized, multiple words capitalized in all letters, underlined to distinguish each word

  Overview and use of constants :

String constants: Content identified by double quotation marks

Integer constants: All integers

Decimal constants: All decimals

Character constants: The contents identified by single quotation marks, and can only hold a single number, letter or symbol

Boolean constant: True, False

NULL constant: null

  in-system :

1byte=8bit 1k=1024b 1m=1024k 1g=1024m ...

  the representation of different binary data in Java :

Binary number: consists of 0, 1, front plus 0b

Octal number: Consists of 0,1...7, plus 0 in front

Decimal: 0 ... 9 composition, front non-zero

Hex: By 0,1...9,a,b,c,d,e,f, Front plus 0x

  convert any binary to decimal number :

Coefficients: data on each one

Cardinality: X-Binary, cardinality is X

Right: On the right, starting from 0, the number on the corresponding bit is the right of that bit

Result: The value of each coefficient * (cardinality weight) is accumulated

  decimal-to-arbitrary conversion: In addition to the accumulation of the remainder

  Original code anti-code complement : Inside the computer, all the operations are in the form of two-complement

The original anti-complement of a positive number is the same.

The inverse of a negative number is the bit-wise negation of the original code (except for the sign bit)

The complement of negative numbers is the inverse of the code plus 1.

  Overview and format of variables:

    Variable definition Format: Data type variable name = variable value;

  Overview and classification of data types :

Data type classification in Java: Base data type, reference data type

Basic data type classification (four types of eight):

Integer type:

Byte: occupies one byte -128~127

Short: occupies two bytes -2^15~2^15-1

INT: accounted for four bytes -2^31~2^31-1

Long: occupies eight bytes -2^63~2^63-1

      

Float float is two bytes -3.403e38~3.403e38 double is four bytes -1.798e308~1.798e308 character char two-byte 0~65535 BOOL Boolean Boolean is theoretically a one-eighth-byte define variables for different data types: integer type data default: int type decimal type data default type: Double type definition float type data plus f: example: float f = 1.2F define long type of data followed by l:long L = 2222222222L (uppercase) Considerations for using Variables: scope: The same zone cannot use the same variable name to initialize the value problem: Local variables must be assigned before they are used implicit conversion of data type conversions: Conversion rules for data types in Java: Data types with a small range of values are evaluated with large data types, and small data types are first promoted to large, with the following examples: Byte type +int type: Byte type data is first converted to int type data, then the operation case:          int a = 10;          byte B = 20; b = a + B; possible loss of precision, the value of A + B is an int type and B is the format of the type of byte cast: b = (byte) (A + B); character and string participation operations: System.out.println (' a ');  Output character type data ' a ' System.out.println (' a ' + 1); The character data ' a ' is converted to int type 97 and then added with 1, resulting in a 98 ASCII table of three values to remember: ' 0 ' x ' a ' x ' a ' 97 string data with the rest of the data   Together, the new string System.out.println ("Hello" + ' a ' + 1) is merged directly into the form;  The result is "HELLOA1" System.out.println (' a ' +1+ "Hello"); The result is "98helloa1." char Data type: Char data range: 0--65535 characters in the Java language char can store a Chinese character: Each character occupies two bytes and Chinese is two bytes basic usage of arithmetic operators: The classification of operators: arithmetic operators, assignment operators, comparison (relationship or condition) operators, logical operators, bitwise operators, and Trinocular (meta) operator arithmetic operators: * +,-, *,/,%,++,--integers can only get integers, if you want decimals, you must change the data to float The number of points type/gets the quotient of the division operation,% gets the remainder of the division operation% Operator: When the left absolute value is less than the right absolute, the result is left; the symbol for the result of the% operator is only related to the left, not to the right. the use of arithmetic operators + + and--:+ +: Self-added. The original data is +1-: self-reduction.    1 of the original data is placed in front of the operand, self-increment or decrement, and then participate in the operation. After the operand, it participates in the operation, then increases or is self-reduced. basic usage of assignment operators: Basic Assignment operator =: Assigns the data to the right to the left extension assignment operator: +=,-=,*=,/=,%= basic usage of relational operators and their considerations: relational operator (comparison operator, conditional operator): ==,!= (not equal to), >,>=,<,<= result is Boolean type basic usage of logical operators: The difference between && and &? && has short circuit effect. False on the left, not on the right (the result is false) & whether the left is false or true, the right side will execute | |    and | The difference? || Has a short-circuit effect. Left is true, right does not execute (result is true) | Whether the left is false or true, the right side will execute basic usage of bitwise operators: Characteristics of the bitwise XOR operator and its characteristics: one data is different to another data bit or two times, the number itself does not change the interview question: please implement the exchange of two integer variables if a = @ b = # a = a ^ B = @ ^ # b = a ^ b = @ ^ # ^ # = @ A = a ^ b = @ ^ # ^ @ = # End result: b = @ a = # <<: Left      Move left highest bit discarded, 0 >&gt on the right;: Right shift the highest bit is 0, the left side is 0; the highest is 1, the left is 1 >>>: Unsigned right shift whether the highest bit is 0 or 1, the left side 0 case: the most efficient to calculate the results of 2 * 8 2<<3 basic usage of ternary operators: The format of the ternary operator: (relational expression)?    Expression 1: Expression 2; When the relationship expression is true, the result is an expression of 1 when the relationship expression is false and the result is an expression of 2 basic format for keyboard entry: Format: A: Guide package format: Import Java.util.Scanner;           Location: Above class.           B: Create keyboard Entry Object Format: Scanner sc = new Scanner (system.in);    C: Get data format by object: int x = Sc.nextint (); Note: No matter how many times we want the keyboard to enter data, create a keyboard entry object once Select the structure if statement format:      the first form of the IF statement: if (comparison expression) {statement body; When the comparison expression is established, the statement body is run; instead, do not run note: Comparing expressions whether simple or complex, the result must be a Boolean value if statement control of the statement body if it is a statement, curly braces can be omitted (recommended not omitted) Generally speaking: there are left curly braces There is no semicolon, there is no left brace for semicolons format of If statement 2: if (comparison expression) {statement body 1;    }else {statement body 2; When the comparison expression is set, the statement body 1 is run, whereas the statement body 2 is run. The if statement's Format 2 and ternary conversion problems:Ternary operators can be implemented using the IF statement.    Conversely when not set when the implementation of the IF statement can not be improved with ternary?    When the If statement controls an operation that is an output statement, it cannot. Why? Because the ternary operator is an operator, the operator should have a result, not an output, after the operation. format of If statement 3: if (comparison expression 1) {statement Body 1;      }else if (comparison expression 2) {statement body 2;      }else if (comparison expression 3) {statement Body 3;      } ... else {statement body n+1; } format of the Select Structure switch statement and its interpretation: switch (expression) {case value 1: statement body 1;      Break        Case Value 2: statement body 2;        Break         ... default: statement body n+1;      Break Note: The type of data that can be put in the expression: basic data type: byte short char int reference data type: Enumerates string execution order: evaluates the value of the expression first, and then matches after the case, if any, executes the corresponding Otherwise, the statement that executes the default control Considerations for choosing a structure switch statement:A:case can only be a constant, cannot be a variable, and the value after multiple case can not appear the same b:break best not to omit, will appear case penetrating c:default not necessarily put in the last, but must be the last to execute D: Meet break or big The parentheses are over. Select the difference between a struct if statement and a switch statement: What are the differences between use scenarios for switch and if statements? Switch recommends determining the fixed value when using the if suggestion to determine the interval or range circular structure Overview and the format of the for statement and its use:A: Classification of cyclic structures
For,while,do...while
B: Loop structure for statement format:
For (initialize an expression; a conditional expression; an action expression after a loop) {
Circulation body;
}
C Execution Process:
A: Execute initialization statement
B: Execute a JUDGMENT condition statement to see if its return value is TRUE or False
If true, continue execution
If False, the loop is ended
C: Execute the loop body statement;
D: An action expression after the loop is executed
E: Go back to B. Note: The FOR statement after the loop ends, the defined variables are freed, and the next statement is to be used, which needs to be redefined the format and basic use of the loop structure while statement: A: The format of a loop structure while statement: The basic format of a while loop:
while (judging condition statement) {
loop body statement;
}
Full format:
initialization statements;
while (judging condition statement) {
loop body statement;
Control condition statement;
} B: Execution process:
A: Execute initialization statement
B: Execute a JUDGMENT condition statement to see if its return value is TRUE or False
If true, continue execution
If False, the loop is ended
C: Execute the loop body statement;
D: Execute control condition statement
E: Go back to B. the format and basic use of the circular structure Do...while statement:A: The format of the circular structure Do...while statement:
do {
loop body statement;
}while (Judgment condition statement);
Full format;
initialization statements;
do {
loop body statement;
Control condition statement;
}while (Judgment condition statement);
B: Execution Process:
A: Execute initialization statement
B: Execute the loop body statement;
C: Execute control condition statement
D: Execute a Judgment condition statement to see if its return value is TRUE or False
If true, continue execution
If False, the loop is ended
E: Go back to B. the difference of circular structure of three kinds of circular statements: Three different loop statements:
The Do...while loop executes at least one loop body.
The For,while cycle must first determine whether the condition is true, and then decide whether to execute the Loop body statement. The difference between a for loop and a while loop:
If you want to continue using the variable that controls the condition after the loop is over, use the while loop, otherwise use the For loop. I don't know who to use for loop. Because variables disappear early from memory, you can improve the efficiency of memory usage. cyclic structure of the dead loop of considerations: A: Must pay attention to control the condition statement control the problem of the variable, do not lose, otherwise it is easy to die cycle.
B: Two simplest dead loop formats-default to TRUE for condition judgment
while (true) {...}
for (;;) {...} Note
' \x ' x denotes arbitrary, \ is an escape symbol, which is called a transfer character.
The position of ' \ t ' TAB key
' \ r ' carriage return
' \ n ' newline
' \ ' can print double and single quotes with escape symbols
‘\‘‘ To control a jump statement break statement:Usage Scenarios for break:
Only in switch and loop (end loop: Nearest principle) control Jump statement continue statement: Continue's usage scenario
Only in the loop To control the label of a jump statement:Label: Mark a loop to control it
Label composition rule: is actually a valid identifier control Jump Statement return statement: The role of A:return
Return
In fact, its function is not to end the loop, but to end the method.
B: Case Demo
What is the difference between return and break and continue?
Return is the End method
Break is jumping out of the loop
Continue is to terminate this cycle and continue the next cycle. method Overview and format Description: A: Why should there be a way
Improve Code reusability
B: What is a method
A block of code that completes a specific function.
C: Format of the method
Modifier returns a value type method name (parameter type argument name 1, argument type parameter Name 2 ...) {
Method body Statement;
return value;
}
D: Format description of the method
Modifier: Use public static now. We'll explain the other modifiers in more detail later.
Return value type: is the data type of the functional result.
Method Name: Conforms to the naming convention. Convenient for our call.
Parameters:
Actual parameters: is actually involved in the operation.
The formal parameter is the method definition that is used to receive the actual parameter.
Parameter type: is the data type of the parameter
Parameter name: The name of the variable
Method Body Statement: Is the code that completes the function.
Return: the End method.
Return value: Is the result of the function, which is brought to the caller by return. How to write a method
1, explicit return value type
2, clear parameter list Considerations for Methods: A: Method call (with a specific return value)
A: Call alone, generally no meaning, so not recommended.
B: The output is called, but not good enough. Because we may need to do further work on the results.
C: Assignment invocation, recommended scenario.
B: Case Demo
A: Method does not call do not execute
B: Methods and methods are lateral relationships, cannot be nested defined
C: When the method is defined, the arguments are separated by commas
D: Do not pass the data type at the time of method invocation
E: If the method has a definite return value, be sure to have return with a value method overloading Overview and basic usage: Method Overloading:
In the same class, the method name is the same, and the parameter list is different. Is independent of the return value type.
The parameter list is different:
A: Different number of parameters
B: Different parameter types
C: The order of the parameters is different (overloaded, but not in development)

    

  

  

Basic Java language knowledge

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.