Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enum Code from Bates/Sierra doesn't compile

 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11888
203
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ 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
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems the CLASSPATH (or rather, PATH) is set correctly because I am able to compile and run programs from the terminal in MAC.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic