Java Note 3

Source: Internet
Author: User

26. Overload: public static void add (int A, char B, double C); and public static void add (int A, double C, char C); overload

27. The overload is irrelevant to the return value type.

28. Even if an instance is empty, it can access the class members of the class to which it belongs. However, accessing the members of the instance will cause an nullpointexception exception.

29. If a class can only create one instance, this class is called a singleton class.

30. Final indicates that the variable cannot be changed once the initial value is obtained.

31. The final modified instance attribute either specifies the initial value when defining this attribute, or specifies the initial value for this attribute in a common initialization block, or the constructor. The initial value cannot be specified in a common method.
Unlike common member variables, final member variables (including instance attributes and class attributes) must be displayed and initialized by the programmer. The system does not implicitly initialize the members of the final member.

32. The system does not initialize local variables. Local variables must be displayed and initialized by the programmer. Therefore, when using final to modify local variables, you can specify either the default value or the default value, the value can be assigned only once, but cannot be assigned repeatedly.
The form parameter modified by final cannot be assigned a value.

33. When final modifies a basic data type, the basic data type cannot be changed, but when it modifies a reference type variable, it only saves a reference, final only ensures that the referenced address does not change, that is, it always references the same object, but this object can change completely.
That is, the reference type variable modified with final cannot be assigned a value again, but the content of the object referenced by the reference type variable can be changed.
34. The basic data types modified by final must follow the naming rules of constants, that is, uppercase letters.

35. The final modifier method cannot be overwritten. If you do not want the subclass to override a method of the parent class, you can use final to modify the method.
If the subclass defines a method that has the same method name, the same parameter list, and the same return value type as the parent class private method, it is not a method rewrite, but a new method is rewritten. Therefore, even if you use a final method to modify a private access permission, you can still
The subclass defines methods that have the same method name, the same parameter list, and the same return value type as the method.

36. The final modification method can only be rewritable, not overloaded.

37. The classes modified by final cannot have child classes, that is, they cannot be inherited.

38. The eight packaging classes provided by Java and Java. Lang. String are both immutable classes. After their instances are created, their instance attributes cannot be changed.

39. abstract methods are only method signatures and methods that are not implemented. They are modified with abstract modifiers.

40. classes with abstract methods can only be defined as abstract classes. abstract classes can have no abstract methods. abstract classes cannot be instantiated. The New Keyword cannot be used to call the constructor of abstract classes to create instances of abstract classes, even in the abstract class
This abstract class cannot create instances. Classes containing abstract methods can only be defined as abstract classes. constructors of abstract classes cannot create abstract class instances and can only be called by quilt classes.

41. Final and abstract cannot be used at the same time. Abstract cannot be used to modify constructors, attributes, and local variables. Static and abstract cannot be used at the same time because static modifies class methods, abstract-based methods do not have a method body.
When a static method is used, the abstract modified method does not have a method body, so an error occurs when calling the method. Private cannot be used with abstract, because the method in abstract must be rewritten by a subclass to make sense.

42. Interface: more thorough abstraction; define an interface using the interface keyword; modifier can be public or omitted; an interface can have multiple direct parent interfaces, but the interface can only inherit interfaces, class cannot be inherited;

43. Because the interface is defined as a standard, the interface cannot contain the constructor and initialization block definitions. An interface can contain attributes (only constants), methods (only abstract instance methods), internal classes (including internal interfaces), and enumeration classes. When defining interface members, the modifier can only be public or omitted.
The default value can only be specified when the attribute defined in the interface is defined (the system will automatically add public static final)

44. A Java source file can have only one public interface. If a public interface is defined in a source file, the main file name of the source file must be the same as the interface name.

45. The interface fully supports multi-inheritance, that is, one interface can have multiple direct parent interfaces.

46. The interface cannot be used to create an instance, but it can be used to declare variables of the reference type. The implements keyword is used for implementation.

47. Only public access is allowed when implementing methods in the class implementation interface.

48. The interface cannot show that it inherits any class, but all referenced variables of the interface type can be directly assigned to reference variables of the object type.

49. Similarities between interfaces and abstractions: they cannot be instantiated and can only be implemented and inherited by other classes. They can both contain abstract methods, these abstract methods must be implemented to implement interfaces or inherit ordinary subclasses of abstract classes.
Difference: the interface represents a standard, and the abstract class represents a template design.

50. The non-static internal class can directly access the private members of the external class, but the external class cannot access the instance attributes of the non-static internal class. To access the instance attributes, you must display the internal class object created.
Java does not allow defining static members in static internal classes. Static modifying internal classes can make internal classes become external class-related, rather than external class instances. Static cannot modify external classes, internal classes can be modified

51. Internal classes provide better encapsulation. Internal classes can be hidden from external classes, and other classes in the same package are not allowed to access this class, internal class members can directly access the private data of the external class, because the internal class is regarded as its external class members, and members of the same class can access each other, however, external classes cannot access the implementation details of internal classes, such as internal class attributes.

52. Anonymous internal classes are suitable for those classes that only need to be created and used once.

53. The internal class can be defined anywhere in the class, including the method. The internal class can also be defined in the method. The internal class defined in the method is called a local internal class.

54. The local internal class and anonymous internal class are not class members

55. The external class has only two types of access permissions: Package access permission and public access permission. The upper-level Program unit of the internal class is an external class, so it has four scopes: the same class, the same package, parent and child classes, and any location, so you can use four types of access control

56. class files of member Internal classes (including static and non-static internal classes) are always in this form: outerclass $ innerclass. Class

57. If the external Class Attribute and internal class attribute have the same name as the local variable of the method in the internal class, you can use this and external class name. This as the limitation differentiation.

58. Non-static internal class members can access the private members of the external class, but in turn they are not true. Non-static internal class members are only known within the non-static internal class range, it cannot be directly used by external classes. to access non-static internal class members, you must create a non-static internal class object to call and access its instance members.

59. Non-static internal class objects must be stored in external class objects, while external class objects do not have to have non-static internal classes.

60. Non-static internal class internal static cannot have static declaration, non-static internal class can not have static initialization block, but can contain common initialization Block

61. static internal classes (class internal classes) belong to the entire external class, rather than an object of an external class.

62. Static modifier members belong to the entire class rather than a single object. The upper-level Program unit of an external class is a package, so static modification is not allowed. The upper-level Program unit of an internal class is an external class. Using static modification, the internal class can be changed to an external class, it is not related to external class instances. Therefore, the static keyword cannot modify the external class or the internal class.

63. static internal classes can contain static members or non-static members. Static internal classes cannot access instance members of external classes. They can only access class members of external classes. Even the static internal class multi-point instance method cannot access the instance members of the external class, but can only access the static members of the external class.

64. Why can't non-static internal class instance methods access the instance attributes of an external class?
Because the static internal class is related to the external class, rather than the object of the external class. That is to say, when an object of a static internal class exists, there are no external class objects stored by him. Only the objects of the static internal class are referenced by the class of the external class, there is no reference to an external class object. If the static internal class instance method is allowed to access the instance members of the external class at this time, but the external class object to be stored cannot be found, this will cause an error.

65. External classes cannot directly access members of static internal classes. However, you can use the class names of static internal classes as callers to access class members of static internal classes, you can also use objects of static internal classes as callers to access instance members of static internal classes.

66. Java Allows defining internal classes in Interfaces. The internal classes defined in interfaces are modified using public static by default. That is to say, internal classes of interfaces can only be static internal classes.

67. An internal interface can be defined in the interface, but it is of little significance and has never been encountered by the author.

68. When a non-static internal class is used outside the external class, the variable outclass is defined. inclass varname; create a non-static internal Class Object: outinstance. new inconstructor (); a specific example: Out. in in = new out (). new in ("test information ");

69. use static internal classes outside external classes. Because static internal classes are class-related, you do not need to create external class objects when creating internal class objects. Syntax: New outclass. inclassconstructor ();

70. If an internal class subclass object exists, the corresponding external class object exists.

71. The internal class defined in the method is a local internal class, and the local internal class cannot be used outside the external class. Therefore, the access control operator and static modifier are not required for the local internal class.

72. For local internal members, whether they are local internal variables or local internal classes, their upper-level program units are methods rather than classes. It makes no sense to modify them using static. Therefore, local members cannot be modified using static. The scope of a partial member is the method in which it is located. Other program units will never be able to access the partial member of a method. Therefore, the access controller cannot be used.

73. The name of the class file of the local internal class has a number greater than that of the class file of the internal class: outclass $ ninclass. class; this is because the same class cannot have two internal classes with the same name, while the same class may have more than two local internal classes with the same name, so Java adds a number for this, used for differentiation.

74. Anonymous internal classes are suitable for creating classes that only need to be used once. Anonymous internal classes cannot be used repeatedly.

75. An anonymous internal class must inherit one parent class or implement one interface, but it can only inherit one parent class or implement one interface.

76. Two rules for anonymous internal classes:
① An anonymous internal class cannot be an abstract method, because when an anonymous internal class is created, the system immediately creates an anonymous internal class object.
② The anonymous internal class cannot define the constructor because the anonymous internal class does not have the class name and cannot define the constructor. However, the anonymous internal class can define the instance initialization block, you can use instance initialization blocks to complete the tasks that need to be done by the constructor.

77. When an anonymous internal class is created through an implemented interface, the creation constructor cannot be displayed for the anonymous internal class because there is only one implicit non-parameter constructor for the anonymous internal class, therefore, parameter values cannot be entered in parentheses after the new interface name;
If you create an anonymous internal class by inheriting the parent class, the anonymous internal class will have a constructor similar to the parent class (same as the parameter list ).

78. If the anonymous internal class needs to access the local variables of the external class, the final modifier must be used to modify the local variables of the external class. Otherwise, the system reports an error.

79. Closure: an object that can be called. It stores information about the scope of the created object.

80. Callback: Once a method obtains reference from an internal class object, it can call the instance method of the external class in turn when appropriate, it is the method that allows the customer class to call its external class through the = reference of the internal class.

81. Several features of the garbage collection mechanism:
① Only recycles objects in the heap memory, and does not recycle any physical resources (such as database connections and network I/O resources)
② The program cannot accurately control the running of garbage collection, and garbage collection will be conducted at appropriate times;
③ Before the garbage collection mechanism recycles any object, it will always call its Finalize method. This method may be a re-resurrection of the object (so that a reference variable can re-reference the object ), this causes the garbage collection mechanism to cancel collection.

82. Finalize method: Never take the initiative to call the finaliaze method of an object. This method should be handed over to the garbage collection mechanism for calling and there is uncertainty when it will be called; when the JVM executes the finaliaze method of the deactivating object, the object or other objects in the system may be re-activated. When the JVM executes the finaliaze method, an exception occurs, the garbage collection mechanism does not report exceptions and the program continues to be executed.

83. The system has three types of references to objects: strong reference, soft reference (dependent on a class), and weak reference (dependent on a class). The system cannot use virtual reference to obtain the referenced image.

84. For initialization blocks and local members, they cannot use any access controllers, and it looks like they use a packet access controller.

85. strictfp Keyword: exact floating point meaning, even if floating point calculation is more accurate

86. The native keyword is used to modify a method. Similar to an abstract method, the native method is usually implemented in C language. If a method needs to use platform-related features or access system hardware, it can be modified using native and then handed over to the C language for implementation. Once the Java program contains the native method, this program will lose the cross-platform feature.

87. abstract and final cannot be used at the same time, and abstract and static cannot be used at the same time. Abstract and private cannot be used at the same time

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.