Learning notes on the Java Error learning method

Source: Internet
Author: User
Tags instance method

The properties of the 1.main method public static can be exchanged, but the return type must be a void type, the formal argument must be of type string[], and the name is variable.

2. View the Load class: New HelloWorld (). GetClass (). getClassLoader (). toString ().

3. In Java, procedures and functions are collectively referred to as methods, methods are divided into class methods and instance methods, and variables are divided into class variables and instance variables. Class methods can access only class variables and cannot access instance variables. Instance methods can access instance variables and class variables.

4. Any design language error: Lexical error, syntax error, run error, logic error.

5. You can use SYSTEM.OUT.PRINTLN () to check for in-method execution, but bold or other comment symbols to remove.

6. Boundary conditions need to be used to test the correctness of the method.

7. Note the use of the "= =" sign. the "= =" operator is used to compare the values of variables for equality, while equals is used to determine whether an object is the same object.

8.String and stringbuffer:string are stored as objects, StringBuffer are stored as addresses. Takes a string as a parameter, which is passed as a value, but is passed as a reference using StringBuffer as a parameter. Also, it should be noted that when assigning a value to a private variable of an object, you should use s= "inital value" instead of S=new String ("inital value"), since the latter will call the constructor each time. Generating new objects, performance is low, memory overhead is high, and meaningless.

9. Logic Operator: &,^,| Short-circuit logic operator: &&,| |.

10.length,length (), the difference between size (): The length property is for arrays, and the length () method is for strings, and the size () method is for generic collections.

11. Use the label after break to jump out of multiple loops.

Two special values for double types are set in 12.Java: Infinity and Nan.

13.javac-d is followed by a directory name, which is where you want to store the compiled class file.

14.JAVAC-CP Abc.a.one is to force the Java command to the subdirectory of the current directory of the ABC subdirectory to find the One.class class file.

15. The abstract method must end with a semicolon and the abstract method cannot use the private adornment.

16. You cannot place any access modifiers (private,public,protected) before local variables, but the final non-access modifier can be used to decorate a local variable.

17. With regard to the encapsulation of classes, the Get method can only get member variables of some basic types. For a member variable of a reference type, you can take the method of deep copy of the object.

18. The Static-modified code is loaded into memory when the class is loaded.

19.system.exit (0) means that the Java virtual machine is shut down before an exception is thrown.

20. Basic rules for method overrides:

(1) The return type and parameter list of the overridden method must exactly match the method it covers

(2) The coverage method cannot be more accessible than the method it covers

(3) The overlay method cannot throw more exceptions than the method it covers

21. Basic techniques for designing a class:

(1) To design the internal data as private: only to see, no touch.

(2) Be sure to initialize the data: The local variables are not initialized in Java, but the member variables of the class are initialized.

(3) Do not use the base data type too much in a class: if there are too many basic data types in a class, you should encapsulate multiple related base data types into one class.

(4) Not all member variables need to use the set and get methods.

(5) Use standard format for class definition:1> Public access Attributes section, package access to accessible attributes section, Private access Attribute section

2> instance method, static method, instance domain, static domain

(6) Decomposition of classes with excessive responsibilities

(7) The class name and method should be able to reflect the responsibility

22. An abstract class cannot be instantiated, so it refers to an object of a specific subclass.

23. Starting with JDK5.0, the method of overriding the superclass is marked with @override.

24.Java requires the Equals method to have the following characteristics: reflexivity, symmetry, transitivity, consistency, empty processing returns false

Content implemented within the 25.equals method:

(1) Determine if the references to two objects are the same: This==object

(2) Determine if the parameter is null: Object==null

(3) Determine if the type matches: This.getclass () ==object.getclass ()

(4) Converts an object to a type variable of the appropriate type: ClassName other= (ClassName) object

(5) Determine whether the values of each field are the same: This.name==object.name ...

26. Recommendations for design inheritance:

(1) Define common operations and member variables in the superclass

(2) Minimize the use of the protection domain protected

(3) using inheritance to implement the "is-a" relationship

(4) Do not use inheritance unless all inherited methods make sense: Holiday classes and Calendar classes should not try inheritance because the Calendar class has a way to turn holidays into non-holidays, and you should not use inheritance

(5) Do not change the expected method when overriding the method

(6) Use polymorphic rather than type information: for the following types of code, you should define the action as a method and place it in a superclass or interface of two classes, and then invoke it, using polymorphism.

1 if(x is of type 1) 2 action1 (x); 3 Else if(x is of type 2) 4 action2 (x);

27. Object cloning: The Clone () method is a protected method of the object class. The object returned by this method is independent of the object being copied.

28. The inner class is equivalent to a member variable. Therefore, an inner class can be defined in a member method, called a local inner class.

29. Reasons for using internal classes:

(1) Methods within the inner class can access all data within the defined domain of the inner class, including private data

(2) Inner classes can hide other classes in the same package

(3) When you want to define a method to parse yourself, try anonymous inner class is more convenient

Learning notes on the Java Error learning method

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.