Object oriented programming with Java annotations. So, we're going to look at what annotations are, why they're needed, how they're used, how they're declared. Different kinds of annotations that exist, give examples of where and how they're used in real code. And in lab, you will write one and actually get a chance to work with some of the code to inspect them. So why annotations? So here are some points that are being made. One, a lot of our programming APIs yes, object-oriented APIs require a lot of boilerplate setting things up for persistence, setting up endpoints for rest. Setting up web services end points. Calling rest or web services end points, and many, many, many other things. And there's a lot of boilerplate that if I could only tell a smart environment a little bit about my programming, maybe it could be do it for me. The earliest form of metadata for Java was actually the Javadoc. There were comments embedded in Javadoc comments that provided metadata. The problem is none of that was left around at runtime. And that is the advantage of annotations. The metadata can be embedded in the class file and preserved even at runtime when the classes are in memory. So that's what annotations are, a facility to provide metadata within the Java code itself. So the advantage is that annotation processing tools can scrape the annotation from the code and find out the metadata from the class, the method or the field. Yes, I deliberately read that to you, because it doesn't actually tell you what the advantages is. So let's look at some code. Here is a complete application in three files. This is a complete although simple REST service for delivering customer information from a database. This is the main program. It's in spring boot, and it simply says run yourself. Here is one of the two critical files. This is a customer Pojo, but it does have some annotations. The ID field, is marked as the ID for looking this up in the database. And we're told how we should generate this value, is it auto incrementing or how is it done? And according to this annotation, it will be done by whatever the default strategy is for this database driver. And there's nothing else in here of note. And in fact, when I wrote this code I created these lines here, as well as the class itself and marked it as an entity and these annotations there, and every other line of code in this file was generated for me by eclipse. I told it to generate the constructors. Generate the setters and getters. I wrote no other lines of code beyond that, period. And here is the whole rest of the program and it's nothing more than an interface. And this interface says I need a customer repository, which is a JPA repository so I'm extending a parent interface. For customer with a key is a long and I'm adding find by first name and find by last name as two custom methods. But all of the other methods and I'd have to go count them but there are over a dozen that give me all the CRUD operations. All the methods you would expect on a repository for managing customer objects. They're all going to be here. Now again, this is an interface where's the code coming from? It will all be generated for me automatically, by the package known as spring data. All the code will be generated, I've simply created a repository and annotated it, that's it. And so because annotations are here to provide the necessary metadata, everything else can be done for me by the framework. And that is the advantage of being able to have annotation based tools that can get the data they need from the code and they will act based on what they find and do, in this case, all the for me. That's why annotations. And that's why this is such a useful module for us.