Friday, August 28, 2009

to start programming

Luke commented on my last post:I took Java as an undergrad but remember none of it. IF I want to start working on these problems as well as working on programing. What would you suggest... What Language? Helpful Sites? What programs I will need? Books to buy?

Disclaimer: what follows is all very basic but (I hope) at least moderately correct. I am really not a computer programmer and I only presume as far as to say that I am learning and I do enjoy it.

I recommend using Netbeans, which is an IDE (Integrated Development Environment) that can be downloaded from here. Netbeans is the first program of this type that I have used, so I know there are people out there that would argue for other IDE's. Netbeans and the Java Development Kit (JDK) are both free, sponsored by Sun Microsystems. Netbeans is very helpful because it will alert you (without being very distracting) when you have made a syntax error, or when you have created a variable that is not used for anything. Netbeans suggests methods while you are typing, but not in a way that I feel interferes in case you do know what you want to type. It also dims out the code that is 'commented out'.

I work on a need-to-know basis. I try to challenge myself just enough to make use of what I know while learning a little bit at a time. It is a fairly experimental process, so as you try new things you need to be writing programs in which you understand all of the code except maybe one or two lines. As a task becomes more interesting and more necessary, you will find the curiosity to look up how it might be done.

For example, I am getting pretty comfortable with int's, long's, double's and BigInteger's, but there are a few problems that will require me to learn some things about dealing with text, and I have simply not gotten around to it yet. As I try to gain some new skill, I move in little steps. A programmer is supposed to begin with a "Hello, World!" program and go from there. I recommend constructing a few simple programs using the tutorials. After you have something that at least returns a result without errors, you can begin to define variables and construct algorithms.

Sun has some Java tutorials (here is an example) as well as full documentation for the Java language (here is an example). The tutorials include code and some explanations, while the documentation is very technical but it explains the properties of each instance of a given class.

When using Java, you will need to learn the differences of data types. For example, a variable which has been defined as an int cannot exceed a certain value, 231-1 = 2147483647. Its minimum value is -231 = -2147483648. This is because the variable is given 32 bits of disk space, one of which is a sign bit to signify (+) or (-). If your application will encounter bigger numbers than what is expressible as an int, you will need to prepare for that by initiating the variable as a long (64 bits) or a BigInteger, which has arbitrary precision. Sometimes you will need to convert between data types, and sometimes that will involve the risk of a loss of information.

Netbeans supports a trial and error learning technique. You can make small changes in your code and execute the program with a right-click of the mouse. You can track the value of a variable (to see if it is undergoing the changes you are trying to inspire) by putting this line in your code:

System.out.println("a label in quotation marks: "+variableName);

You can use this line to keep track of the progress while the program is running, to see if an anticipated condition is ever met, or to observe where the program stopped doing what you wanted it to do.

There are various tutorials and message boards around the internet, and even reading information about a different language may be helpful. Netbeans has been invaluable as I have been learning the Java language and syntax.