aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Enum Code from Bates/Sierra doesn't compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Enum Code from Bates/Sierra doesn Watch "Enum Code from Bates/Sierra doesn New topic
Author

Enum Code from Bates/Sierra doesn't compile

Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
Hello,

I'm going through Chapter 3, Q&A of Bates/Sierra book. It seems like a good idea to actually run and trace through code to get better understanding and appreciation of Java language.

Using the NetBeans 6.5 IDE, I am running the below code:




However, it doesn't compile because of the line:



Yet, if I comment it out, it compiles, runs, and displays the following output:

run:
SPADES 30
[LBridge$Suits;@190d11
BUILD SUCCESSFUL (total time: 2 seconds)


Questions:
1. Why doesn't it compile?
2. When I comment out the offending line, why does the output include something confusing as [LBridge$Suits;@190d11
3. How do I trace through code, line by line.

I appreciate your guidance.


Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
The code doesn't compile because the is no method getBidValue() defined anywhere. However there is a method called getValue(). Probably someone changed the name, but missed some code that references the old name.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

Sandra Bachan wrote:2. When I comment out the offending line, why does the output include something confusing as [LBridge$Suits;@190d11


This is a sort of default "I don't know how to display the information you want" type of output. Where possible Java will try to output a reasonable string representation of an object, however in many (most?) cases the Java compiler decides that there is no reasonable output, and so it goes back to a default: from memory the output can be read as "literal" Bridge class, Suits subclass, at memory address 190d11. This, of course, is quite useless for humans, but can have limited value for decompilers and debuggers.

Many people choose to use ReflectionToStringBuilder or Pojomatic or similar APIs to get reasonable representations of complex objects.

Sandra Bachan wrote:3. How do I trace through code, line by line.

This is probably the wrong forum for this question - you probably want to ask this question in the IDEs forum. Alternatively, searching Google for tutorial debug NetBeans may provide you with some useful suggestions. The first link I saw seems to me (a non NetBeans user) to be reasonably straightforward and what I would expect to see.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
@ Mike Simmons: I actually copied and pasted the code into the IDE - hopefully there won't be such typos on the actual exam!

@ Andrew Monkhouse: Thanks for the explanation - and I appreciate the link

Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hey Sandra,

You found an error in the book and you have my apology. But, I wonder if you're using an old copy of the book because that error is fixed in the new version of the book?

In any case, if you search for "errata" in this forum you can find several lists of errors in the book - depending on which version you have.

hth,

Bert

p.s. I absolutely encourage you to test the code in the book, and play around with it, make changes, recompile, etc. BUT, I also STRONGLY recommend that you NOT use an IDE. The entire Sun exam was written and tested without IDEs, and so was our book. The problem with IDEs is that they 'help' you by doing stuff behind the scenes. In many cases the stuff they do is the stuff you need to learn for the exam.


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
Hey Bert,


It's a great book to study from, especially the jokes every now and then. The version of the book I am using was published June 24, 2008.

By the way, I was using NetBeans to review chapters 1 through 3 before I proceed to chapter 4, but it seems that I'm focusing more of my time learning NetBeans rather than understanding the material for the exam, so I'll probably use JDK, (this is command-line, if I understand correctly?)

Will definitely search for errata - thanks!
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8883
    
    5
Hi Sandra,

Later on IDEs are great - they're just not the best for studying for the SCJP.

For now, you need to be able to type Java commands in at a command line, on a Mac you open a terminal window - on PCs you open up a DOS window.

Then you use a simple text editor to create and edit the actual .java files that you'll compile and run.

I'm assuming that since you have an IDE up and running that all your classpaths and such are already set up.
Sandra Bachan
Ranch Hand

Joined: Feb 18, 2010
Posts: 434
It seems the CLASSPATH (or rather, PATH) is set correctly because I am able to compile and run programs from the terminal in MAC.
 
wood burning stoves
 
subject: Enum Code from Bates/Sierra doesn't compile