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).
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.
There are two key areas:
- Problem solving (Understanding the problem at hand and how to solve it)
- 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.
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. 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.
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.
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.
The journey of a thousand kilometers beings with a
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 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.
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!
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.