A small summary of the first Java

Source: Internet
Author: User

What are the common annotations in 1.Java and what are the syntax?

1) Single-line comment with//indicates that the compiler sees//ignores the line//after the text
2) Multiple lines of comments/*/* indicates that the compiler will look for the next */, ignoring the text between/*/* when it sees/*.
3) document comments are written in/** * *, which is a Java-specific note, which can be parsed by the tool Javadoc provided by the JDK, generating a set of documentation for the program, which is represented in the form of a Web page file.

1) Single-line comment. The content of the comment

2) Multiple lines of comments. /* Contents of comments */

3) Documentation comments. /** the contents of the comment */

What are the 2.java common operators?

1) arithmetic operator: +,-,*,/,%,++,--

2) relational operator: equals (= =), not equal to (! =), greater than (>), greater than or equal (>=), less than (<), less than or equal (<=)

3) Logical operators: Logic and (&&), logic or (| | ), logical non (!)

What are the basic data types for 3.java?

BYTE shape short shaped int integer type long length integer Boolean boolean type
char character type (single character) float single-precision floating point double double-precision floating-point type

4 Please write the syntax and execution flow of 3 if selection structure

I. BASIC IF structure:
if (judging condition) {
Code Block 1
}else{
Code Block 2
}
First, if the condition in the IF () is true, code block 1 is executed, and if False then the code block in else is executed 2

Three. Multiplicity:
if (judging condition 1) {
Code Block 1
}else if (judging condition 2) {
Code Block 2
}else{
Code block 3
}
1) First judge if the condition in the IF () is true to execute code block 1
2) Continue execution if not satisfied else-if continue to judge if true to execute code block 2
3) Execute code block 3 if judging condition 1 and judging condition 2 is false

Four. Nesting:
if (judging condition 1) {
Code Block 1
if (judging condition 2) {
Code Block 2
}else{
Code block 3
}
}else{
Code Block 4
}
1) First judge the condition of the outermost if 1 if true to execute code block 1,
2) then judge the inside if the judgment condition 2 if true to execute code block 2 if False, code block 3
3) If the judging condition in the outermost if 1 is true directly executes the code block 4

5. Write out the syntax of the switch selection structure and the execution process

switch (expression) {
CASE constant 1:
code block 1;
Break
Case constant 2:
code block 2;
Break
......
Default
code block N;
Break
}

1) First calculate and get the value of the expression or variable in parentheses after the switch, and then compare the order of the results with the constants after each case, and when they are equal, execute the code in the block.
2) When a break is encountered, jump out of the switch selection structure and execute the code after switch selection
3) If there is no one case after the constant is equal to the value in the parentheses after the switch, execute the code in the default block at the end of the switch

6. Please write out while do-while syntax and features

1) Syntax:
while (loop condition) {
Looping operations
}
do{
Looping operations
}while (cyclic conditions);

2) Features:
While loop structure features:
Judge first, then execute
While loop structure if the first time the loop condition is not satisfied, it will jump out of the loop, the loop operation will not be executed again

Do-while Cycle Structure Features:
Execute first, then judge
Do-while loop structure, loop operation at least once

7. Please write out the syntax for the For loop and the execution process

Grammar:
for (expression 1; expression 2; expression 3) {
Loop body
}

Execution process:
(1) Perform initial judgment
(2) to determine the cyclic conditions
(3) Judging results based on cyclic conditions
> If True, the loop body is executed
> If False, exits the loop
(4) Execute iteration part, change value of cyclic variable
(5) Repeat "condition"---loop operation--Change variable value--condition judgment ... "until you exit the FOR loop structure

8. Please write out the basic syntax of the array, and the basic elements

Grammar:
1) data type [] Array name = new data type [array length]
2) data type [] Array name = new data type []{value 1, value 2, ... Value n};
Basic elements:
(1) Identifier:
As with variables, in computers, arrays also have a name, called an identifier, that distinguishes between different arrays
(2) Array elements:
When given an array of names, which are arrays identifiers, you want to store the data in the array, which is called an array element
(3) Array subscript:
In order to get the elements of the array correctly in the array, they need to be numbered so that the computer can access it, and this number is called the array subscript.
(4) Element type:
The array elements stored in the array should be of the same data type

9. How to set ascending descending order of arrays

Method One:
1) Use Arrays.sort (array name); sort the array ascending
2) in ascending order with syntax, the output is inverted, descending
Method Two:
By comparing each element of an array of loops, a larger value moves backward, compares and moves backward, and sorts in ascending order. Descending sort instead

10. How do I find the maximum and minimum values for an array? Please write your ideas?

1) Define a variable and initialize it to any of the elements in the array.
2) by the judgment statement within the loop structure, each element in the array is compared with the previously defined variable, if an element in the array is larger than the variable, the value is assigned to the variable, the maximum value is obtained, the minimum value is reversed

11. How do I think of the array episode element? Please write your thoughts.

1) define an array of length +1 for the original array
2) Assign the value of the original array to the new array
3) Find the insertion position of the new array
4) Use the loop structure to move the element back (backward, assign the previous bit to the next, until the position to be inserted) to empty the position to be inserted
5) Assign a value to the position to be inserted (empty)

12. Double for loop syntax, and its characteristics

Grammar:
for (expression 1; expression 2; expression 3) {
Structural body
for (expression 1; expression 2; expression 3) {
Structural body
}
}
Features: An external loop executes once and the inner loop executes a circle

What are the uses of 13.break and continue respectively?

1) Break: Force the end of this layer loop without affecting the outer loop
2) Continue: End this cycle in advance and continue with the next cycle without affecting the number of cycles

14. Write out the relationship between classes and objects

The relationship between a class and an object is like the relationship between a mold and a casting, and the instantiation of a class is the object, and the abstraction of a class object is the classes. Class describes a set of objects that have the same attributes (attributes) and the same behavior (methods).
15. Please write out the difference between the member variable and the local variable.
1) different positions in the class: member variables: Outside the method in the class. Local variables: In a method definition or on a method declaration.
2) The location in memory is different: member variable: in heap memory. Local variables: in stack memory.
3) Different life cycles: member variables: As objects are created, they disappear as objects disappear. Local variables: As the method is called, it disappears as the method's call is complete.
4) Initialization values are different: member variables: There are default values initialized. Local variables: No default values are initialized and must be defined, assigned, before they can be used.
※ The local variable name can be the same as the member variable name, when used in the method, the nearest principle is adopted.
16. How do I define the properties and methods of a class? How to use the properties and methods of a class
Defined:
/**
* This is the manager class
*/
public class Manager {
String username= "Zhang San";//defines a property of the manager class
String password=0000; Defines a property that defines the manager class
Public String toString () {//a method in class
Structural body
Return "Administrator information is:" +username+ "\ T" +password;//use the Username property of the manager class
}
}
Use:
1) Defining classes: Using the keyword class
2) Create the object of the class: Use the keyword new
3) Use the properties and methods of the class: use "." Operator
What are the uses of 17.return? There are two common functions of return:
One is the keyword used to return the parameter, and if a method with a return value is executed, it needs to return a parameter.
Example: public string FunctionTest () {
String a = "abc";
return A;
}
Then this method is called to return a string with the value ABC, string result = FunctionTest ();
The second usage is that the code executes here to terminate.
For example, when the code executes to a certain place there will be several results, and then one of the results can not execute the subsequent code, when there is a return to terminate the subsequent code execution.

18. Would you describe the idea of object-oriented programming?

1) Object-oriented is an emerging program design method, or it is a new programming paradigm, its basic idea is to use objects, classes, inheritance, encapsulation, messages and other basic concepts to program design.
2 It is from the real world objective things (i.e. objects) to construct the software system, and in the system structure as far as possible the use of human natural thinking, emphasizing directly in the problem domain (real world) things as the center to think about problems, understanding problems, and according to the nature of these things, They are represented abstractly as objects in the system, as the basic constituent units of the system (rather than being used in relation to things in the real world, and have no other concept of corresponding relationships to construct the system). This allows the system to directly map the problem domain and maintain the original appearance of things and their interrelationships in the problem domain.
3) Object-oriented is a kind of thought, is our way of thinking about things, usually shows that we will solve the problem by the process, or to abstract the problem into an object to solve it. In many cases, we will unconsciously follow the process to solve it, rather than consider to solve the problem of abstraction as an object to solve it.

19. What issues should you be aware of when calling the class's parameter method?

1) Calling the parameter method is the same as calling the parameterless method, but you must pass in the value of the actual parameter when calling the parameter method.
2) Define the method and call the method when the parameters are called formal parameters and actual parameters (formal parameter and argument).
3) The purpose of the formal parameter is to define the number and type of parameters that the method needs to pass in. Arguments are the actual values that are passed to the method processing.
4) You need to be aware of instantiating an object, calling a method, and the type, quantity, and order of the arguments corresponding to the parameter one by one.

20. How do you write string strings, and how do you use them?

1). Length () string

2). CharAt () intercepts a character

3). Equals () and = =
The Equals () method compares the characters in a string object, and the = = operator Compares whether two objects refer to the same instance.

4). IndexOf () and LastIndexOf ()
IndexOf () finds the first occurrence of a character or substring.
LastIndexOf () find the character or substring that is the last occurrence

5). substring () There are two forms of it
The first is: String substring (int startIndex) extracts the characters after the StartIndex subscript

The second is: String substring (int startindex,int endIndex) extracts the characters of StartIndex subscript to EndIndex (startIndex subscript starts from 0, endIndex subscript starts from 1);

6). Concat () Connect two strings

7). Trim () Remove the start and end spaces

8). Convert toLowerCase () to lowercase

9). Convert toUpperCase () to uppercase

). CompareTo () and comparetoignorecase () compare strings

ONE). public int IndexOf (string str,int fromIndex);//start retrieving Str from the first fromIndex character of the string

What is the difference between 21.== and equals?

1) = = Compare the memory address of the two value
2) The Equals method compares the actual values of both

22. How do I use StringBuffer for string stitching, please write code?

Call append () to connect a string representation of any type of data to the end of the called StringBuffer object.
Example: int a=42;
StringBuffer sb=new StringBuffer (40);
String s=sb.append ("a="). Append (a). Append ("!"). ToString ();

A small summary of the first Java

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.