Java Basics

1. Visibility of Java modifiers

public accessed to all components
protected accessed to all components in the same package and subclass in the different package
default accessed to all components in the same package
private accessed only to the components in the same package

2. final, finally, finalize

final means once the reference is assigned, it cannot be reassigned

  • for class, it cannot be inherited
  • for method, it cannot be overiden
  • for variable, it cannot be modified
  • 3.synchronized

    Synchronized methods:

  • When a thread executes synchronized methods of one object, any other thread which is going to execute any synchronized methods in this object is blocked.
  • hapopens-before state is stored, so the change of states can be visible to all threads.
  • Synchronized objects:

  • any access to this object is blocked
  • hapopens-before state is stored, so the change of states can be visible to all threads.
  • Leave a Reply

    Your email address will not be published. Required fields are marked *