A few special activities / Annotation Examples
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
This lesson contains a few examples of using annotations. When you compile this class it compiles OK but it generates a spurious warning message, all this class does is create a vector as a date object to the vector and then returns it. The logical is fine and the code will work but the vector class is a generic, so a warning message comes out. Let me show you. There you see a part of the warning message along with instructions about what you need to do to get the rest of the message. Here's the whole thing, you can see from this that the name of the warning is unchecked, you can use that name to suppress the message like this. This is the same code but with the warning message suppressed, this annotation does the suppressing, an annotation applies to whatever follows it, so this annotation applies to the main method. This same annotation could have been in front of the class name and it would apply to everything in that class. Anyway, now it compiles like this, no warnings, no errors, this form compiles clean. This is something we've all done, when you write a sub class and you need to override a method of the super class and you misspell the name of the method in the sub class you don't get what you intended but you don't get an error message either. However if you use the override annotation you can specify a method as being one that must override a super class method and you will get an error if it doesn't. This example has two sub classes, both of which attempt to override the super class but overriding the super class method fails but only one of them generates an error message. The override annotation checks. Here's what happens, in this example the name is misspelled, but it also happens if the parameter types don't quite match. That's how it usually gets me. Ok, one more and this one is pure documentation, you can devise a special documentation scheme and be as detailed about it as you want. Remember an annotation applies to whatever follows it, class, interface, method, variable, whatever. This example is about defining a special documentation hitter block for classes. You declare the lay out of the block with this annotation keyword, the at sign interface. Then you define the contents of the interface as being a collection of fields. Each has a type and a name, the syntax of the field definition is a little odd, it looks sort of like meta definitions and each one can have a default value. Notice the array format, you can define an array of any data type, in this case its an array of strings. Once you have declared the format of the interface you can use the name anywhere you'd like, in effect you've defined a new annotation type. You can declare values for all the fields, any fields that you leave out will assume their default values, this annotation is supplied to a class because it's placed right in front of the class. Also this annotation is defined as documented, because it has the documented annotation in front of it. To be able to use the documented annotation you have to include this import statement. If an annotation is documented it means that the information will be included by Java doc. Here let me show you, this is the Java Doc page for the class, there's not much to it really. But you can see that the contents of the annotation are included in the class description. With the next lesson we are going to start taking a look at concurrency and what it takes to run multiple Java threads.
Tutorial Information
| Course: | Java 6 |
| Author: | Arthur Griffith |
| SKU: | 33858 |
| ISBN: | 1-934743-59-3 |
| Release Date: | 2008-02-29 |
| Duration: | 7 hrs / 92 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 