• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible typo page 274 (Java OCA 8 Programmer I Study Guide, Sybex)

 
John Consorti
Greenhorn
Posts: 12
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not totally sure if what was written is how it was intended, but I believe the second code block on page 274 should read "public abstract interface CanSwim".  This section is based around interface integers being public static finals, but it states that the compiler will automatically convert the both to the second example.  Like I said it may be written as designed, but as a fresher it would be nice to have the abstract keyword added as well to reinforce the concept.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Consorti wrote:I believe the second code block on page 274 should read "public abstract interface CanSwim".

No, it should not! The abstract modifier in an interface declaration is allowed but discouraged. So you might encounter the following interface declaration on the examAnd you should know it's valid code (which will compile successfully), but the compiler will not translateintoSo the code snippet in the study guide on page 274 is accurate as-is.

Hope it helps!
Kind regards,
Roel

PS. If you download a Java decompiler (like JAD), you can create an interface, compile it, decompile the .class file and verify it yourself
 
Ganesh Patekar
Bartender
Posts: 694
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can download JAD from this  link <--- click here
Example 1:
  • Suppose you have MyInterface.java interface on c drive.
  • Before decompiling:

    After decompiling:

    Example 2:
  • Suppose you have MyAbstractInterface.java interface on c drive.
  • Before Decompiling:

    After Decompiling:

  • Compile interface using javac, you will get .class file and use jad command to decompile that .class file like shown in screenshot image. You will get .jad file after decompiling, can open in text file or notepad++. Jad has ample number of options too.

  • jadCommand.png
    [Thumbnail for jadCommand.png]
     
    John Consorti
    Greenhorn
    Posts: 12
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you both, I appreciate the help and I will also look into getting a JAD for better understanding.  Although this does raise a question about a previous page (268) where it states "For example, the following two interface definitions are equivalent, as the compiler will convert them both to the second example:



    In this example, the abstract keyword is first automatically added to the interface definition."

    I apologize if I am misunderstanding, but I want to be sure I'm understanding exactly what is going on.
     
    Ganesh Patekar
    Bartender
    Posts: 694
    23
    Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Actually I tried It practically, It removed that abstract keyword. Also checked It is not in OCA 8 Errata List. You can refer this erratas link for future use to check erratas. Until someone who knows notices, you can download JAD and try It. 
     
    Jeanne Boyarsky
    author & internet detective
    Marshal
    Posts: 35279
    384
    Eclipse IDE Java VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I saw this thread. I didn't rely because Roel said what I would have.

    Keep in mind the book is teaching you for the exam. Whether the compiler gets rid of the word "abstract" in the interface isn't important for the exam. The methods are logically abstract and you can't instantiate the interface. That's the important part here.

    While it is fine to use a decompiler, don't let it distract you from the level of understanding required for the exam. You don't want to get a question wrong based on a decompiler output. Also keep in mind compilers (and decompilers) may optimize the code. If you don't know Java well, I wouldn't recommend using the decompiler. I think it could confuse you.
     
    Paul Clapham
    Sheriff
    Posts: 21566
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Decompilers will often produce code which is different from the original, too. The differences can range from trivial to bizarre-looking, too. So I second Jeanne's recommendation -- don't bother with the decompiler while studying for the exam.

    After you've passed the exam, though, using a decompiler can provide some interesting insights into how the compiler works. Just remember that the exam isn't asking questions about how the compiler works.
     
    Ganesh Patekar
    Bartender
    Posts: 694
    23
    Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh I see, thank you Jeanne and Paul for clearing misconception.   Yes thoroughly agreed with both of you decompiler might distract from the objective of exam.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ganesh Patekar wrote:use jad command to decompile that .class file like shown in screenshot image.

    I wonder why you have posted this as a screenshot and not simply as a plain code snippet (and UseCodeTags of course )? If I want to compile (and execute) your code snippets, I know have to type them myself. And yes, I am (very) lazy So I'll be losing precious time which I could otherwise be spending on typing a nice reply... And another reason: attached images are not searchable using the search engine, some text or a code snippet definitely is.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Roel De Nijs wrote:PS. If you download a Java decompiler (like JAD), you can create an interface, compile it, decompile the .class file and verify it yourself

    Since I was the first in this thread to mention the use of a Java decompiler, I like to emphasize it should only be used just for fun and by no means to prepare yourself for the certification exam. Because as already mentioned by Jeanne and Paul:
  • the certification exam doesn't require any knowledge about (de)compiled code (because different compilers might result in different code optimizations)
  • different decompilers might result in different decompiled code (which might be different from the original code too)
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic