• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forgive the newb. Headfirst Java pg.79 the ElectricGuitar app.  RSS feed

 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I'm just starting to get this stuff straight in my head. I just figured out how objects relate to classes and how you can create and re-use object types, so I'm proud of myself
on that point, but this has me baffled. I most certainly do not have a firm grasp yet on passing things to and from methods that just makes my head hurt. SO anyway I tried out
one of the code examples:



I get one error on compile:

/Users/rfindlay/Dropbox/Java/SourceCode/ElectricGuitar.java:18: error: missing return statement
}
^
1 error
[Finished in 0.5s with exit code 1]
[shell_cmd: javac "/Users/rfindlay/Dropbox/Java/SourceCode/ElectricGuitar.java"]
[dir: /Users/rfindlay/Dropbox/Java/SourceCode]
[path: /usr/bin:/bin:/usr/sbin:/sbin]


But I just realized this thing has no main method and only one class defined.....so I guess I just tried to compile
something that isn't meant to compile...lol....am I wrong?

-Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not need a main to compile.

What you do need is no spelling mistakes. Check your syntax carefully, bearing in mind that case counts.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are things you need to aVoid.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You do not need a main to compile.

What you do need is no spelling mistakes. Check your syntax carefully, bearing in mind that case counts.


Oh boy, help me out here guys, I'm actually dyslexic and I've looked over this code until my eyes want to bleed and I
don't see were my syntax is wrong.

Also if anyone can help enlighten me or perhaps point me to some resources to better understand this whole
passing of arguments to methods.....I just don't "see" it in the code yet.

Thanks again.

-Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carefully compare line 15 to line 27. The syntax highlighting also helps hint at what's wrong
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Carefully compare line 15 to line 27. The syntax highlighting also helps hint at what's wrong


ARG! Guys throw me a bone here, on line 27 to I have the order of the variable types wrong? I'm pulling my hair out trying
to find this syntax/spelling error.

I seriously do not see it......

:-(

-Rob
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 15: "Void" with a capital "V", also looking like the rest of the code.

Line 27: "void" with a lower-case "v", displayed by the code formatting as blue, unlike the rest of the code.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh good lord I'm face palming off the Empire State Building. Arg.

THANK YOU GUYS

Ok the txt editor I'm using is sublime text I guess the color coding doesn't catch spelling errors :/

So 2 things what's a good or betterish text editor for simple java coding with really good color and syntax checking? I've tried VIM and textwrangler any other ideas for the Mac? Trying to avoid a full IDE but wouldn't rule it out if it's simple and intuitive.

Second can some point me to a good doc that covers what this code is doing? Passing things to and from methods. I'm just not getting it.
Thanks again.

Rob
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use IntelliJ. It's an IDE, but I use it as an intelligent editor rather than a full-blown environment.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regards to your parameter passing quandary, it'd be better to post some examples of things that confuse you. That way we have concrete examples to explain.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:With regards to your parameter passing quandary, it'd be better to post some examples of things that confuse you. That way we have concrete examples to explain.



Well how about the code above for example....
 
Paul Clapham
Sheriff
Posts: 22835
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We've already covered that code. Haven't we? Didn't you fix the problem in it?

Assuming you did all of that, then if you still have a question then how about posting the code you have a question about? (And the question, of course.)
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People who have no difficulty spelling fall foul of that sort of pitfall, too, so don't worry about it.
We usually tell beginners to avoid IDEs, but you are probably better off using one if you are dyslexic, because it can help with spelling corrections.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, here's another example, this one compiled and ran fine, can someone look at my comments and tell me if I'm even remotely correct?



Thanks.

-Rob
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Findlay wrote:Ok, here's another example, this one compiled and ran fine, can someone look at my comments and tell me if I'm even remotely correct?

No, you are declaring public method that returns the value of size.

No, you are not declaring variable size here. You are setting the value of instance variable size to the value passed to method setSize in argument s.


The rest of your comments seem correct.

What you don't understand in passing parameters to methods? I'd like to help, but I need to know what you are unable to understand.
The variable size was declared in line 9.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you muchly for the help.

I guides I understand the concept I just don't "see" it
In the code yet if that makes any sense?

I think if someone could explain in the above two
Examples or provide a couple snippets of code
and describe exactly what is being passed
from point a to b, it might help me understand
and "see" where it's taking place.

Also, RTFM is a fair enough answer as I haven't
coded beyond HTML in almost 20 years and
I'm only into the 4th chapter of this book.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read those two:
link1
link 2

Hope, you'll find an explanation there.
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:Read those two:
link1
link 2

Hope, you'll find an explanation there.


Jackpot!


The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.


-Rob
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm. Is this the sentence you were looking for or the sentence you did not understand ant wish to receive an explanation ;) ?
 
Rob Findlay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pawel Pawlowicz wrote:Hmmm. Is this the sentence you were looking for or the sentence you did not understand ant wish to receive an explanation ;) ?


Well as much as it makes me sound like a simpleton, I just didn't get that the parameters went into the " () " section of the function and how they were formatted. This basically opened the door to "seeing" how it worked.

It's still a bit murky but I now have a point to work from.

Thanks again lads!

-Rob
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!