• Post Reply Bookmark Topic Watch Topic
  • New Topic

Head first Java is quickly becomind a headwreck  RSS feed

 
Eoghain McGrath
Greenhorn
Posts: 2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I began reading Head first Java a couple of days ago because I want to learn Java and then program my first game.

I like to run all the programs myself, but so far I've only been able to run the basic ones at the start of the book. I'm at the end of chapter three right now, "Primitives and references". I compiled one of the exercises and got this error "C:\Java\Programs>java Books
Error: Main method not found in class Books, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application"

Here's my code. If anyone could direct me towards a solution, that would be great. Cheers.



 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

The problem is exactly what java tells you.
Class Book you are trying to run does not have main method.
Your BooksTestDrive has one. So maybe you could run java BooksTestDrive ?
 
Eoghain McGrath
Greenhorn
Posts: 2
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote:Welcome to the Ranch!

The problem is exactly what java tells you.
Class Book you are trying to run does not have main method.
Your BooksTestDrive has one. So maybe you could run java BooksTestDrive ?


Thank you Pawel. I didn't realise you could run different classes within a file. It's working now.
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I keep getting the same error in my Java programs. Can you explain to me exactly how to fix this please ?
Use the original code on here as an example. Pretty please :-)

Regards,

Caroline
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caroline Thom wrote:I keep getting the same error in my Java programs. Can you explain to me exactly how to fix this please ?

I think Paweł has already explained. The class you specify on the command line has to be the one that contains the main method.
So in the case of the original post the command line is
java BooksTestDrive
and not
java Books
because the BooksTestDrive class contains a main method and the Books class doesn't.
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joanne,

Sorry, I'm pretty thick with java. Although I do 'think' I understand what your saying. However when I copy the code into Eclipse an run the program I get the same error.

Can you show me how the code should look, so it runs and without the error.

Apologies for my serious lack of knowledge. i should know more than this by now at my level of study :-/

Regards,

Caroline
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me again :-/

Well that was weird, several of my programs didn't run before and showed that error about main method and now suddenly they are running !! I swapped my installed JRE's from Java\jre1.8.0_25 to \Java\jre7 by adding \Java\jre7 into the installed JRE's list, the programs still didn't work so I swapped back to the original installed Java\jre1.8.0_25 and suddenly hallelujah my programs work as they should with no error as before. Same error mentioned in this thread. Now am I thick or Eclipse playing tricks on me now ???


I haven't altered any of the code at all ??

Any explanations of this, would be most welcome. I find Java hard enough without these things confusing me more !!

Regards,

Caroline
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds as if you're just starting out with Java. Based on that, I strongly recommend not to use an IDE. IDEs are great, but they hide things from you that you simply need to understand, or you will struggle for a lot longer than necessary. You may wish to read http://www.coderanch.com/how-to/java/IdeFaq for some elaboration on that.
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Well I do struggle with Java much more than I think I should really. I've been trying to learn it for a few years now (OUCH) and still getting really baffled by some simple things. I am in my 3rd year of a BSc Honors Degree in Computing and have a few hefty Java projects to try and smash too in not too much time so really need to get up to speed and quick.

Any help or advice appreciated. I will look at your link definitely. Thankyou :-)

Regards,

Caroline
 
Ulf Dittmer
Rancher
Posts: 42972
73
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eoghain McGrath wrote:I began reading Head first Java a couple of days ago because I want to learn Java and then program my first game.

Ooof. Just a warning: You've set yourself quite a task.

I have to admit to being biased, because I detest GUI programming; but I'd suggest that you choose your "game" very carefully if you don't want to get frustrated. You're not going to be programming "Mario" or "Doom" anytime soon. Tic-tac-toe or Nim, on the other hand...

I certainly don't want to put you off, but you might want to read this cautionary tale. Programming can be a long and rewarding career (or hobby), but you need to take one step at a time.

Winston

[Edit] Just noticed that the OP was from July, but I leave the post for Caroline in case it helps.
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Winston,

I totally know what you're saying. I've only been learning Java for 2 years now and I think I do know the basics now although I seem to be afraid to try and tackle my own problems when it comes to creating my own program. I watch YouTube tutorials, read Java apps and do quizzes, bought tons of books (including the Sams teach yourself in 24hours - well thats from library actually) and it all helps. I look at source code online and try to run it and understand it. Something IS going into my brain, but what I'm not quite sure. However i do enjoy the challenge and am determined to carry on trying to learn.

I have to agree, it seems the Eclipse IDE although great does seem to confuse the heck out of me at times and does inexplicable things, that make no sense to me. I seem to waste a lot of time trying to understand these things.

Thanks for your link anyway, all help is useful to me :-)

Regards,

Caroline
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caroline Thom wrote:I have to agree, it seems the Eclipse IDE although great does seem to confuse the heck out of me at times and does inexplicable things, that make no sense to me

Corollary to Clarke's third law: Any sufficiently advanced technology that fails to work as expected is always blamed for being stupid.

Now don't take that the wrong way; I'm always calling MS Word and Visio stupid when they don't do what I want them to do. If we're going to anthropomophize them anyway, computer programs actually are pretty stupid sometimes. However, if you really think about, the problem really lies in the differences of expectations on the parts of the developer(s) of the software and it's users. That's why starting out on the command line is a good thing for you to do because you will gain a better understanding of the tedious things that Eclipse does and eventually hides from you. Even as I type this on my tablet, I have called the autocorrect feature a dumbass (it just now replaced that with "dumbest") several times already.

I had to patiently explain to my daughter how the clutch on a car works so that she could comprehend why the car would jump and sputter out when she'd let the clutch out too fast. It took a while to get past all the eye-rolling but once she finally listened and understood she was off and running fairly smoothly.

So pull out that stick shift and give it a go on the command line first.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caroline Thom wrote:I have to agree, it seems the Eclipse IDE although great does seem to confuse the heck out of me at times and does inexplicable things, that make no sense to me. I seem to waste a lot of time trying to understand these things.

It might seem like it sometimes, but I doubt that you're actually wasting your time. The mere fact that you've been at it for 2 years says that you're plainly prepared for a long haul.

One book that I can definitely recommend without question - especially if you've put in 2 years - is this one. It's not for complete beginners, but it is, bar none, the best "why to" book I've ever read about ANY language.

You also don't have to read it from cover to cover, because it's arranged in chapters and "topics". I believe it's also available in PDF form now; although I have to admit that I prefer good old-fashioned paper - in fact, I'm on my second copy now ... after the first one basically fell to bits from so much use.

Maybe I should start a "Joshua Bloch for Sainthood" campaign.

Winston
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Winston,

I appreciate the recommendation, I will definitely purchase this book. And I too, prefer books to e-books :-)

Maybe I'll get through this 3rd final year of my Degree after all ....

Regards,

Caroline
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . .
One book that I can definitely recommend . . . is this one. . . .
Agree.

Also try another Joshua Bloch boo, written with Neal Gafter: Java Puzzlers.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caroline Thom wrote:I appreciate the recommendation, I will definitely purchase this book. And I too, prefer books to e-books :-)
Maybe I'll get through this 3rd final year of my Degree after all ....

A couple of others for you; although I'm quite sure that others may have more "up-to-date" or "readable" recommendations. These are simply the ones I was "brought up" with, and you'll find they're often quoted in other publications:

For algorithms: this one.
For design patterns: this one (the authors - and sometimes the book itself - are often referred to as the "Gang of Four", or simply 'GoF').

And just for "background reading": this one - although I warn you that a lot of it may go over your head (as it did mine). This chapters that you can follow are well worth reading though.

HIH

Winston
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have thought that the first two are required reading for CSc students. They're quite dense though, especially Knuth's, at least that's been my experience whenever I've tried to read him. I really like the Beautiful Code book though. At the risk of overwhelming Caroline even more, I offer my standard recommendations to read Robert Martin's Clean Code book and other related books about unit testing and Agile development in general.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:They're quite dense though, especially Knuth's, at least that's been my experience whenever I've tried to read him.

Because he's a bloody mathematician. (pause ... wait for Piet's response ... )

Damn fine one though; and I've usually found that after a second or third read-through, something finally "clicks" and I "get it". But your point is well made.

Winston
 
Caroline Thom
Greenhorn
Posts: 18
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Thankyou for all the recommendations. I've bought sooooo many books already it's almost a little ridiculous, but I will buy more. I appreciate being pointed in the right direction or in a direction that has proved helpful for others/yourselves.

I quite like having a huge library of my own anyway.

My project at University is called Face Manipulation. I have to manipulate a facial image in Java Code so that the face changes expression and possible get two facial images to morph into one. Do you think I've got my work cut out for me .... I do !! So confused. I got to get my Literature Review in this Friday, got Literature coming out of my ears !! haha

Regards,

Caroline
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Caroline Thom wrote:Do you think I've got my work cut out for me .... I do !!

Me too. Sounds like a fun project though.

So confused. I got to get my Literature Review in this Friday, got Literature coming out of my ears !! haha

About the only thing I can suggest there is to take it one step at a time, and try to break down the problem into manageable chunks.
I honestly have no idea what face-morphing involves, but I suspect that you might be able to divide a face up into various "parts" or muscle groups so that, for example, you may be able to work on just the nose or the eyes, and get those working before you start adding in other "bits".

The feeling of helplessness often comes from thinking that you have to understand everything before you start; and the fact is that you rarely do.
You will need a good idea of WHAT you need to do, but not necessarily HOW you're going to do it (ie, the actual code); and Object-oriented languages like Java have lots of tools to help you put off coding decisions until you're ready to tackle them.

One specific technique (stubbing) is described in this page. It's meant for beginners, but it might help you to see that you don't necessarily need to know how you're going to implement everything in a class in order to create one.

And a couple of others that may help: WhatNotHow (←click→) and StopCoding.

Good luck - and remember: The Tortoise beat the Hare.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!