_java Basic arrangement of notes

Source: Internet
Author: User
Tags arithmetic arithmetic operators case statement change settings clear screen logical operators naming convention java se

Computer Computing Capacity (CPU) Silicon storage capacity (HDD)1. Human logic2. Computer machine code (001100101010) low-level language (100) Intermediate language (easy language C/c++) high-level language (C # java) people please output hello. net php java c c++C # vb.,......3. Java language Components Java SE Desktop application development Java EE Enterprise Application development Web site Java Me mobile tablet and other mobile project development Jdk:java Program development environment, Java language Software Development Kit, mainly for mobile devices, embedded devices on the JAV A application JRE: runtime, including Jar package, JVM. A collection of environments necessary to run a Java program, including the JVM standard implementation and the Java Core Class library JVM: A timely compiler, a virtual machine6. Development step A) write I.    Create a source file with a suffix named. java. c) Compile I. Download JDK version recommended for use with 1.7.x 1.8.x corresponds to 32/64 of the computerII. Install (check JDK/bin/whether to include Java.exe and javac.exe Two execution commands) Iii. Configure the right mouse button to click on the computer--Properties--Change settings--Advanced--Environment Variables1. Variable 1 Name: Java_home value: Find the path to the installed JDK2. Variable 2 Name: Path value: Locate the directory path IV of the bin in the installed JDK.    The cmd operation jumps to the source file where the folder is compiled with the full name of the Javac file and gets a machine code with the suffix named. class executable C) running I. The warning warning in the path to the. class file under the DOS Operation command does not affect compilation and run can optimize error syntax error compilation period cannot get. class file exception exception Runtime DOS command windows-Daddy (Dos)1. Run2. Drive letter Jump Instruction Drive letter name: Enter3. Folder Jump instruction CD folder name CD: Go back to the top level directory CD/returns the drive letter directory4. View files in the current directory dir5. Clear screen CLS Note: There are different encoding methods used in the program for Chinese and English language code: GBK/gb2312 English: ISO-8859-1International Code: UTF-8d) In addition to the string (text information) special content escape character: (\) placed in "", you can print the next character content of the conversion \ n line break \ t tab stop produces 8 English words spaces the indentation E) code Comments (specifications) on the real code of the interpretation Sentence does not participate in compiling and running a single line comment//Multi-line comments/*                 * */Documentation Notes:/*** @author Author * @param parameters *@returnreturn value*/2. Interactive a) Output Print statement B) receive input pause c) Save data Bad way: logical bad way physical bad way3. Memory a) memory==Hotel B) storage unit (type)==Room (type) c) data==the tenant variable uses a data type numeric integer after the three-step declaration is first declared and then evaluatedbyteByte type can only save 0 or 1 ShortintThe maximum value is 232-1Longdecimalfloat: Single-precision floating-point number, when value is assigned and F is addedDouble: Double-precision floating-point number non-numeric characterChar: Writes the data in ' when assigning a value to a variable, and char can only be used for addition and subtraction operations, and a string that converts the data into ASCII after it is assigned to a variable: writes the data in "" in string str="ABC"; Where the string "abc" is stored in the string pool variable name str opens up a space to hold the string address for the accepted string is also a mandatory space to open upNew: A flag that refers to a data type that forces a memory space to receive input from the user from the console:1. Borrow the tool from the system:ImportJava.util.Scanner;2. Apply for the tool and take a separate name for the tool: Scanner input=NewScanner (system.in);3. Specific use:intnum=input.nextint (); or char si=input.next (). CharAt (0); indicates that the first byte system agrees to random number:1. Borrow the tool from the system:ImportJava.util.Random;2. Apply for tools: and take individual names for tools: Random ran=NewRandom ();3. Specific use:intNum=ran.nextint (9) +1; represented from 1-9 randomly produces a number in fixed format output system current time:1. Borrow the tool from the system:ImportJava.util.Date;ImportJava.text.SimpleDateFormat2. Apply for tools: and take individual names for the tool: Date da=NewDate ();3. Set the time format: SimpleDateFormat fo=NewSimpleDateFormat ("yyyy-mm-dd Hh:mm.ss.SSS ");4. Specific use: System.out.println (Fo.format (DA));5. Leap year Calculation: year%4==0&&year%100!=0| | Year%400==0; split string and convert1. Borrow the tool from the system:ImportJava.util.Scanner;2. Apply for the tool and take a separate name for the tool: Scanner input=NewScanner (system.in);3. Specific use: String date=Input.next ();4. Split operation: string[] Strs=date.split ("-");5. Convert the split character to an integer type:intYear=integer.parseint (strs[0]);intMouth=integer.parseint (strs[1]);intDay=integer.parseint (strs[2]); JDK1.8 after the version to do the string split, the first is a space, cannot be converted to an int, to skip the number of decimal places after the retention point:1. To borrow a tool from the system:ImportJava.text.DecimalFormat;2. Apply for the tool and take the individual name for the tool: DecimalFormat df=NewDecimalFormat (##### #0.00);(This format is reserved after two bits)3. Specific use: Df.format (3.333333) array Sorting:1. Borrow the tool from the system:Importjava.util.Arrays;2. Specific use: Arrays.sort (array name); Ascending can only sort on numeric types. CompareTo. (): String comparison, comparison, the longer the length, the larger the value, the comparison is ASCLL code valueTry{ }Catch(Exception ex) {} exception handling variable declaration requires adherence to Java's established rules and specifications (variable name) Rules 1 First character letter _ $ Other character Letter _ $ number Rule 2 keyword: Public、Static, void, etc. reserved words:NULL、true, goto and other variable names must not conflict with the System keyword Specification 1. The name of a variable in Java follows the Hump nomenclature (Camel): The first character of the first word lowercase, the first character of each word is capitalized, the variable name declared in the other lowercase specification 2.java has a certain meaning: student age stuage, teacher name Teaname scope:byte< Short<int<Long<float<DoubleData type conversions: Automatic conversions: From low to high, data types are compatible; cast: loss of precision; Syntax:intTemp= ( Short) 30.33; integer: Except 10 go to the bottom, modulo 10 take the difference between the lowest and the non-numeric: Can do the difference between arithmetic and non-integral: whether there are decimal operators: arithmetic operators:+ 、-、 *,/,%"+"There are two meanings: the symbol is a numeric type of data, it represents the addition operator symbol on one side or even on both sides of the string, it represents the connector"%": Only and integer collocation relational operators:>, <, >=, <=, = =,! =logical operators:&&, | | 、!、 &, | || and | differences: | |the previous condition is established to determine the result, then the latter condition is not executed|the first condition of the establishment can determine the outcome, still execute after a condition&& and &the difference is the same as the Boolean value: is the result priority of the relational operation logical operation: Highest priority: parenthesis () Lowest Priority: assignment operator=other priority levels:! > Arithmetic operators > Relational Operators >&&>| |the increment and decrement and the precedence of other operators depend on the position of the symbol:++i>1: First self-increment after comparison I++>: First compare after self -increment 1:num+ + or + +num Self-increment any number: num+=5comparison: equals: Compare string contents, compare case-sensitive usage: s1.equals ("Baiyun")==: Compare memory address equalsignorecase compare character contents, and case-insensitive statement: If condition:if(condition) {};if(condition) {}Else{} Where else depends on if the condition in the if existence should be the first to write the argument, then write the number "if(i>3) {} ", otherwise an error will occur"if(3<i) {} "If the condition is encountered greater than or equal to and less than equals should be written first> or <, and then write the equals sign "if(i>=3) {} ", otherwise an error will occur"if(i=>3) {} "multiple if:if(Condition 1) {    }Else if(Condition 2) {    }Else if(Condition 3) {   }Else{The other condition executes the statement} nested if:if(condition 1) {if(Condition 2) {}Else{   }            }Else{if(Condition 2) {}Else{}}switch Select:Switch(String,byte、 Short、int、Char){         Casecorresponding value: Operation statement; Break; Casecorresponding value: Operation statement; Break; default: operation statement; break; The loop structure: used to solve the recurring operation cycle condition: there must be a variable exists; The variable declares the starting point in the loop (the loop variable assigns the initial value) the change (cyclic variable) end point (cyclic conditional expression Loop operation: Change the variable loop: while() {}: After judgment, execute at least 0 times for the number of cycles that are not fixed Do{} while(): After the execution of judgment, at least 1 times, the loop in vitro declaration, the circulation body assignment, for the number of times not fixed cycle for() {}: After the judgment is executed, for loops with a clear loop, the two semicolons in the parentheses must be present, the expression can be defaulted, and the last expression can be i+=2There can be two variables when assigning the initial value of a variable in the for parenthesis, but when the loop variable is changed, two variables should also participate in the FOR loop clause, which can be omitted, but cannot cause a dead loop. Hit Mark:1. Define a Boolean value:Booleanboo=true;2. Change the Boolean value where needed: boo=Fals;3. The judgment operation uses the tag array:1. Declaring an array:int[] A; 2. Allocate space: a=New int[5]; Default assigned default value3. Assignment: A[0]=8; 4. Processing data: a[0]=a[0]*10;int[] Default value is 0Double[] Default value is 0.0Char[] Default value is NULL character string[] default value is nullBoolean[] The default value is false to declare the array in the way:1.int[] i=New int[5]; int[0]=5; 2.int[] i={1,2,3,4,5}; 3.int[] i=New int[]{1,2,3,4,5}; The disadvantage of the number of variables saved is that the amount of data stored in a finite array can be controlled, fixed in length, inflexible in type, and uniformly changing the size of the original array:int[] num=New int[5]; Num=New int[6]; Num stores the first element address above method The original data will lose data common operations: Add, delete, change, check backup array data:int[] temp=scores; Assigns the address of the original array to a newly declared variable bubble sort: N numbers to sort, two phases smaller by the front outer loop n-1, Inner loop n-1-Ijava Data type: base data type (9): Stored value, Short、int、Long、Char, Flaot,Double、byte、enum、Booleanreference data type (countless): storage address type, Stringenum: Enumeration that enumerates the value types and range of values for the selection of string space stack method pool constant pool static pool string pool: Non-volatile, recyclable, new note: System.out.println () and System.out.print () Do not: The former, the output after the line, the latter, the output is not wrapped, the latter () must have content, or is a useless nonsense, the former even if there is no content within (), the statement also has a line-wrapping operation. The public-decorated class must have the same name as the filename the main function does not return a value, so add void "." The front is generally class, the first letter of the class to uppercase code block Each statement end must be used; for the data to be printed must contain content variables: must follow three steps: first declaration, re-assignment, after use. Variable name can be used: The letter _ $, in addition to the first letter can also be used with a numeric variable name cannot repeat int cannot be automatically converted to a CHAR switch statement: Each case statement ends with a break, otherwise there will be a cross effect, the subsequent output statement will be executed ; and the constants after the case cannot be duplicated; The default is usually placed after the case and can be omitted; The value expressed in the parentheses after the switch must be an integral type (int、byte、Char、 Shortthe character type (String) is added after JDK1.8;default: There is no limit to the position, use switch through the effect of the time to adjust the location of the computer can only handle a type of complete expression name: Java package name consists of lowercase words; no special characters, "." The names that are available but do not show the start and end classes must start with a capital letter and the other letters in the word are lowercase, and if the class name consists of multiple words, the first word of each word should begin with a lowercase letter. The next word starts with a capital letter and the name of the constant should be capitalized, and indicates the full meaning of the constant. If a constant name consists of multiple words, you should use underscores to split the naming conventions of these word variables with the same naming convention as the method, and to avoid confusion when reading the program, make the name of the variable as meaningful as possible if the variable name is a single word while the loop parentheses exist intI I++>0 of the situation is the first judgment, the operation is completed and then self-increment continue can only be used in the loop, skipping the loop in the back of the statement, the next loop break out of the loop after the execution of the statement; switch and loop usereturnterminate the program immediately without executing any code Package: Claims for packagesImportGuide Packageif(num%==0) System.out.println ("even");ElseSystem.out.println ("odd"); Can be used when there is only one statement inside, omitting the {} ternary operation:intNUM=2&GT;1?10:20 Replacement if-Elsevariable Name: the alias of memory address, avoids the difficult to remember the address of the variable name can not be used with the loop consolidation; The array name may be consolidated with the circular name using NULL to represent the empty address objiect[] obj=NewObject[5]; All the data can be installed, the more generalization of the type, the more powerful, the more troublesome to use. Length gets the length of the data, the value of the number is a property, the length of the string is the method, and the string array is used. LENGTHGC: garbage collection Mechanism, Has hysteresis and timeliness the class must be declared with public in Java, and the Java class is not required to have a finalize () method for the main (): garbage collection mechanism, which forces the free space to inherit from the object class, freeing the objects resource

_java Basic arrangement of notes

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.