• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Should I write my own code ?

 
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm reading Head First Java. There're various code examples like battleship etc.
Should I try to understand the logic followed in the book or try out the problem with my own flow ?
Which is a better approach ?

Thanks
 
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are learning the basics, you really need to write your own code. If you have time, you can download what they have, see that the concepts really do work (and build confidence in the language, environment, etc.), and then proceed to write code of your own. You could also (blech??) hand type what they have, to give your fingers the experience of having done that. Sounds like a waste, but it can be valuable. It forces you to look at the code more so than if you just try and read it.

When studying for depth, I like to write little programs that exercise one concept at a time, and then build up from there.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm finding it hard to understand their logic that's why I was thinking to write my own code.
 
L Foster
Ranch Hand
Posts: 270
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are having trouble understanding their logic, then please try the "very short program" suggestion. Take one little part of what you see, or are reading about. Then run it in a little skeleton. Here is a skeleton you can borrow, and insert fragments of code:



In order for this to work, you have to save it in a file called "MyCode.java", use javac Mycode.java and then use java Mycode to run it.

Sorry if I've oversimplified things here. I don't meant to insult.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you should first analyze the logic in the sample code in the book. After you see the output of that code, you can make your own code that is similar in output with what is in the book, but with different logic, what I mean is, the output is similar but the way you used to do that is not a copy-paste from what is in the book, the shorter your code is, the better, as long as it is correct and similar with what is in the output of the book.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

L Foster wrote:If you are having trouble understanding their logic, then please try the "very short program" suggestion. Take one little part of what you see, or are reading about. Then run it in a little skeleton. Here is a skeleton you can borrow, and insert fragments of code:



In order for this to work, you have to save it in a file called "MyCode.java", use javac Mycode.java and then use java Mycode to run it.

Sorry if I've oversimplified things here. I don't meant to insult.



np.. It's actually a very good way to tell new people. I don't think most people who already knew would be offended and it'll be a blessing for new learners.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jaypee Hernandez wrote:I think you should first analyze the logic in the sample code in the book. After you see the output of that code, you can make your own code that is similar in output with what is in the book, but with different logic, what I mean is, the output is similar but the way you used to do that is not a copy-paste from what is in the book, the shorter your code is, the better, as long as it is correct and similar with what is in the output of the book.



Thanks. I find this approach helpful. Write your own and then compare functionality with the other code.
 
Shubham Semwal
Ranch Hand
Posts: 176
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

L Foster wrote:

Sorry if I've oversimplified things here. I don't meant to insult.



np.. It's actually a very good way to tell new people. I don't think most people who already knew would be offended and it'll be a blessing for new learners.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic