Home  >  Article  >  Java  >  Regaining the basics of Java (11): Summary of three common methods of Eclipse and bean objects

Regaining the basics of Java (11): Summary of three common methods of Eclipse and bean objects

黄舟
黄舟Original
2017-01-16 09:53:481760browse

Regain the basics of java (11): Summary of three common methods of Eclipse and bean objects

1. Introduction to Eclipse

1. Eclipse is a multifunctional and powerful Java and other language development software jointly developed by IBM and OTI.

2. Installation and use of Eclipse

1. Changing the working path for the first time*Person class, used to define basic information about people*@author author*@version version informationFile|Switch Workpace

3. Common shortcut keys for Eclipse

1. Shortcut keys Ctrl + Shift + f*Get the value of the name attribute *@return the value of the name attribute*Set the value of the age attribute*@param age age & code formatting Ctrl + Shift + O&&& included Import Ctrl + F11&&&&&&& Compile and run Ctrl + d& Delete a line of code Ctrl + /&&Add/Cancel single line comment Crtl + Shift + /&Multiple Line comment (first select the code to be commented) Crtl + Shift + /& Cancel multi-line comment (first select the code to be uncommented) Generate main method: write main first and then alt + / Finally Enter to generate the output statement: write first syso then alt + / automatically generate (right-click Source menu) getter/setter method construction method

4. Documentation comments

& /**& #&*/&&/**&*//**&*/1. Stronger function: you can extract the content in the comments to generate a help document (instruction manual)

3. Write documentation comments in Java source files& a. Can only be written above (immediately next to) the class or method& b./**&*/& c. Generally, the first line is an overall introduction to the class or method

4. How to extract and generate help documentation& javadoc xxx.java -d doc

5. Breakpoint debugging

  1. Troubleshooting (logical errors)

    2. Steps a. Add breakpoints b. To debug Mode running program& c. Single-step code execution& d. Observe Variables, console and other views

6. Use of Object class

& 1. Our customized class will automatically inherit the Object class

2. The non-private methods of this class will be automatically inherited by other classes and can also be overridden

3. Functional method&&getClass(), obtain the type of an object (runtime type)&&equals(), "equality" judgment between objects (reference types)&&hashCode (), returns the hash code of the object&&toString(), returns the string representation of the object

## 7. equals method

  1. If you want to compare the values ​​of basic data types for equality, use ==

2. == does not compare the contents of variables or objects, but compares memory. Are the addresses the same

3. For basic data types, due to memory allocation, if the values ​​are the same, the memory addresses will be the same; if the memory addresses are the same, the values ​​will be the same

4. For reference data types, Due to memory allocation, if the value is the same, the memory address may not be the same; if the memory address is the same, the value must be the same

5. How to compare reference data types to see if their contents are equal? & The Object class provides a method: public boolean equals(Object o){}& s1.equals(s2)

6. When we customize the class, we need to override the Object class equals method

Regaining the basics of Java (11): Summary of three common methods of Eclipse and bean objects


##8. hashCode method

    A master :Hash& invented an algorithm that can convert a hexadecimal memory address into a number. This number is called a hash value
  1. 2. Memory addresses of two objects Different, the hash value is different, the memory address is the same, the hash value is the same

3. By overriding the hashCode method to generate a hash value based on the content, the efficiency of comparison can be improved

4. Adding attribute values

Regaining the basics of Java (11): Summary of three common methods of Eclipse and bean objects##9. toString() method

cannot be output directly An object
  1. 2. When we directly output an object, the toString() method will be automatically called
3. The string returned by the default toString() method is nothing function, so we need to rewrite

The above is the summary of the three common methods of Eclipse and bean objects. Please pay attention to the PHP Chinese website (www.php. cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn