Java Learning-the first day

Source: Internet
Author: User
Tags bitwise bitwise operators logical operators java keywords

Start learning Java today and see [Bi Xiangdong _java Basic Video Tutorial]. Because there is no book, write notes on the blog can be forgotten and record learning mileage. At the same time I hope that the form of blogging can let oneself learn Java more motivated.

01day

1.Java Cross-platform

The main reason for the cross-platform nature of Java is the existence of a Java Virtual machine (JVM).

2.JRE and JDK

The JRE is the Java Runtime Environment, all of which is (Java Runtime Environment), and the JRE includes the Java Virtual machine and the core libraries required to run the Java program. If you want to run a Java program, install the JRE on your computer.

The JDK is the Java SDK, all spelled (Java development Kit), and the JDK is available to Java developers. This includes the tools used to develop Java programs, and also includes the JRE.

3.doc system Commands

CD into path CD. Returns the upper directory cd\ return drive letter

Dir List current directory MD Create folder kd Delete Folder

4.JDK environment variable Configuration

Java_home C:\Java\jdk1.7. 0_51     CLASSPATH%java_home%\jre\lib;      Path%java_home%\bin; 

5.hello World

Class Demo {static void main (String [] args) {System.out.println ("Hello World"); }}  

After compiling through Javac on the command line, then Java demo.class can print a Hello Wrld on the doc console.

02day

1.Java keywords

Java keywords are words that are given special meaning by the Java language.

2. Identifiers

Identifiers are names that are customized in the program, which consist of letters, numbers, and symbols. Identifiers need to conform to two rules: 1. Numbers may not be at the beginning 2. Keywords cannot be used

In order to improve the readability of the code, the name must be as meaningful as possible.

3. Code comments

Comment Line

/*

Comment Multiple lines

*/

4. Constants and variables

Constants are values that cannot be changed. Constants in Java include integer constants, decimal constants, Boolean constants, string constants, and null constants.

Variable: is the storage of uncertain data, that is, in memory to open up a space to store data.

The definition of a variable:

Variable name of data type = initialization value; eg. int i = 0;

When do I define a variable? When the data is uncertain, it is necessary to store the data to define a variable to complete the storage.

Data types in Java include: base data type (byte, short, int, long, float, double, char, Boolean) and reference data type (class, Interface, [] (array))

   

    int x=4; BYTE b =2//-128~127 short s = 30000;  3w+ long L = 4l;  float f = 2.3f;  Double d = 24.46;  char ch = ' 4 '; Boolean bo = true;    

5. Type conversion

Class  d2byte{public    static void main (string[] args)     {        byte b = 4;         B = B + 5;         B + = 5;        System.out.println (b);                b= B + 5; Compilation does not pass, here is the first by the line addition and then assignment, the sum will be converted to int by default. The int type cannot assign a byte type when assigning a value.        //b + = 5;   Compile through, where the + = operator is cast by default. 

6. String concatenation

Class Stringdemo {public static void main (string[] args) {String a = "liming";        int b = ALL; System.out.println ("Hello," +a+ "You Are" +b+ ".")    ); }}    

String data and any data using + are connected and eventually become strings. The above program will print out after running: Hello, liming you are 23.

7. Escape character: (through \ To change the meaning of the following character or symbol).

\ n: Line break.

\b: Backspace.

\ r: Press ENTER.

\ t: tab.

8. Assignment operators

+=   -=    *=    /=    %=

9. Logical operators

Logical operators are used to concatenate expressions of type Boolean

& and:& can be regarded as the number 0, in the judgment when only 0 is false

| Or: | can be seen as the number 1, in the judgment when only 1 is true

^ XOR: Summed up is that the same false and different truth.

! Non: is to take the inverse, take the anti-expression after false is true, really is false

&& Logic and: judgment is similar to &. The difference is that when you use &&, the left side appears false immediately after the judgment result, && right expression will not be judged and use & both sides of the expression are involved in the operation.

|| Logical OR: The verdict is almost like |. The difference is when using | | When the left appears true, the result is immediately determined, | | The expression on the right is not judged and used | Both sides of the expression are involved in the operation.

  

10. Bitwise operators (bitwise operations are direct to the binary number on the line operation)

<<: Shift left eg. 3<<2 =----3*2*2 = 12 The left shift is multiplied by 2 to move the number of bits to the power

The binary representation of 3:0000-0000-0000-0011-------00-0000-0000-0011--> 0000-0000-0000-1100=12 after the left-shift 2-bit complement

 

>>: Right shift eg. 3>>1 =1-3/2 = 1 Right Shift is divided by 2 to move the number of bits to the power

Binary representation of 3:0000-0000-0000-0011------1-bit 00000-0000-0000-001--> 0000-0000-0000-0001=1 after right shift

>>>: Unsigned right shift eg. 3>>>1 = 1--3/2 = 1

>>: After the right shift, the highest bit complement is determined by the top of the original data. If the highest bit is 0, the right shift is followed by a 0 complement, and if the highest bit is 1, the right shift is followed by a 1 complement

>>>: No matter what the top bit is, use 0 to fill the right after you move it.

& and arithmetic eg. 6 & 3 = 2

0000-0000-0000-0110 & 0000-0000-0000-0011-----------------------  0000-0000-0000-0010 = 2

      

|  or operation eg. 6 | 3 = 7

0000-0000-0000-0110 |  0000-0000-0000-0011----------------------------  0000-0000-0000-0111    = 7

^ xor or operation eg. 6 ^ 3 = 5

0000-0000-0000-0110 ^ 0000-0000-0000-0011----------------------------  0000-0000-0000-0101  = 5

^ XOR application: 7^4^4=7 a number of different or the same number twice or that number.

Application 1: For encryption

  

Application 2: Do not use third-party two variables for mutual

Class D2ntom {public    static void main (string[] args)     {/        *         not interchangeable with third-party two variables        */        int a = 10 , b =50;        System.out.println ("Before swapping with third-party two variables: a=" +a + ", b=" +b);        Method One                  a= a + b; b= A-b; a= A-b; System.out.println ("Without the use of third-party two variables after Exchange: a=" +a + ", b=" +B); System.out.println ("--------------------------------------------------");/* Method two * /SYSTEM.OUT.PRINTLN (" Before swapping with third-party two variables: a= "+a +", b= "+B); A = a ^ b; b = a ^ b; a = a ^ b; System.out.println ("After swapping with third-party two variables: a=" +a + ", b=" +B);}}         

~ Anti-code eg. ~ =-7

~  0000-0000-0000-0110----> All------------------------------  1111-1111-1111-1001--->  First minus repeated inverse of the integer-  0000-0000-0000-0001---> minus One
---------------------------- 1111-1111-1111-1000---> take anti----------------------------- 1000-0000-0000-0111 =-7

10. Conditional operators

(conditional expression)? Expression 1: Expression 2

If the result of the conditional expression is true, the contents of expression 1 are executed, and if the result of the conditional expression is false, the contents of expression 2 are executed.

int a=10, b; b= (a>8)? 100:200;      /* Three mesh Operator:        Benefits: Can simplify if else code        disadvantage: Because it is an operation, so the operation must be done by a result.      */    

11. Judging the structure

If statement: There are three forms of 1.if(conditional expression) {        execution statement;} 2.if(conditional expression) {        execute statement;   } else{        EXECUTE statement;} 3if(conditional expression) {        execute statement;   } else if(conditional expression) {        execute statement;} ... else{EXECUTE statement;}     

12. Select the structure-switch statement

Switch(expression) {case     value 1:    EXECUTE statement;    Break;  Case Value 2:    EXECUTE statement;    Break;  Case Value 3: EXECUTE statement; break ... case value N: Execute statement; break; Default: Execute statement; break;} /*switch features the 1.switch statement chooses only four types: there is no order between byte,short,int,char.2.case and default. Executes the first case until the default is executed without a matching case. 3. Two cases of ending the switch statement, encountering a break or execution to the end of the switch statement. 4. If the matching case or default does not have a corresponding break, then the program will continue to execute downward. Run statements that can be executed until the break is encountered or the end of the switch ends.


If and switch statements function Similarly, how to choose the specific situation?
If the exact value of the judgment is not many, and conforms to the four types of byte short int char. Although both statements are available, a switch statement is recommended because the effect is slightly higher.
In other cases, the range is judged by the interval, and the result is a Boolean type, then the if,if is used more broadly.
*/

  

 

Java Learning-the first day

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.