• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

OCP Java SE 11 Programmer II Study Guide (Sybex 816) Errata Chapter 2

 
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is very minor, but I looked thru the text to see what was being talked about both when I first read this in January and again now coming back to it...

On page 65, we find:

In this example, some annotations are all lowercase, while others are mixed case.



I guess we mean the @interface annotation that is used to define an annotation.

In every example I've seen so far anywhere, and in the book, pretty much every single one was InitialCaps everywhere, with @interface the sole exception.

I know this is not a rule, annotations will compile usING aNY CASE, but normally @interface is going to be the only one we will see lowercase, right?

It is an extremely-adhered-to convention that Annotation names will be usual InitialCaps names preceded by an @ when applied, right?

For that matter, they would normally be expected to be saved in MyAnnotationName.java as well, unless nested, as they are normally public top-level objects, right?

And lastly, it seems clear that @ is just a sigil for "apply the annotation here" and not to be considered part of its name, because import statements for them name them without it.

I think I got this now, and there are no actual misstatements mentioned here, just things that were sort of left to be inferred rather than stated explicitly anywhere, which left me wondering while working thru the chapter.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By far the scariest part of Chapter 2 on annotations has to be the new @Repeatable annotation (well, new to Java 8).

Coming back to it after six months away, it doesn't seem quite as scary, but part of that might be because I've accidentally learned some non-basic Java not otherwise in scope for the exam.

I looked at the Java SE 16 JLS sections 9.6 and 9.7 and boy, is the stuff on the test easier, simpler, way less complex!

Two things threw me when reading the chapter initially.

1. What the heck is the element value supplied to @Repeatable() even syntactically?
When first reading it, I was guessing it was the simple name of the .class file that the annotation was defined in after compilation, but felt really nervous about it.
I believe it turns out that is simply a class literal (Section 15.8.2 of the Java SE 16 JLS).
Now, if I am not mistaken, class literals, as important as they are to Reflection, are out-of-scope for the 819 exam, as are the rest of Reflection topics.
I believe the following, and any possible mock exam questions on the topic, are the only usages of class literals in the Complete Study Guide or the two volumes for 815 and 816:



Even more than before, I appreciate the extreme hard work that goes in to preparing the books to prepare the student, showing them everything they need to know, and not more, with a couple of places warning "this is not in scope for the exam anymore, but employers would expect Java programmers to know this".

In this case I feel like just a line or two about:

Risks.class is something called a 'class literal', which is beyond the scope of the exam except for its use here.
Basically, it just indicates that the containing Annotation Interface is named Risks.



Even just that would have quieted various fears or questions that sprang up about whether it needs to be qualified if it is in a package or whatever (remember I thought we were specifying the name of a file in some directory or in a JAR when I first read this chapter).

Optionally, an extra line saying something like:

Class literals are used pretty frequently in advanced Java coding involving Reflection, but all of that is beyond the scope of the 819 exam.  You don't need to worry about them in any other contexts beyond identifying the containing annotation class in a @Repeateable() annotation.



would have left me feeling confident that I had understood the section rather than wondering what was going on there (until I randomly learned about class literals outside the scope of exam preparation).

While we are discussing this scariest part of Chapter 2, I think the following is actually an error, tho minor.  I did stare at it a little both times wondering if I was misinterpreting it:

The containing type annotation must include an element named value(), which is a primitive array of the repeatable annotation type.



I don't think the Sybex OCP books refer to the term 'primitive array' anywhere else, I checked and the term is never used in the latest JLS.

Knowing what primitive means (one of the 8 non-reference types, i.e. byte, char, short, int, long, boolean, float, double, can live on the stack, they are value types, can't be placed in collections without boxing, etc.) and what array means, I would presume that the following three are primitive arrays:

int[] i
float[] f
double[] d

and the following are arrays of reference types:

String[] args
Character[] c
Cloneable[] clo

As annotations types are a special kind of interface, I am almost sure they are not primitives.

Probably, the words 'primitive array' were just used in the text to distinguish between say, an ArrayList<RepeatableAnnotationType> or Set<RepeatableAnnotationType> but I found the use of an unfamiliar term to raise more questions than it quelled.  Saying 'one-dimensional array of the repeatable annotation type' wouldn't have confused me in the same way, nor would have simple 'array of the".

I am glad I am thru reviewing this hardest/scariest part of the Annotations chapter.  I do think small changes would have made it seem less scary the first time, and appreciate that this chapter is about twenty thousand times easier to read than the corresponding sections of the JLS, now that I went and looked...
 
Master Rancher
Posts: 3930
51
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:I guess we mean the @interface annotation that is used to define an annotation.


@interface is not an annotation.  interface is a keyword indicating you're declaring an interface, and the @ modifies this to indicate that you're declaring an annotation interface.  That is, @interface isn't an annotation; it's the thing that tells the compiler you've begun declaring an annotation - and the next thing afterwards will be the name of the annotation.  You don't have any discretion in capitalization of Java keywords, including interface.

Jesse Silverman wrote:It is an extremely-adhered-to convention that Annotation names will be usual InitialCaps names preceded by an @ when applied, right?


The InitialCaps part, for annotation names, is an extremely-adhered-to-convention, though not a rule.  (Just like we have for class names and interface names.)  The @ part is not a convention, it is a requirement.
 
Mike Simmons
Master Rancher
Posts: 3930
51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe your statements in the latter post are all correct.  I agree that "primitive array" would seem to indicate an array of primitives, and thus, an array of Class object does not qualify.  I think they should just remove "primitive" from this statement; it's wrong.  The value() of a @Repeatable should be an array of Class objects, representing the types that the repeatable annotation may be repeatedly applied to.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I realize I am not quite sure what @Inherited means, even after consulting the JLS!

The 816 book says simply "When this annotation is applied to a class, subclasses will inherit the annotation information found in the parent class."

I nodded my head along at this and kept going.

In the example given, they demonstrate that an @Inherited class-level annotation applied to the super-class gets inherited by the sub-class, and there's no confusion there at all.

The words "the annotation information found in the parent class" led me to realize that I am not sure if the inheritance of annotation information covers annotations on absolutely everything inherited from the super-class, or just the top-level class information.

For instance, does @Inherited mean the sub-class will behave as if it has all the same annotations on all the inherited methods, parameters of inherited methods, etc. or just a top-level annotation applied to the super-class as a whole?  I think it does, but wouldn't be sure without writing test code or searching the web.

EDIT -- I am not sure which of the following is true:
1. @Inherited is only relevant to annotations applied at top-level to a class, not those applied anywhere else.
2. @Inherited is relevant to annotations applied to anything that can be inherited in a sub-class, not just those applied to the class definition as a whole.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm even more dense!

While I don't create them often, sub-interfaces are certainly a thing.

Does @Inherited apply at all to interfaces that extend other annotated interfaces, or only to annotated super-classes and sub-classes?

I didn't see anything that *says* "classes and interfaces", but it seems like it might be a reasonable thing to have implemented.

Thanks for the clarifications.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wrapping up Chapter 2, the odd words "primitive array" come up again.

On page 73, we show that if we only have one single String value that needs to be passed to an annotation element defined as a String array, we can shortcut something like this:
@Music(genres={"Rock and roll"}) String mostDisliked;

with something like this instead:
@Music(genres="Classical") String favorite;

On page 92, under Understand how to apply an annotation with a single-element array.
If one of the annotation elements is a primitive array and the array is passed a single value, then the annotation value may be written without the array braces ({}).

"primitive array" does cause me to think of the hysterical Fred Schneider classic "Boonga, the New Jersey Caveman", but that song is outside the scope of the exam.

If it is meant to be "array of primitive values" it is incorrect.  If not, I am not sure what this term is meant to signify.

I felt comfortable with this section of the chapter so it doesn't bother me much.
I had already felt unsure about @Repeatable in the other place this term was used so it freaked me out, but I am not sure if the term is being used appropriately in either spot, or what it is meant to signify.  I often use the term primitive similar to the definition of primitivetype as seen in section 4.2 of the Java SE 16 JLS, which would not include String, etc.
 
Jesse Silverman
Ranch Foreman
Posts: 627
13
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the chapter end questions, which are intended to also be suitable mock certification exam questions asks us to fill in the blank:

The __________ annotation determines what annotations from a superclass or interface are applied



This makes me think, if true, it would be less odious if the description in the text which is simply

"When this annotation is applied to a class, subclasses will inherit the annotation information found in the parent class."



Were "When this annotation is applied to a class or interface, subclasses and sub-interfaces will inherit the annotation information found in the parent class or interface."

To be fair, in Table 2-3, the description of "Default Compiler Behavior (if annotation is not present)" does read "Annotations in supertypes are not inherited." which suggests that @Inherited also affects interfaces which extend other interfaces and classes which implement interfaces.

Also, in the "Exam Essentials" section, We see the sentence that "@Inherited is another marker annotation that determines whether annotations are inherited from super types."

So I guess it becomes clear (at least after taking the chapter quiz) that @Inherited does NOT just apply to classes inheriting classes, but to both sub-interfaces and implementing classes as well.

I would suggest that the material in the section that introduces and explains @Inherited be updated to not suggest that it only applies to inheritance from super-classes to sub-classes.
 
author & internet detective
Posts: 40677
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:
I guess we mean the @interface annotation that is used to define an annotation.


@interface is the only one that comes to mind. It 's certainly good practice to make them @InitialCaps
 
Jeanne Boyarsky
author & internet detective
Posts: 40677
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Simmons wrote:

Jesse Silverman wrote:I guess we mean the @interface annotation that is used to define an annotation.


@interface is not an annotation.  interface is a keyword indicating you're declaring an interface, and the @ modifies this to indicate that you're declaring an annotation interface.  


Oh interesting. I never realized it wasn't an annotation
 
Jeanne Boyarsky
author & internet detective
Posts: 40677
827
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesse: I've noted your comments for consideration when we edit. Thanks.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic