Take the 2-minute tour ×

Possible Duplicates:
I still can't figure out how to program?

I don't known if you guys have super brains specifically for programming but I would like to know how you do manage to learn, understand and apply Java programming. I am in grade 11 and we have learnt statements, objects, classes and arrays. We get programming test each week and I'm failing them. Now we have a project to do BlackJack using a JPanel form. Also memorizing the while loop is not the problem; I think that the problem is applying it to the situation (my friend never programs the same way as the teacher but still gets the same results).

share|improve this question

marked as duplicate by Mark Trapp Oct 16 '11 at 20:55


As for your friend writing a program that looks different but gets the same results: A program is nothing more than a set of instructions and it's quite possible for different sets of instructions to give the same result. As the old (Perl) saying goes: "There's more than one way to do it!" –  FrustratedWithFormsDesigner Apr 11 '11 at 20:04
Practice? If you've used a while loop countless times, you won't need to memorize it... –  Cameron Apr 11 '11 at 20:04
My father put me in a boat, took me to the middle of a lake and threw me into cold water. He then threw a laptop at me and told me to fix a bug in 2 minutes or else ... After I fixed it, and after the nervous twitch went away, I learned to believe in myself. –  Job Apr 11 '11 at 21:39
@Job you didn't die from that? –  alternative Apr 11 '11 at 23:54
@Mathepic i think he means to convey the point of right situation and proper motivation @ Mpumi Check this I still can't figure out how to program!. –  Aditya P Apr 12 '11 at 2:10

9 Answers 9

You learn to program by programming. There really is no substitute for experience. After you've solved enough problems, you start to make mental associations. Then you encounter something you have to do, and it's conceptually similar enough to something else you did earlier that you realize you can solve it in basically the same way you did the other thing.

There are really only two parts to programming: Having a repertoire of solutions to problems, and the analytical ability to break down a large problem into smaller sub-issues, and then break those down further, until you turn them into individual pieces that you have a solution for. Both of these skills are built up by experience.

EDIT: Let me add one more thing. If you really want to learn to be a good programmer, think of programming skills like muscles. They grow bigger when you exercise them and push them to their limits. Keep looking for new problems to solve, things you haven't done yet, and learn how to solve them.

share|improve this answer
I think to be a good programmer, as well as what is mentioned in this answer, you have to have a passion for what your doing. Passion will keep you coming back to tackle the bugs time and again after all those inevitable times when you can't figure it out. I think one of the best ways to get good is to find a nice small project and start contributing to it as best you can. You will improve over time. –  Jeff Welling Apr 12 '11 at 1:38
Programming requires problem-solving skills, which it's hard to learn. so hard do I learn that?. I known everyones saying practice but what must I practice if I don't known what to do. Must I redo the problems the teacher has given me and when I get stuck look at his program –  Mpumi Apr 12 '11 at 20:49
@Mpumi: That's a good place to start. But make sure that you only look at the teacher's program when you're really, honestly stuck. And when you do look at someone else's work, (the teacher's or anyone else's,) make sure that you understand what you're reading and why it works. This is something I cannot stress enough. When you write code without understanding why it works, you will have no idea what's going on when something goes wrong, and you'll have a very difficult time fixing it. –  Mason Wheeler Apr 12 '11 at 21:22

There are two key areas:

  1. Problem solving (Understanding the problem at hand and how to solve it)
  2. Abstraction (Understanding how to generalize and separate the solving of a task, this is very important in OO languages like Java)

Some of these naturally come easier to some people just like Math or English might come easier. If it is something you struggle with then the solution is more practice just like learning Math.

share|improve this answer
Problem Solving. The problems are always different so how can I improve in problem solving? –  Mpumi Apr 12 '11 at 11:50
@Mpumi, by not memorizing solutions. Continuing with the Math analogy ever Math problem is different, you don't memorize every possible calculation, you learn what calculations exist and with experience and research you learn wisdom on when to apply each calculation to get to your goal. –  jzd Apr 12 '11 at 11:57

It's very good that you're asking for help. The key to learning to program is

  • Have something you want to do with it that's fun, and that is very simple.


  • Write a program that randomly insults people, like "What's your name?" "George" "Hi George, you are a snivelling snob!"

  • Write a program that helps your parents keep track of the phone bill, minutes and text and all that.

  • Write a program that makes a ball bounce around the screen, and then maybe make it play pong.

Memorizing is not a good way to learn programming. If you have something you want to do, you will realize the purpose of each piece of the language.

ADDED: Ok, if you really don't know where to start, I used to teach this stuff so let's see if I can help. It was 30 years ago, so we used BASIC for introductory programming, later going to a structured language. Now people will jump all over me for this, and you can get bad habits from BASIC, but I still think it's good for when people are starting from nothing. Maybe you can do the same thing in Java, I don't know.

You write and play with a series of programs, such as:

  • A program that prints out a greeting to you. This will teach you how to print a string.
  • A program that asks you your name, and then prints out a greeting to you. This will teach you how to input a name into a string variable, and how to use that in a print. You will learn that a variable is like a named container, and what it contains is a number or a character string, and it's name is different from what it contains.
  • A program that asks you to enter a temperature in Celcius, and tells you the same temperature in Fahrenheight, or vice-versa. This will teach you simple assignment statements and the use of numeric variables and calculation. Hopefully this will also impress on you that the computer doesn't read your mind, a program is made out of simple pieces like a construction set, the order of statements matters, and each statement cannot be started until the previous one completes. (Some newbies think that since the computer seems to be so quick, it must be doing everything all at once.)
  • A program that prints out a random integer between 0 and 9, or between 1 and 10, take your pick. In order to do this, you will need to generate a random number and manipulate it to the range you want.
  • A program that prints out 100 random integers between 0 and 9 (repeats allowed). In order to do this, you're going to have to code a loop, with an index variable, unless you want to repeat the code 100 times, which I hope you don't.
  • Now you can do the insult program, where you input the user's name, make a random number, use the random number, along with one or more IF statements, to select a disgusting insult, and print it back to the user. Then you can use a loop to make it do this over and over, if you like.

At this point, you have used print statements, input statements, string and numeric variables, assignment statements with calculation, IF statements, and looping statements. Pretty good!

  • Now you're going to hit a speed bump - arrays. Make a program that holds 10 numbers in an array variable, and adds them up, printing out the sum. For example, rather than have 10 variables named something like A0, A1, A2 ... A9, you can have a single variable A that holds 10 numbers (rather than 1). You refer to the individual numbers in it by indexing. So instead of saying, for example, A2, you can say A[2]. What's more, if you have another variable I containing a number, then A[I] would use I to decide which number in A you want to pick out. Then if you have a loop where I is the index variable, maybe you can see how you can add up all the numbers in A with only about 3 lines of code.

There are more speed bumps, such as file input/output, subroutines (sometimes called functions or methods), and all into more modern stuff. But hopefully that will get you started. As I said, you need to quickly get enough of a skill base that you can consider doing some simple but fun project, such as your black jack.

share|improve this answer
I want to jump in the pool but I can't swim so what do I do. For example I want to do the game black jack but I have no clue where to start so what do I do. –  Mpumi Apr 12 '11 at 11:54
@Mpumi: I'm editing a response. –  Mike Dunlavey Apr 12 '11 at 17:11

It sounds like you're not fully understanding some of the fundamentals. In computer science classes after they get past the basic concepts like assignment, half the students tend to catch on, where half the students fall behind, there are two separate curves. Thats because half the class learned just enough of the fundamentals to get by, they cut and paste code from the book, but they don't really understand it; then they have to write harder code and they hit a wall.

It sucks, but there's no other way. Since you're learning programming in a class, you should have a textbook. Go back to the earlier chapters of the textbook, and read through them. Then, try, yourself, writing some REALLY simple programs to test what you know, and slowly make them more complex and utilize all the different concepts.

You mentioned memorizing the loop isn't the problem, but how to apply it. Well, there's nothing TO memorize with a loop, unless you mean the syntax. What you need to learn, what you need to understand, is EXACTLY what the loop does, and what you can use it for.

If you're asking whats the best way to learn to program: You're already doing it. Get in a class, with a structured curriculum that you have to keep with, so you don't end up blowing it off or skimming a book.

I cannot stress enough. Knowing the difference between if(i = 10) and if(i == 10) is everything. Knowing your fundamentals is everything in writing code, understanding algorithms, and learning computer science.

share|improve this answer
Thank you Zaphod42 but I think I understand what the loop does. The problem is how do you known where to use it in a situation given? When my teacher does the program and explains everything I think I understand. however, when I have to do the program myself I don't really known whats going on. How do I build up that understanding and knowing how to modify the loop in a different situation/problem given. –  Mpumi Apr 12 '11 at 12:04
@Mpumi - If you understand what the loop does then you should know when a loop is an acceptable way of solving the problem. –  Ramhound Apr 13 '11 at 14:32

Here's why your friend is able to write programs differently than your teacher. He either now or at some-point prior (I wasn't sure if he had prior programming experience) took the time to not just learn how to replicate the program but also understand what the commands are doing. I'm sure he (whether it was conscious or not) asked himself every time the teacher put up an example, "what is that doing?" Perhaps he even asked himself right then what another way of doing it would be.

The worst possible thing you can do as a programmer is memorize a solution for a problem and not also understand what is happening. If you understand what is happening then you can always recreate the solution even if you have forgotten it otherwise. You can also generally modify the solution to meet other needs for other problems. If you only memorize the solution but take no thought at how it works or why its the solution then when you forget it (which you likely will), you won't be able to reuse it later.

Aside from gaining full understanding of the code you see/write, the biggest thing you can do to improve is practice.

share|improve this answer
Thank you Kenneth. I think I understand it when the teacher explains and I have the solution in front of me but when it is time for me to do the program I am lost? How do I practice if I don't known whats going on. Must I do problems without looking at the solutions and when I get stuck look at the solutions? –  Mpumi Apr 12 '11 at 21:13
Do you write down what the teacher does (code with corresponding output)? If you do I would recommend looking at that and trying to understand why the output results from the code. If you're not writing this stuff down you need to. Once you feel you understand it try to recreate it on your own without looking at the notes. Really with learning you always need to have two parts... Understanding and the ability to recreate the program on your own. If you can do this you should find it easier in time. I would also recommend running your thoughts on how things work past your teacher too. –  Kenneth Apr 13 '11 at 0:31

The journey of a thousand kilometers beings with a single step!

How do you build a house? How do you make a clay pot? How do you write an essay?

What is the common most basic way to answer those questions?

You get the right materials, and tools to construct the object.

house = bricks / wood / mortar / nails
clay pot = clay / water / glaze
essay = paper / ink / idea(Topic) / vocabulary / research

house = spades / hammer / saw /
clay pot = potters wheel / hands
essay = pen / command of the language used to write it / structure (introduction, conclusion, body)

It always amazes me to see how all house are built with the same things, but some are better then others. The are works of art while others you would not feel safe in and should be torn down. It comes down to the skill of the workers in using the materials and tools together and solve problems of building a house. Some houses are works of art, and that comes down to how well they can express their creativity with those components.

I would break down you problem into two areas. One is understanding the tools and materials you need to build a solution to a problem. And two is how to solve a problems. In programing the material we use at the simplest form is down to these things SSI (sequence, selection, iteration):

sequence = what order do you execute you instructions. Example from maths is (BODMAS) Brackets of Division multiplication, addition subtraction. You have to do some things before others.
selection = if statements, functions, methods how do you move around in your code
iteration = loops how do you repeat some thing.

Those are the building blocks, of a solution to any problem that can be expressed as code. Know you material, its strengths and weaknesses. How it works. This is the basics of all programing. It changes names from language to language but the essence remains the same.

The tools your computer, key board, monitor, compiler, text editor(IDE), API(application, programmers interface) and most importantly creativity / problem solving.

The place where a lot of new students struggle is with the problem solving. They have all these materials they just learnt about in sequence selection and iteration. They just don't see how to build the house or write the essay with them. The solution to that problem is to stop thinking about the material, ie do I use a loop or an if statement. You need to think much more abstractly about the problem. Break it down into the pieces.

  • I need to print the contents of the file
    • I need to get the name of file
    • I need to get the file from the hard drive
    • display the contents
  • Ask the user to make a chose (delete, save, change)
    • I need a menu to display the choices
  • perform the action( delete, save, change)

It is too easy for new students to get bogged down in details and they do not clearly see how to solve a more complex problem that is longer then a few lines. Problems that require you to think about the over all structure of you code. It becomes difficult to see how you solve the problem(creatively) and with what you solve it with(code SSI). You don't solve the problem with the materials (SSI). You solve it with the right tools together with the materials.

When your start writing an essay you don't think about how long a sentence should be, what words to use. You think about the topic how you want to cover it, what sections you will break up the content into. Only after that do you sit down and think about the first sentence, the introduction paragraph, the conclusion paragraph. What words you are going to use. You know how to do this because you have practiced, you have been taught the components of an essay. Programing is no different.

On a different note. One of the best things you can do is learn to type faster, get a typing tutor. There are a number of free ones on the internet. This will help with every aspect of your problem solving, and using materials and experimenting with them. http://steve-yegge.blogspot.com/2008/09/programmings-dirtiest-little-secret.html

it is not going to happen over night.

share|improve this answer
Thank you nelaar. Programming requires problem-solving skills, which it's hard to learn and the most important according to you. So how do I learn that? I known some people are naturally good at that like my friend but is it possible to develop that skill. He also remembers how to type the for loop and modify to different situations but I don’t even known how to memorize the for loop I always have to minimize my window and look at the word document with the for loop. –  Mpumi Apr 12 '11 at 21:10
When your learning a language you keep a dictionary next to you help you with words you don't understand. It is fine to keep a reference next you of the programing language. Learn to use the help systems that are available to you. To check and recheck that you have got things right. –  nelaar Apr 13 '11 at 5:27
@mpumi How to problem solve, don't think about every thing in one go. Break down the problem into parts that you know you can do. Do those parts. Take the poker game. Start by getting a program that just brings up the window. then the window with a single card. Then every Every time you click on the card it changes. Next try and get it to display two cards. Don't try and write the whole program the first time you sit down. Set you self a small goal. Like change the back ground colour of the window and that and check it. The get it to change the back ground colour when you click on it. –  nelaar Apr 13 '11 at 5:32
@mpumi sounds like an African Name. I am a South African. Google nelaaro, to find me and send me an email if you want more help. –  nelaar Apr 13 '11 at 5:34

It really helps if you love doing it. Before I started my degree in computer programming, I hated any reading that was for school, but now I willingly read all my programing books and then some. I also do work through extra problems to help understand new concepts and help other students in my free time. You can't just put half your heart in.

I would suggest spending a day catch up with the class, do all the reading and work through what you don't understand, then if you are still having trouble talk to your teacher, they are usually willing to give you more time if you are putting in the effort.

share|improve this answer
Thank you Justin Stryker I just don't like doing something I don't known how to do. –  Mpumi Apr 12 '11 at 20:50

Practice is your friend here. The other thing you want to do is understand what each line in the program is doing. There is a lot to under stand so don't try to do it all at once. Learn to break the problem down into a bunch of small chunks and figure out how to do each one, then put them together. (Really that is the heart of programming).

What I would say if you are banging your head on Java try something else, Ruby, Python or Scheme might be good choices. Specifically I would look for the book "The Little Schemer" its a nice little introduction to some concepts.

Oh and if you get stuck ask the teacher for help, thats what he/she is there for!

share|improve this answer
Thank you Zachary K –  Mpumi Apr 12 '11 at 20:51

I think the best way to learn programming is to immerse yourself in it and make it your passion. Think of a really cool program you'd like to write that would be really challenging. Now spend an entire summer banging your head against the wall trying to get the simplest thing to behave as expected, figuring out all the cryptic compiler errors that you run into ad infinitum, and find good resources - books, blogs, tutorials, forums, this site - and use them constantly. By the end of the summer you should understand some of the core concepts in programming. Truly understanding them will take being able to think about abstract concepts in ways you never have before. But once you learn some core concepts - OOP would be a good base - more advanced concepts will get progressively easier to understand.

Whatever you do, don't assume that going to class and doing assignments alone will be enough to learn how to program effectively. I seriously doubt many people get proficient at programming through classroom instruction alone; to truly learn to program, you have to write a lot of code, spend a lot of time extremely frustrated at why nothing ever works the first time you try it, and then breathing that sigh of relief and accomplishment when something finally comes together that you've worked very hard on.

share|improve this answer
