• 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

what is the most effective way to learn to code?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just started learning Java in college and going to be a CS major and eventually want to get my MS in CS. My question is what is the most effective way to learn to code? i will learn C++ as well and who knows what else later down the road. right now my classes at school are just lectures and a lab once a week. not much coding going on unless its on my own time so i want to know how to effectively use the time i do have. When i say im new i mean im super new haha.


This is a little thing i wrote just getting used to coding and typing it out and everything. nothing fancy obviously. any tips or pointers would be appreciated. thanks all!

 
Bartender
Posts: 7201
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the real world currency is almost never represented by a double but a BigDecimal instead. You might try to modify your code to use BigDecimal.
 
Mike Mo
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Carey. yeah i have been told by a few people to look into that now. wasnt aware that existed obviously lol xD i will be working on figuring all that out tomorrow after i get home from classes. i had a bigger program written but now both of my classes in BlueJ are saying no source so i might have to remake all of it. going to ask my prof if she knows how to fix that and call it a night for tonight. thank you again!
 
Marshal
Posts: 69843
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Open your folders and see whether the .java and .class files are where you think they are. Maybe stop using BlueJ (I have suffered from it in the past and have a disliking for it) and use NotePad++ instead. But the important thing is to move that code out of the main method and start creating objects.
You can see examples of BigDecimal in use here
 
Sheriff
Posts: 7108
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good style and indentation on your code!

Here's something to start doing in Java: declare local variables just before you need them.  Declaring all your variables at the top is not necessary.  So,

...becomes...
 
Mike Mo
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome to the Ranch

Open your folders and see whether the .java and .class files are where you think they are. Maybe stop using BlueJ (I have suffered from it in the past and have a disliking for it) and use NotePad++ instead. But the important thing is to move that code out of the main method and start creating objects.
You can see examples of BigDecimal in use here



yeah I just got out of my CS class and my professor explained what the issue was with my files not being found so I am going to try and fix that soon. Thank you for the welcome! so far this has been the most helpful and quick thing to get a response
 
Mike Mo
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Good style and indentation on your code!

Here's something to start doing in Java: declare local variables just before you need them.  Declaring all your variables at the top is not necessary.  So,

...becomes...



I can definitely see how much that would clean up my code. I didn't think about doing that even. didn't occur to me that I could ask for input, declare, and store a value all in the same line :P thank you!
 
Sheriff
Posts: 15801
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Mo wrote:Just started learning Java in college and going to be a CS major and eventually want to get my MS in CS. My question is what is the most effective way to learn to code?


This is a more general answer to your question. They say French is the language of love, possibly because of the beautiful ways you can use it to express that emotion. Code is just another way of expressing yourself not only to a computer but also to other people. At their core, computer languages are languages of logic and math. Java itself is an object-oriented computer programming language. To code effectively in general, you need to learn how to be logical, organized, and systematic, just as you need to be in other disciplines that involve math and logic. To code effectively in Java, you need to understand object-orientation.

The replies you've received from others like the suggestion to move code out of your main() method, to start creating objects, and the comment about good style and indentation all hint at the kind of logical, organized, and systematic thinking you need to develop. They are different ways of expressing your ideas in code more effectively.

I think you would benefit from reading the book Think Like a Programmer by V. Anton Spraul. That book is all about thinking logically and being systematic and organized. It also uses examples in C++ which you'll be learning as well in the near future.

Other books I'd recommend you read are Clean Code by Robert Martin, Refactoring by Martin Fowler, Effective Java Programming by Joshua Bloch, and Understanding the Four Rules of Simple Design by Corey Haines.  All these books go beyond basic language mechanics and touch more on the heart of the kind of thinking you need to master the skill of writing computer programs effectively. If you study and master the principles you'll find in these books, then I think you'll be well equipped to meet any challenges you'll have in your further studies.

Good luck.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic