Deployment / Annotation
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
Annotation is like nothing else in Java. It was completely new in Java 5 and it's very different. This lesson introduces you to it and how it works and you'll be seeing other aspects of it in upcoming lessons. Annotations are really a form of documentation. Now, this is not Javadoc. This is something else. The annotation documentation is in the source code of course, but it can also be written in such a way that it appears in the Runtime code also. But it doesn't do anything. It can appear in the Runtime code, but it is never something that's actually executed. While annotations do not directly produce executable code, they can slightly effect the way the compiler operates, so they can have an effect on what code is produced, but it's minor. Because some annotation information can be included in the Runtime code, it is possible to inspect the annotation information at Runtime Inspection is not covered in this lesson, but it is covered in a future lesson. Let's start with a simple annotation. An annotation always begins with the at sign character and it always come immediately in front of the item being annotated. This is an annotation of a method. In this example, the annotation override is being used to document the fact that this method is overriding a method of the super class. Because of the annotation, compiler will check. You can see that the compile failed because the method name was misspelled and there was no such method in a super class. Without the annotation, the error would have simply gone unnoticed. This example tries to create an instance of the vector class in its raw form; that is without using the generic portion. Here's what happens when you try to compile this class. But you can use an annotation to suppress warning messages. This is a warning message, so it can be ignored. The class compiled ok. Here is almost the same class again, but this time the suppress warnings annotation is suppressing the emittance of unchecked warning messages. Here's what happens when you compile it this way. It's the same as if the vector class had been declared without generics. The class compiles clean either way, but this way the compiler shuts up about it. The various compilers have different warning messages, so you'll need to check the documentation of your compiler and see what warnings you might like to suppress. You can put as many as you like in a list like this and any that don't apply to the compiler are just ignored. You can define your own annotations and apply them as you like. The keyword interface preceded by an at sign is used to declare an annotation. You declare the annotation as a list of variables. You can use any of the Java types. The syntax for the variable name sort of looks like a function. It's followed by the keyword default and a default value for that item. I'll have some more about these declarations in a future lesson. This annotation is declared with some annotations of its own. The documented annotation means that the information from this annotation, whenever it is used, will also show up in Javadoc. The retention annotation means that this annotation will be included the Runtime; that is it will go into the class file. Here is an example of the newly-defined annotation being used to annotate a class. When this class is compiled, the resulting class file will contain the values defined in the annotation. More about all this later. In the next lesson, we start looking into the contents of the java.lang package and annotation is one of its sub-packages.
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 