Javase Base Rollup __java

Source: Internet
Author: User
Tags arithmetic operators function definition logical operators modulus
Write code:
1, clear demand. What I'm going to do.
2, analysis of ideas. What am I going to do? 1,2,3.
3, determine the steps. What statements, methods, and objects are used in each part of the idea.
4, code implementation. Use the specific Java language code to reflect the idea.


Four points to learn new technology:
1, what the technology is.
2, what is the feature of the Technology (use note):
3, how the technology is used. Demo
4. When will the technology be used? Test
-----------------------------------------------------------------------------------------------
One: Java Overview:
1991 Sun company James Gosling and other people began to develop the language named Oak, hope to control embedded in the cable TV Exchange box, PDA and other microprocessors;
1994 renamed the Oak Language to Java;


Three technical architectures for Java:
Javaee:java Platform Enterprise Edition, develop the application in enterprise environment, mainly for Web program development;
Javase:java Platform Standard Edition, the completion of desktop application development, is the basis of the other two;
Javame:java Platform Micro Edition, the development of electronic consumer products and embedded devices, such as mobile phone procedures;


1,jdk:java Development Kit,java's development and running environment, Java development tools and JRE.
2,jre:java Runtime Environment,java The running environment of the program, Java runs the required class library +JVM (Java Virtual machine).
3, configure environment variables: Let the Java jdk\bin directory of tools, can run in any directory, because the tool is the directory told the system, when the tool used by the system to help us find the specified directory.
Configuration of environment variables:
1): Permanent configuration mode: java_home=% installation path%\JAVA\JDK
Path=%java_home%\bin
2): Temporary configuration mode: Set path=%path%; C:\Program Files\java\jdk\bin
Features: The system defaults to the current path to find the program to execute, if not, and then go to the path set in the paths below to find.
Classpath configuration:
1): Permanent configuration mode: classpath=.; C:\;e:\
2): Temporary configuration mode: Set Classpath=. C:\;e:\


Note: When defining CLASSPATH environment variables, you need to be aware of
If you do not define an environment variable Classpath,java starts the JVM, it finds the class file to run in the current directory;
If Classpath is specified, the class file to run is found under the specified directory.
Will you also find it in the current directory. Two cases:
1): If the value of the classpath has a semicolon at the end, the running class is not found in the specific path and will be found again by default in the current directory.
2): If the value of classpath results in no semicolon, in the specific path does not find the running class, no longer the current directory to find.
Usually do not specify a semicolon, if you do not find the specified directory to run the class file, the error, so you can debug the program.


4,javac commands and Java commands do something.
You know, Java is divided into two parts: one is compilation, the other is running.
Javac: Responsible for the compiled part, when the javac is executed, the Java compiler program is started. Compiles the. java file for the specified extension. A bytecode file that the JVM can recognize is generated. That is, the class file, which is the Java running program.
Java: The part that is responsible for running. The JVM is started. Loads the class libraries required by the runtime and executes the class file.
A file to be executed must have a starting point for execution, and this starting point is the main function.
----------------------------------------------------------------------------------------------
Second: Java Syntax basics:
1, the keyword: is actually a language given a special meaning of the word.
Reserved word: In fact is not given special meaning, but prepare to use the word in the future.
2, identifiers: The names of packages, classes, methods, parameters, and variables in Java that can consist of any order of uppercase and lowercase letters, numbers, underscores (_), and dollar signs ($), but identifiers cannot begin with a number and cannot be reserved in Java.
• The following are valid identifiers:
Yourname
Your_Name
_yourname
$yourname
• The following is an illegal identifier:
Class
67.9
Hello Careers
1), numbers may not begin.
2), you cannot use keywords.
3, constant: is the data that will not change in the program.
4, variable: In fact, is a memory space, used to store constant data.
Function: Convenient for operation. Because some data are not sure. So determine the noun and storage space for the data.
Features: Variable space can be reused.
When to define variables. Define variables as long as the data is uncertain.
What elements are needed for the opening of variable space?
1, this space to store what data. The data type.
2, what is the name of this space? The name of the variable.
3, the first data of this space is what. The initialization value of the variable.
Scope and lifetime of variables:
Scope of variable:
The scope begins at the position defined by the variable and ends with the curly brace where the variable is located;
Life cycle:
The variable begins to live in memory, starting at the defined location;
The variable disappears in memory when it reaches its scope;
Data type:

1): Basic data type: Byte, short, int, long, float, double, char, Boolean
2): Reference data type: Array, class, interface.
Levels from low to High: Byte,char,short (these three peers)-->int-->float-->long-->double
Automatic type conversion: from low-level to high level, the system automatically turn;
Coercion type conversion: Under what circumstances? Assign a higher number to a lower-level variable of that number;


Operator symbol:
1), arithmetic operators.
+-*/%: Any integer modulus 2 is not 0 is 1, so as long as the change is modulus can be implemented switch operation.
+: Connectors.
++,--
2), assignment operator.
=  += -= *= /= %=
3), comparison operator.
Feature: This operator is characterized by: the result of the operation is either true or false.
4), logical operator.
& |   ^  ! && | |
logical operators except! are used to concatenate two Boolean expressions.
The result is true only if both sides are true. Otherwise it is false.
|: If both sides are false, the result is true
^: vary or: And or a little different.
The results are the same on both sides, false.
True if both sides of the result are different.
& and && differences: &: Regardless of the result on the left side, the right-hand side is involved in the operation.
&&amp: Short-circuit and, if the left is false, then the right side of the parameter and operation.
| and | | Difference: |: Both sides are operational.
|| : Short circuit or, if the left is true, then the right does not participate in the operation.
5, bitwise operator: operator used to manipulate bits.
&
Example: 129&128, "A" is a value of 129, converted to binary is 10000001, and "B" value is 128, converted to binary
Is 10000000. According to the operation law with the operator, only two digits are 1, the result is 1, you can know the result is
10000000, or 128.
|
Example: 129|128, the value of a is 129, converted to binary is 10000001, and B's value is 128, converted to binary is 10000000, according to or operators of the operation of the law, only two digits have one is 1, the result is 1, you can know the result is 10000001, That is 129.
^
For example: The 15^2 or operator XOR is represented by the symbol "^", whose operation law is: the bit of two operands, the same result is 0, and the result is 1.
Analysis of the above program section: A is a value of 15, converted to binary 1111, and B's value is 2, converted to a binary of 0010, according to the difference or the operation of the law, can be concluded that the result is 1101 or 13.


<< >> >>> (unsigned Right shift)
Practice: Efficient calculation of 2*8 = 2<<3;
5, statement.
If switch do While in for
When these statements are used.
1, when judging a fixed number of values, you can use if, you can use the switch. Switch use is recommended, and the efficiency is relatively high.
Switch (variable) {
Case value: The statement to be executed;
...
Default: the statement to execute;
}
How it works: The value of the variable in parentheses is compared to the value after the case, which is the same as the value after the case.
Executes the statement following the case, and executes the statement following the default if there is no equivalent;
Details: 1: Break can be omitted, if omitted to be carried out until the break until the break;
2): The variable in the parentheses behind the switch should be one of the four types of byte,char,short,int; +string
3: Default can be written anywhere in the switch structure; If the default statement is placed on the first line, the program will start from default until the first break occurs, regardless of whether the expression matches the value in the case.
2. When judging the range of data and getting a Boolean type of the result of the operation, use if.
3. When some statements need to be executed many times, the loop structure is used.
While and for can be interchanged.
The difference is: if you need to define the number of variable control loops. It is recommended that you use for. Because the For loop is finished, the variable is freed in memory.


Break: Action on switch, and loop statements, used to jump out, or call it an end.
When a break statement exists alone, the following do not define other statements, because the compilation fails because it is not executed. (Break and return should not be used before and after adjacent.) When the loop is nested, the break only jumps out of the current loop. To jump out of the nesting of the outer loop, as long as the loop name can be, this name is called the label.


Continue: Used only for circulation structure, continue to recycle.
Function: End this cycle and continue the next cycle. When the statement exists alone, the statement cannot be defined below and cannot be executed.


6, Function: In order to improve the reusability of code, it can be defined as a separate function, the function is embodied in the Java function. function is one embodiment.
The definition format for functions in Java:
Modifier returns the value type function name (parameter type argument 1, Parameter type form parameter 1, ...) {
Execute the statement;
return value;
}
When a function does not have a specific return value, the return value type returned is represented by the void keyword.
If the return value type of the function is void, the returns statement can omit the write, and the system will help you automatically add it.
Function of return: End Function. End Function.


How to define a function.
function is actually a function, the definition function is to implement the function, through two clear to complete:
1, clear the function of the result of the operation, in fact, is in the clear return value of this function type.
2, in the implementation of the function of the process is unknown content involved in the operation, in fact, is in the clear parameter list of this function (parameter type & number of parameters).
Functions of the function:
1), for defining functions.
2), used to encapsulate code to improve the reusability of code.
Note: Functions can only be called and cannot be defined.
Main function:
1), to ensure the independent operation of the class.
2), because it is the entrance to the program.
3), because it is being invoked by the JVM.


What is the function definition name?
A: 1, in order to mark the function, easy to call.
2, in order to use the name can be defined function, in order to increase the readability of the code.


An overload is defined as a function overload in a class if there are two or more or more than two functions with the same name, as long as the number of their arguments, or the type of the parameter is different.
How to distinguish between overloads: When the function has the same name, only the argument list is looked at. Does not matter with the return value type.


7, one-dimensional array: a container for storing data of the same type. Benefits: You can number the data in the container, starting with 0. Arrays are used to encapsulate data, which is a specific entity.
How do you represent an array in Java? Two forms of expression.
1), element type [] Variable name = new element type [number of elements];
2), element type [] Variable name = {element 1, element 2 ...} ;
3), System.arraycopy (source,0,dest,0,x): The meaning of the statement is to copy the source array from the X element starting with subscript 0 to the target array, starting at the location corresponding to the subscript 0 of the target array.
4, Arrays.sort (array name) to sort the operation, but this method is in Java.util this package, so you need to import it first

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.