wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Java, oh what art thou errors? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java, oh what art thou errors?" Watch "Java, oh what art thou errors?" New topic
Author

Java, oh what art thou errors?

Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Good evening fine folks. I am need of some schooling on the beginnings of Java. Just to give a little back story on myself, I have zero experience in programming. None at all, on any language and have recently taken interest in Java. I recently won a B&N card in a golf tournament and used it to purchase Murach's Java Programming, 4th Edition. I have been reading the fist chapter to better understand the ins and outs of OOP and tonight I felt it was time to start the exercises and learn this confusing language. After all, I am a hands-on learner, what better way to learn that working some exercises?

Okay, so to my problem: I am unsure if the issue is with NetBeans (which this book recommends I use) or with me just missing something. Honestly, I wish I could use Notepad++ so that NetBeans would not auto-fill stuff for me, but I will use it later once I get the hang of "how" and "why" what I am doing in my exercises works, so getting Notepad++ to work these classes and such is an entirely different issue altogether that I will not discuss here. Here is the code that is confusing me:



Lines 6 and 16 have the little red 'error' icon to the left of them. The first states "illegal start of expression" and the latter "reached end of file while parsing". Now I typed everything exactly as it is in the book, and the other examples have this very format, so I am unsure why "main" is giving me an error in Line 6 and the final error is confusing altogether, but it seems it is pointing me to an error of not closing the loop properly.

Honestly, I have been up all day (I am in the military, and no, I do not have a computer job, this is me just trying to learn Java since it just intrigues me so) and am too tired. I reach out to you all in hopes to find an understanding of what I am doing wrong so that I can improve myself now, and not keep making the same mistake over and over. Many of you will likely laugh at my inability to see an obvious truth, but hey, I would rather you laugh and teach me the correct way than wait until many exercises later where I have done wrong consistently and continue to do it. I am not a perfectionist through and through, but I do want to ensure I learn this language properly. I know I can do this, and I will continue to push myself to ensure I learn this language and put my knowledge and skills to good use.

Sheesh, I am rambling; good gracious, it is time for bed. To those who can and will, help, I seek your council.

-JTH


-Rodge
“Don’t call me a mindless new programmer, you overweight glob of grease.”
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Welcome to the Ranch!

Take a good, long, careful look at lines 1 and 2.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Hint: that's not the only problem, but it is the first.
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Ah, I see the first. I am already in bed, so will look into this tomorrow. So the error is likely the latter's resolve, but can you give me a little more on the other? Is it the main? Goodness, this is already turning out to be fun... I may be in trouble...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Carefully review your use of braces.
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Gah, twice? Nice!

Okay, going to try this on my Lumia:



Since my 920 can't compile, I will test this in NetBeans tomorrow. Good looking out! And thank you!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Why the braces on lines 6, 7, 9 and 10?
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

You know, I almost got out of bed to go try it without them or review the book for guidance on overusing them under the string, but I talked myself out of it. I am so new at this and my brain just won't stop asking questions. You really pushed my brain into thought mode, even as tired as I am and I appreciate the nudge. I will mark resolved tomorrow after testing a few ideas, but for now I must sleep. Good night, friend! Looking forward to tomorrow...
Mphatheleni Ernest Matidze
Greenhorn

Joined: Oct 10, 2012
Posts: 24

Every opening Brace "{" must be closed by "}" some we're when the code block ends.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7700
    
  20

Rodge Paroissiaux wrote:I am unsure if the issue is with NetBeans (which this book recommends I use) or with me just missing something. Honestly, I wish I could use Notepad++ so that NetBeans would not auto-fill stuff for me, but I will use it later...

My advice: Use it NOW and, for the moment, forget about Netbeans. Your instincts are spot on and, quite frankly, I'm very surprised that a book for beginners would start you out with an IDE.

IDEs are for productivity, not for learning; and you will miss out on some very important (and, I warn you, sometimes frustrating) stuff by leaping straight into an IDE. However, you will need to learn about the javac and java commands, and classpaths; and if your book launches you straight into an IDE, it may not contain information about them.

TBH, I'm not sure where to look for a decent tutorial for compiling, jar-ing and running from the command line - I've just learned it by osmosis - but I'm sure others here will have. The Oracle tutorials get you kick-started, but then seem to leave you to discover the rest for yourself.

Good luck.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Winston Gutkowski wrote:
IDEs are for productivity, not for learning; and you will miss out on some very important (and, I warn you, sometimes frustrating) stuff by leaping straight into an IDE. However, you will need to learn about the javac and java commands, and classpaths; and if your book launches you straight into an IDE, it may not contain information about them.


You know, I am not sure this book is aimed at beginner's of programming as much as it is beginner's for Java, so I will continue to reference the links here as needed. Yeah, I need to figure out this Notepad++ thing, it just seems easier to me in terms of how it all works, but following Murach's examples are far easier via IDE. I am still figuring it all out, this programming thing is tough...
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7700
    
  20

Rodge Paroissiaux wrote:I am still figuring it all out, this programming thing is tough...

Yup. For (perhaps) some consolation, read this.

Winston
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Winston Gutkowski wrote:
Rodge Paroissiaux wrote:I am still figuring it all out, this programming thing is tough...

Yup. For (perhaps) some consolation, read this.

Winston


Impressive. Finally, something that helps me see it the slow and steady wins the race. I am 33 years old. At 19 I joined the Air Force, and in six months, my time with them will be done. I have fought the war, deployed to hell and back, and given my all to the 'Force'. And in six months, when I break away from the only life I have known, I will get into college and focus on things I enjoyed as a child. I took a class on Turbo Pascal when I was but a Sophomore in HS and joined the military for that "computer" job, but it never came to be, my focus was put elsewhere on my skill set. My time is over. It is time for me to move on and be better at what I want. I want computer science. Not to be a "great", but to be great at it. Yes, I have forgotten much over the past 15 years, but hey, I can get my mojo back me thinks. LOL.

Given these criteria, my recommendations for a first programming language would be Python or Scheme. But your circumstances may vary, and there are other good choices. If your age is a single-digit, you might prefer Alice or Squeak (older learners might also enjoy these). The important thing is that you choose and get started.

So Python, looking at it, I am just more lost. Is this really a better place to start than Java? Or can I work on them both for learning's sake?

I thoroughly enjoyed that read, so thank you for that. Great read indeed!
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7700
    
  20

Rodge Paroissiaux wrote:So Python, looking at it, I am just more lost. Is this really a better place to start than Java?

You have to understand where Peter's coming from. He's looking at the business of learning a computer language emprirically; not from the point of view of someone who wants to do something with it (like, for example, getting a job ).

Or can I work on them both for learning's sake?

I wouldn't; at least not to begin with. We've already established that programming is tough - and I hope you understand now that there are all sorts of measures of "tough" - so dividing your energies at this stage is probably not a great idea.

However, you also need to understand that anything that I say about the merits of Java as a language are biased by my own C → C++ → Java career path - all of which have the same syntactic base, which meant that I had some "familiarity" with it before I started learning it.

It does have idiosyncracies though; and beginners often find it verbose. You'll probably find that you have lots of "why can't I do it this way?" questions which, unfortunately, are usually answered by "because that's the way Java does it". Hopefully, your military training will stand you in good stead when you run into them .

One possible parallel "language" that might interest you would be a scripting language like perl or bash. If you start using Linux you'll find the latter incredibly useful; and you'll be amazed at what you can do without a "proper programming language".

Sorry. I've been rambling a bit here, but hopefully you get my drift.

Winston
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Winston has given you some really good advice here. I'd just add some emphasis to learning how to do things from the command line without using the IDE as a crutch, and without the complexity of the IDE getting in the way.

Also, I'd advise to learn a "real" command line: as in a unix command line. Linux and OS X (my choice) give it to you natively; on Windows, you can approximate it with a tool called cygwin. (If you are stuck on Windows I would highly recommend cygwin over the anemic Windows DOS shell.)

And, thanks for your service (from a retired U.S. Army E7).
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7700
    
  20

Bear Bibeault wrote:And, thanks for your service (from a retired U.S. Army E7).

And seconded (from someone who has never had anything to do with an army, and isn't even American).

Winston
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Thanks guys, I appreciate that. Thanks for the mentions as well, will look into them. I had an old Dell lying around and put Linux on it, but two days later my wife asked me to give it to my daughter for her to learn and so I revamped it with Win 7 that came installed, so now it is her laptop and my delving into another OS just isn't possible right now as I do not want to run a virtual machine on my current setup. This is a pretty decent laptop, it is an ASUS K52J with a Core i7, 8GB DDR3, a WD Black 7200RPM HDD backed by a 1GB Radeon HD 6370M GPU. It isn't the best of the best, but it suits my needs and then some. It can crunch some numbers, so installing new software and such really doesn't bother me if I need it, but I am not a software hoarder; if I do not need it or use it, I uninstall it. Actually, a lot of the things I use are portable apps, I rarely install anything unless the need to do so is required.

Oh by the way, lookie here:

BWAHAHAHAHAHAHA!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Almost, looks like you still have an unbalanced brace.
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Bear Bibeault wrote:Almost, looks like you still have an unbalanced brace.


Hmm, Line 10 brace should be under the p in public static void, huh?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Rodge Paroissiaux wrote:
Bear Bibeault wrote:Almost, looks like you still have an unbalanced brace.


Hmm, Line 10 brace should be under the p in public static void, huh?


No, wait. Line 10 is correct: I didn't see the brace because it is so far indented.

A lesson in making sure your formatting is correct. Bad formatting makes code hard to read.
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

So all is well or is there an imbalance I must find?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Rodge Paroissiaux wrote:So all is well or is there an imbalance I must find?

What happened when you compiled it?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

It compiles fine. It does as it should, all three lines print...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Cool!

What I was pointing out was that on the first inspection of your code, I didn't even see the closing brace on line 10 because it's waaaaaaaaaaayyyyyyyy over there.

The brace should be spaced in using proper indentation. Otherwise, if things aren't where they should be, people find it hard to read the code.

And hard-to-read-code == bad-code, even it works properly.
Rodge Paroissiaux
Greenhorn

Joined: Aug 12, 2013
Posts: 22

Would you mind showing me proper indentation? I am curious how it is wrong.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

Here's what 99.9999999999% * of developers would expect. The only difference is line 10:


* The only "religious war" regarding braces tends to be whether they go on the next line (as you did on line 2), or same line (as you did on line 3). Either is correct (just different).
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Bear Bibeault wrote:* The only "religious war" regarding braces tends to be whether they go on the next line (as you did on line 2), or same line (as you did on line 3). Either is correct (just different).

only one is correct, not both. So pick on and stick with it - don't mix and match within the same file.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

fred rosenberger wrote:
Bear Bibeault wrote:* The only "religious war" regarding braces tends to be whether they go on the next line (as you did on line 2), or same line (as you did on line 3). Either is correct (just different).

only one is correct, not both. So pick on and stick with it - don't mix and match within the same file.

Yes, that. (I thought I had added a paragraph about consistency, but I guess not...)
 
 
subject: Java, oh what art thou errors?