text: Q:
  
  Does a lock do the same for synchronized?
  
  Let's say I have a thread-safe bank account class looks like this
  class BankAccount {
  
      private long balance;
  
      public synchronized long getBalance() {
          return balance;
      }
  
      public synchronized void deposit(long amount) {
          balance += amount;
      }
  
      public synchronized void withdraw(long amount) {
          balance -= amount;
      }
  }
  
  Does using a lock make a same effect?
  class BankAccount {
  
      private long balance;
  
      private final Lock lock = new ReentrantLock();
  
      public long getBalance() {
          try {
              lock.lock();
              return balance;
          } finally {
              lock.unlock();
          }
      }
  
      public void deposit(long amount) {
          try {
              lock.lock();
              balance += amount;
          } finally {
              lock.unlock();
          }
      }
  
      public void withdraw(long amount) {
          try {
              lock.lock();
              balance -= amount;
          } finally {
              lock.unlock();
          }
      }
  }
  
  A:
  
  Yes.
  
  ReentrantLock: A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities.
  
  From the official documentation for reentrant locks
  
  