• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

minor typo in page 262 chapter 5 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Ramya Subraamanian
Ranch Hand
Posts: 178
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the code it says

you don't need a final. thats a typo right . is there a errata list for Java OCA 8 Programmer I Study Guide, Sybex.
 
Ramya Subraamanian
Ranch Hand
Posts: 178
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry thats not a typo.

I have never seen reference variables created with final modifier. This seems perfectly alright. I am exploring final reference variables

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramya Subraamanian wrote:you don't need a final. thats a typo right .

As you already have figured out yourself, that's definitely not a typo. Besides final classes and final methods, you can have final class (static) variables, final instance variables, final local variables and final arguments (parameters). And the type of the variable doesn't matter: it can be both a primitive data type and a reference type. Please note that although a reference variable is marked final, you can not assign another object to the reference variable, but you can still change the actual object denoted by the reference variable as illustrated in this code snippet

Ramya Subraamanian wrote:is there a errata list for Java OCA 8 Programmer I Study Guide, Sybex.

Yes! Here you can find the official errata overview (updated by one of the authors).

Hope it helps!
Kind regards,
Roel
 
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
Ramya Subraamanian wrote:I have never seen reference variables created with final modifier. This seems perfectly alright. I am exploring final reference variables

I'm pretty sure the code snippet you have posted doesn't compile, because the myeel class doesn't exist. You should always be very meticulous when posting code snippets and make sure your code snippets compile successfully (unless it's intended to have a compiler error). Not only because otherwise ranchers who want to answer your question (or clear your doubts) might be confused, but certainly because on the actual exam having an eye for detail is one of the very important aspects to pass the exam. You should definitely put some effort and have great care when posting code snippets, so you learn to pay attention to little details. For example, (as you probably know) a short and a Short are definitely not the same in Java.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personal style comment... I love marking all local variables "final" as this prevents other developers in large projects from accidentally re-assigning a new object to my variable when editing a class. I do skip doing this for method arguments, though, as it makes the signatures really long.

To put it other way, it's my way of having the compiler tell the other developer "Are you sure you really want to do that?" as oftentimes they didn't mean to reassign it. Lists are a great example of this. When I create a local List in a method (to be used as a return type especially) I almost never want it reassigned. If you need to wipe it, just use clear(). The object to be returned stays constant throughout the method even if the contents change dynamically.
 
Ramya Subraamanian
Ranch Hand
Posts: 178
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this was the code I intended to paste. I accidentally pasted a part of it and overlooked it.






 
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
Ramya Subraamanian wrote:this was the code I intended to paste. I accidentally pasted a part of it and overlooked it.

That looks much better!

Although it's not a requirement, it's considered a good (best) practice to follow the naming conventions: e.g. classes (and other types) start with an upper case letter and follow camel case notation, as in this code snippet
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic