Javase basics 1: Basic knowledge

Source: Internet
Author: User
Tags bitwise operators float double

------- Android training, Java training, and hope to communicate with you! ----------

I. Java implementation mechanism: 1.1 Virtual Machine Mechanism

Java virtual machine features: multithreading, dynamic connection, and exception handling.

Program compilation and execution process:. Java source program -- Java compiler -- generate bytecode file. Class -- JVM Java interpreter -- operating system.

1.2 garbage collection mechanism

The system automatically recycles memory that is no longer in use to improve security.

Ii. language basics: 1.1 data types define data Nature, value range, Storage MethodAnd the operations that can be performed. Including basic data types and reference types.

Basic Data Type: 8 Basic Types

  • Integer: byte bytes intlong
  • Float Type (real type): Float double
  • Boolean: Boolean
  • Character Type: Char
1.1.1 INTEGER:

Hexadecimal: decimal, octal, hexadecimal, Binary Conversion

Byte: 1 short: 2int: 4 long: 8

Int type.

1.1.2 floating point type

Bytes occupied: float: 4 double: 8

The floating point is double by default.

1.1.3 Boolean

Value: True. False cannot be converted to other types.

1.1.4 accept type

CHAR: 2 bytes. The characters in Java are represented by a 16-bit Unicode code.

Escape Character \

1.2 variables and constants

Variables are divided into local variables and member variables;

Constants can be declared using the final keyword. Constant identifiers are generally expressed in uppercase letters. For example, final int min = 0;

1.3 operators and expressions 1.3.1 Arithmetic Operators

Unary operator: +-++ --

Binary OPERATOR: +-*/%

1.3.2 bitwise operators

~ Non ^ exclusive OR & amp; | or & gt; right shift <left shift> & gt; 0 shifted to the right

1.3.3 Relational operators

=! ==<=> <

1.3.4 boolean operator

And & or | not! Exclusive or ^ short circuit and & short circuit or
|

1.3.5 three-object OPERATOR: expression? Expression 1: expression 21.3.6 string merging "+" 1.3.7 combination operator. For example, + = forcibly converts the value on the right to the type on the left for calculation.

Conversion between data types:

Small capacity is converted to large capacity, and the type is increased. The calculation between byte short and char is automatically converted to int type before the calculation.

Forced type conversion is required for large to small conversion, which will result in loss of precision.

Operator priority and combination sequence:

Note: unary operators such as -- ++ are left-right

System. Out. println (INT) (char) (byte)-1); the output result is 65535.

Public static void main (string [] ARGs) {final string pig = "Length: 10"; final string dog = "Length:" + pig. length (); system. out. println ("animals are equal:" + pig = dog); // output flase because the + number has a higher priority than ==}

1.4 Process Control

1.4.1 SELECT statement
(1) ifelse Statement (2) the expression after switch only accepts values of four types: byte short int char

Case statements have no order. They are executed from case and ended with break.

When the condition is met, the statement is executed until the break is met.

End with the default statement. If the default statement is placed at the end, you can skip the break.

The switch statement is not suitable for determining the range and boolean type.

// Jdk1.7 enhances the switch function

1.4.2 Loop Structure
For Loop: If the variable is only used as a loop variable, you can use for to end the for loop, then the loop variable is released. While loop: If the loop variable has other functions, you can use the while loop to define the loop variable in vitro. The variable scope defined in the loop body is valid only in the loop body.
For simple infinite loop for (;) {} while simple infinite loop while (true); accumulative thought: records the results of each change through variables, and accumulates through loops. Counter idea: records the status changes of data through variables. It is done in a loop.
Loop nesting: (large traps and small circles) 1. Print a rectangle, control the number of rows in an external loop, and control the number of columns in an internal loop.
* Tip-up: enables the inner cycle condition to change with the outer loop Variable
** Point-down: enables the inner loop variable to change with the outer loop variable.
* ** Print the 9-9 multiplication table

1.4.3 redirection statement:
Break statement: used to jump out of the switch and select the structure and loop structure, add a label to the loop, you can control the position of the loop (internal or external loop) Continue statement: Used for the loop structure, end this loop ahead of schedule. Execute the next loop and add a label to the loop to control the exclusive loop position (inner or outer loop). When break and continue exist separately, no statement is followed, compilation fails because the execution fails. After the for loop executes the continue statement, it jumps out of the loop body, executes expression 3 in the for loop, and then judges expression 2.
Method (function): When the method type is void, the Return Statement in the method body can be omitted. Urn is used to end the function. You cannot define a function in the function weight. Define functions: 1. define functions and returned results. 2. Determine whether unknown content is required for calculation (parameter type and number of parameters)

Function overload: when the functions are the same but the parameters are different, the same function name is used to indicate the function. The parameter list is used to identify which function to call. The function overload is irrelevant to the function return type.

------- Android training, Java training, and hope to communicate with you! ----------

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.