Before talking about Aspect-Oriented Programming (AOP), let us think about the following situation:
I’d like to create a method that read from/write to database (a DAO class). And I end up doing the following:
- get the connection, create the prepared statement
- run the query, and process the result
- close the resultset and prepared statement
The problem is: everytime i create a method that read from/write to database, I end up doing all the above. If you notice, the first point and the last one are always repeated. If we could code the code such that it knows how to do the first point and the last one, life will be much easier.
Similarly for logging and transaction, most of the time they are repeated in every method and class. That replication is such a waste of effort.
We love to focus on 1 thing, 1 concern, which is the main functionality of our code. JDBC access, logging, and transaction are things we do to accomplish our secondary objective. They are repeated horizontally accross all class and methods, which makes these things called: cross-cutting concerns, or simply: Aspect. We definitely must deal with those Aspects, but can we do it once and for all instead of repeating it all over the place?

AOP is the answer. AOP is trying to separate these cross-cutting concerns (aspects) containing secondary objectives with our primary concern/objective of the code.
You may consider this similar to outsourcing. As a grocery supermarket company, the IT service, cleaning, and transportation service are the cross-cutting concerns of the company. Those services are used across ALL departments. It would be beneficial and cost-effective to the company if the company can focus on its core business competency i.e. selling groceries, and not being burdened by their IT, or cleaning, or transportation services. And thus, the company may decide to outsource those services/cross-cutting concerns/aspects.
Internally, in programming, Aspect-Oriented Programming works in such a way that: whenever it detects point(s) of interest (by matching a pattern), it will apply an operation to that part.
The points are called, Pointcuts. While the operation is called Advice.
Both Pointcuts and Advice together are called Aspect.
For JDBC above, we can use JDBCTemplate object of Spring so that we would not deal with the opening connection/preparedStatement/resultset and closing them.
For logging, we can define a pattern that matched all methods (pointcuts), and just after entering the methods, and exiting the methods we create Advice to print out some info into log.
For transaction, we can define a pattern that matched the create and update methods(pointcuts), so that just after entering method, transaction is started(Advice), and before exiting method successfully, we commit the transaction(another Advice), and when there is exception occured, we rollback (another Advice).
I hope it helps.