As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
If this question can be reworded to fit the rules in the help center, please edit the question.

15 Answers
15

but some people don't learn well that way, and prefer something more formal, like going on a training course, something I can't sit still for, though as an ex-instructor I used to be glad that many people feel otherwise.

I've done something interesting and tried to rewrite my IRC bot in the new language. This allows me to learn several things including

Using whatever GUI framework the language uses

Using things like sockets, streams, etc

Synchronization

OOP style (if the language is OOP)

Multithreading

Do things dynamically (for plugins)

If I'm doing it correctly when I solicit a code review.

How to use other frameworks

In java, this is pretty much the extent of any SE desktop application. In PHP (yes, I did this in some awful looking PHP that I abandoned), I learned many interesting things, mainly that PHP was not made to do that.

Using this can give you great insight into the many features of the language. It can also be fun sometimes.

This is a duplicate, as I remember answering this not that long ago, but for me it depends on the language and whether I need to learn just the languages or completely new ideas as well.

With a language like Haskell, which I considered hard given that it was quite different to what I was used to, I started with book learning. Practical experience is however essential, but rather than trying anything ambitious from scratch, I concentrate on small modifications to existing code.

With easier languages like Ruby, or indeed Java, I may do a tutorial, then I would try and write an app from scratch. When I come up against any walls, I just surf around for answers, or ask here, and the learning comes with experience.

The most important thing for me is always to find something I really want to do with the new language I intent to learn. Otherwise its difficult to be really motivated. But once I have an idea for something I go read tutorials and articles on the language and start building my project learning as I go.

I used to read many books but today with stackoverflow and the tutorials everywhere I find my self needing them less and less.

I personally still have a copy of the NetflixPrize dataset that I write algorithms in said language to solve or just goof off with it, in general. Unfortunately, the dataset is no longer publicly available (at least officially from Netflix themselves).

Regardless, find a fun project that you have a good idea what you need to do to complete it and solve, and then learn that language and platforms facilities and best practices for solving it. Once you've gotten your feet wet, then branch out and start new projects with the language/platform you are learning.

I have gotten into new languages by coming up with a project. Maybe something you have already done in another language or something you would find useful(like a programming tool). Then try to write it in the language you wish to learn, at first using just what you understand about the language and can glean from books and websites. As you get the project to completion start asking in the community for someone to look at your code and ask questions for what appear to be problem areas.

It is important to realize that a language is usually very general while a problem will give it context. For instance I may know how to develop Java applications, but that does not mean I know how to develop J2EE applications. Same language, different context; so you may wish to think about that while coming up with the learning project or projects.

I also highly recommend building the project with very heavy unit testing. Writing unit tests is going to give you a solid set of tools that they will not be showing you in the books, your code will improve and more importantly any unexpected language idioms will stick out like a ... well like a failed test.

For me: I learn a language by just starting a project. I learned C#.NET this summer by starting a web project on C#. When I get stuck on something, I either google it or just benefit from stackoverflow!!
If you don't feel confident: start a mini project with Java and see how it goes!

If you're in the very early stages of learning to program, then I think it's more didactic to play with what you've learned as you go through the book. Don't wait until you finish reading it to get some practice. You can understand the knowledge, but being able to apply it adequately takes a lot of practice. And it's easy to forget what you learned a week ago, if you don't exercise it.

So what I usually do when I'm learning a new language, is to try to solve some problems with it. That helps me a lot to evaluate how far my understanding of the language is, and also helps me discover the in-depths of the language. Examples of problems I try to solve when I'm learning a new language:

If you never had any experience programming, I don't think it's a good idea to start a project where you'll find yourself getting stuck most of the times and requiring the assistance of google or stackoverflow.

Rather, get a book, go through each example, try some end of chapter questions, type the code from the examples and think of creative ways to modify the program according to your needs.
You can also supplement your learning by watching the video lectures provided by Stanford's Engineering Everywhere or MIT's OCW.
In your case, Stanford's first free video lecture series starts with Java, goes on to C++, then deeper to MIPS and some scripting languages.

read book that talks about same thing (ex Java intro, Java for beginner, Java head-first etc)

The reason is they talk about same thing but use different examples and different coding style sometimes so it helps me understand the varieties of way of coding. Also often one example is not really enough to fully understand what's really going on when you get stuck.

read codes that other people write.

Go online and search for the code you looking for, they write in different way and you will find which approach has what pros and cons.

join forums and get involved in discussion.

Make sure to spend sometime before you post questions. People don't like easy solution seeker. I usually spend couple hours searching for answers and if I can't figure out, then start asking online with as much detail as possible so I get the precise answers.

Do you have a computer science or programming background? If not, it's important to learn on data structures and algorithms as well as the actual language. There are many free resources out there, and while the book will help you, you may want to consider taking a CS course to help with some of the concepts.

If you (or anyone else reading this question) is interested, you can check out This site for an intro to computer science. There are also a lot of other good courses on opencourseware. This class in particular is all streamed or downloadable videos of lectures with assignments, tests, and quizzes, all 100%, and from MIT teachers.

I usually google for the best book possible (a one with most recommendations) and I scan through it very fast, just to get the general idea of the language, good practices etc. Then I either think off or google a program which would be able to cover everything you can possibly do with that language (well OK not everyting, but as much as possible). Like when I was learning Java EE (JSP, Servlets, JPA) I decided to write a simple hangman game, first I'd do the basics, then I would add the database etcetc. - first I did a very basic program, then I added more and more. Of course I while writing it I would always google for good practices, because you can code something and it will work, but it might be hell to maintain it in the future etc.

I think that writing stuff in a language you're learning is the most efficient way if you execute it right.