• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Is it okay to have absolutely no clue on the first try?

 
Greenhorn
Posts: 9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi developers,

I am still fairly new to java programming. I have made really good progress so far.
But now I am stuck at one particular problem which makes me feel real stupid as i acnnot get my head around it.

I dont want a solution or anything, i just want to know, if it is okay to be stuck for some hours, mabe even a day? I am learning JAVA to maybe get a job as a programmer.
But things like that set me back and make me question myself.

Just as a side note, the problem i am confronted with is to wrote a code, that is able to calculate the factorial of a number that is input by the user.
Again I want to mention, that I dont want to be presented with a solution. I just want to know, if the feeling i have described above, is normal.

Thanks for reading and for your answers.

Best regards,
Jens
 
Marshal
Posts: 26300
80
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on what I've seen on this forum, yes, having no clue at the beginning seems to be quite common.
 
Bartender
Posts: 1202
22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that's pretty normal.

In my case, I had breakthroughs in chunks:  
"Oh... functions/procedures/methods/gosubs.  I get it now."
"Oh... recursion.  I get it now."
"Oh... using an OO class hierarchy to make my life easier instead of harder.  I get it now."
etc.
 
Jens Jensen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I was thinking too complicated where the solution was really just like when you sum up the numbers.



Somehow I was over complicating stuff in my head.
I was having a look at how devs in C use to write such programm and then I felt really stupid, as the solution is actually quite simple.

Beste regards,
Jens
 
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use Scanner#nextLine() when there are methods which will read the input as an int directly.
Don't try an input > 12 otherwise you will get a wrong result because of an overflow error. You can get up to 21! (I think) if you use longs instead of ints. If you want any more, you will have to use a BigInteger object.
And, yes, it is normal to appear clueless at first. Your code looks no worse than anybody else's, and it does actually give the required answer.

You can make your code simpler by losing the variable i and counting down while the input is greater than 0.

I tried your code on JShell and got an overflow error with a long for 21! Don't go over 20!
 
Campbell Ritchie
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to find out when overflow errors occur, try this method and similar.
 
Paul Clapham
Marshal
Posts: 26300
80
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jens Jensen wrote:Somehow I was over complicating stuff in my head.



Yes, that's another common thing that happens to beginners.
 
Jens Jensen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Don't use Scanner#nextLine() when there are methods which will read the input as an int directly.
Don't try an input > 12 otherwise you will get a wrong result because of an overflow error. You can get up to 21! (I think) if you use longs instead of ints. If you want any more, you will have to use a BigInteger object.
And, yes, it is normal to appear clueless at first. Your code looks no worse than anybody else's, and it does actually give the required answer.

You can make your code simpler by losing the variable i and counting down while the input is greater than 0.

I tried your code on JShell and got an overflow error with a long for 21! Don't go over 20!



Thanks so much for the constructive hints!
How can I determine whether I get wrong results due to overflow? When i insert 13 I now see that, but only because I used the calculator to verify. But in NetBeans i do not get an overflow error.

Thanks for the help!

Best regards,
Jens
 
Campbell Ritchie
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jens Jensen wrote:. . . Thanks so much for the constructive hints!

That's a pleasure

How can I determine whether I get wrong results due to overflow? . . . But in NetBeans i do not get an overflow error. . . .

Try the methods I gave you a link to earlier. You should suffer an exception if overflow occurs. Remember that overflow errors usually occur silently and you don't get any notification of them. Notice that calculating 12! gives you a result ending ...00 but after an overflow error, the result from 13! doesn't end 0.
It may be necessary to tolerate overflow errors in some circumstances; overflow may happen repeatedly whilst calculating a hash code but we ignore it.
 
Saloon Keeper
Posts: 23040
157
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First try, fifth try, whatever. Some things are harder to grasp than others. And the worst problems to solve are the ones that aren't really there.

Example: I spend 3 days ripping my hair out because code doesn't work right. Finally show it to the most junior programmer I can find. Who notices that the comma that I keep "seeing" in the code isn't actually there. Because I "know" what the code is so the flaw is invisible to me.

As far as basic understanding goes, the JavaDocs are often less than totally clear and very frequently don't mention exactly what happens in the edge cases. Which is why it's good to have resources like the Ranch that you can ask.
 
Campbell Ritchie
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:. . . the JavaDocs are often less than totally clear and very frequently don't mention exactly what happens in the edge cases. . . .

I think it's a bit of an exaggeration to say they very frequently don't mention edge cases. There are some things not clear: the naming of the methods Color.getRGB() and Scanner.nextLine() are two examples where you read the method name and that doesn't actually tell you what the methods do. But I think only a minority of documentation comments suffer such obscurity or inclarity.
 
Tim Holloway
Saloon Keeper
Posts: 23040
157
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Tim Holloway wrote:. . . the JavaDocs are often less than totally clear and very frequently don't mention exactly what happens in the edge cases. . . .

I think it's a bit of an exaggeration to say they very frequently don't mention edge cases. There are some things not clear: the naming of the methods Color.getRGB() and Scanner.nextLine() are two examples where you read the method name and that doesn't actually tell you what the methods do. But I think only a minority of documentation comments suffer such obscurity or inclarity.



No, they're very bad in particular about saying what happens when you submit parameters that are out of range or otherwise not "normal". And they assume you know what "normal" is, which leads to the classic "It worrks for me just fine" response when someone can't make it work. Because when you know how it works, you would never have thought to submit offensive parameters.

There's also a shortage of caveats like the secondary effects of closing a Scanner when it's attached to System.in.
 
Jens Jensen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

the funny thing is, that I cannot evaluate at all when it comes to the JAVA documentation.
I feel that I am still at the beginning with no deep and useful knowledge at all

What I am missing in the courses that I do is, besides that there are TONS of practices, not a single one provides me with a real life scenario, where the stuff I am coding might come in handy.
And nobody so far could give me a good example of program that is simple enough for a beginner to write yet still being used on a daily basis by companies etc.

So that is the point where I stand. The JAVA documentation itself looks like gibberish to me at that point, as i still am fighting with vocabulary and all the stuff.

 
Tim Holloway
Saloon Keeper
Posts: 23040
157
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't feel bad. Java is an industrial-grade programming language and so there's a lot to learn.

Back in ancient times, one of the popular programming languages was FORTRAN. There were something like 10 types of statements and a few math functions. That's it. Learn them and you're ready to roll.

The downside of that was that everything else had to be (re-)invented by you. Sorts, searches, file structures, everything. No support for strings, GUI (Not invented Yet), databases (ditto), Internet services (ditto). So it was easy to program but programs couldn't do much. Except launch spacecraft, anyway.

The actual Java core language isn't that much more complicated, but it comes with an immense amount of built-in support functions and there's plenty more extension functions as well.

So to put it plainly, Java for simple programs is like a sledgehammer for cracking nuts. There are other resources that are easier to work with when you don't need industrial grade security, maintainability and performance. Things like shell scripts and Python, for example.

I'm generally not well-informed about books these days. I get most of what I need straight from the Internet. But I think that maybe the O'Reilly "Java in a Nutshell" book might be useful to you. It's a good reference for basic Java with simple examples. Perhaps others have some recommendations?
 
Saloon Keeper
Posts: 7617
68
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Nutshell" books pack a lot of information between the covers but they squeeze out any hand holding, and often I would like to see more examples. If you are already struggling with introductory Java stuff I  don't recommend Nutshell books. On the other hand I've been away from it so long I'm not sure what I would recommend. "Head First Java" used to be the go-to book for beginners, but it is so old at this point that I don't know if it is still relevant.
 
Campbell Ritchie
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't used the Nutshell books for a long time; I found there was too large a proportion comprising simply quotes from the public API.
I still think HFJ is good, despite its age, but it is rather slanted towards cert exam questions. I might use HFJ and then go on to Horstmann, which used to be my favourite big book, but Horstmann doesn't write beginners' books.
 
Jens Jensen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:"Nutshell" books pack a lot of information between the covers but they squeeze out any hand holding, and often I would like to see more examples. If you are already struggling with introductory Java stuff I  don't recommend Nutshell books. On the other hand I've been away from it so long I'm not sure what I would recommend. "Head First Java" used to be the go-to book for beginners, but it is so old at this point that I don't know if it is still relevant.



I mean I am not really struggling. It is more like, I have to get my head around a few things first before seeing the bigger picture, if you know what i mean :-)
 
Campbell Ritchie
Marshal
Posts: 71730
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jens Jensen wrote:. . . . It is more like, I have to get my head around a few things first . . .

That is normal.
 
Sheriff
Posts: 16042
266
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Jens Jensen wrote:Somehow I was over complicating stuff in my head.



Yes, that's another common thing that happens to beginners.


It's common for *all* programmers, not just beginners. Complexity often comes from a lack of understanding. When you fully understand the problem and what a good solution is, you can usually find a way to make your initial tries much simpler.

This is why you shouldn't feel bad about overcomplicating things. It's a natural part of the process. If you accept that you probably are complicating things too much on your first try (or first few tries), then you will be in a better frame of mind to refactor your code to find better and simpler solutions.
 
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there! I am totally new to this community and an absolute beginner in Java; just wanted to share this course with you because I’m currently doing it and I think it’s absolute hardcore value for the money I paid for it ( I am NOT an affiliate of this product just a student of it) and it has a lots of coding practice exercises in it.
https://www.udemy.com/course/java-the-complete-java-developer-course/
Hope that helps out someone. Cheers!
 
Campbell Ritchie
Marshal
Posts: 71730
312
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ST: welcome to the Ranch

Most people speak highly of Udemy courses.
 
Steve Török
Greenhorn
Posts: 2
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:ST: welcome to the Ranch

Most people speak highly of Udemy courses.



Thanks! It seems like a great place to learn from like minded people!

Udemy is great if you carefully choose which course you take and it requires a lot of self discipline to learn on your own. I love it since I have no problem with that.

Thanks again!
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for asking your question Jens, I'm glad I'm not the only one!
reply
    Bookmark Topic Watch Topic
  • New Topic