Tuesday, October 25, 2011

Javalog Day 1. Starting out.

Mission: Get software, install it, write "Hello World" program.

I will need the Java Development Kit (JDK) and the NetBeans IDE (Integrated Development Environment).

My computer already has Java SE 6 (Standard Edition 6) installed to run Java code in browsers. But Java has recently upgraded to release 7. Do I stick with 6 (stable but will get outdated) or go to 7 (more features but possibly buggy). The Java website tells me that the tutorials are based on Java 7. That does it. Java 7 it is.

Check requirements: My system is 64-bit Windows 7 Home Basic SP 1, 1.9 GHz Celeron Dual-Core, 2 GB RAM, 250 GB HDD.  Check check check check check. That'll do.

At Java SE Downloadsl I scroll down to find JDK 7 with NetBeans 7.0.1. The file is a whopping 164.2 MB, far too big for my puny home dial-up connection. So off to the internet cafe I go, and 40-odd minutes later I have jdk-7-nb-7_0_1-windows-ml.exe saved on a memory stick, together with any promising looking documents.

What I really want is a complete list of all the functions or objects and how to call them, together with brief snippets of sample code. Can't find it, but maybe it's on the NetBeans IDE or in the Java book. We'll see.

Back home, I push the memory stick into my laptop's USB slot, click on the program name, follow instructions, and soon the JDK and NetBeans install themselves without a problem on my hard drive in their own directories in C:Program Files (x86)\Java.

Hmmmm. x86 is the 32-bit program directory. Not 64-bit as I was expecting. Did I make a mistake or is only 32-bit available? Don't suppose it makes a difference. Total installation size: 564.3 MB. Phew! Back in the 1990s, Clipper installation size: 8 MB. Things have changed.

On my Desktop I find a new shortcut icon. A blue cube calling itself NetBeans IDE 7.0.1.

Time for "Hello World." But first a cup of tea.

A digression

I'm nervous. If I click on the icon and nothing happens, what then?

I remember when I started with Clipper. It took days to set up before I could start programming. You had to tell it where everything it needed was. You wrote the code using a text editor like Notepad. Then you compiled it, i.e. Clipper checked that your code was understandable, correct (e.g. no spelling mistakes or unclosed brackets), and didn't use unknown functions or variables. Then you linked it, i.e. it added standard software modules to your code and packed it all together into a big executable .exe  file which would run on DOS or Windows up to XP without needing any other software.

Java is different. It creates a .jar file which cannot run unless it has Java SE to provide essential software. The benefit is that if everyone has Java SE loaded on their computers, most of the code is already present and you only need a small amount of additional code in your .jar file. This makes a .jar file ideal for sending around the internet.

DISCLAIMER: This might be entirely wrong! I'm teaching myself Java, so I have an idiot for a tutor.

But I will tell you if I'm wrong. That's a promise.

For my first attempt I will follow a tutorial on netbeans.org called NetBeans IDE Java Quick Start Tutorial.

First Attempt

1. Start NetBeans IDE.

Desktop. Blue cube icon. Hold thumbs. Here goes.

Click.

Nothing happens.

Uhhhh.... Double click.

NetBeans IDE 7.0.1 loading modules... starting modules... aaaand... we're in!

2. Choose File > New Project

Phew. Four panes, five buttons. One day I'll know what they all mean.

3. Expand the Java category (middle pane) and select Java Application (right pane).

I highlight the Java category. "Creates a new Java SE application in a standard IDE project." The screen shot has Java Web, EE, and ME in addition to Java. I presume that applies to the Enterprise Edition of the JDK which I didn't download because I'm only interested in Java SE for now.

Then I click on Java Application and Next.

4. Choose Name and Location.

Like a good little boy I follow the tutorial exactly. Later I'll choose my own names. But for now it's HelloWorldApp for a name. Leave the Project Location at the default NetBeansProjects and the Project Folder has automatically changed to HelloWorldApp.

"Use dedicated folder..." is unselected. Check.

"Create Main Class" is selected and the text box automatically and correctly filled. Check.

"Set as Main Project" is selected. Check.

Click Finish.

"Creating project..." new window with four panes opens titled HelloWorldApp, "Scanning project...", and it looks just like the screen shot.

No idea what it means, though. One day I will, I hope.

The big window on the top right contains code. Following the tutorial exactly, I replace "// TODO code application logic here" with "System.out.println("Hello World!");" copied and pasted from the tutorial.

The "out" turns green and the "Hello World!" orange. I'm guessing the system recognises "Hello World!" as text. Don't know about the "out".

File > Save.

Nothing dramatic happens. That's good, because it automatically compiles when you save. If you don't get error messages that means there are no obvious errors. Doesn't mean it works like you want it to, though. (Voice of bitter, bitter experience talking here.)

Run > Run Main Project

Sound the trumpets! In the bottom right window appears the joysome tidings:
run: 
Hello World!
BUILD SUCCESSFUL (total time: 1 second)

And that's enough for today.

Prologue

Recently I decided to take up programming again, this time as a hobby, and blog about my experience.

I have programmed before. I learned enough Clipper (by studying books and analysing other people's programs) to get paid to write a couple of useful database programs. So although I never had a lesson I would be classed as an intermediate-level programmer.

Clipper is a DOS-based database language derived from dB III. It was fabulous to use in its day but it is outmoded today. It will run on Windows up to XP but not 64-bit Windows 7.

Around the year 2000 I stopped writing Clipper code except for code maintenance. I didn't learn a new language, believing I was too old to compete against hotshot young programmers with computer science degrees.

But writing code can be fun. And I had some ideas for applications. So I decided to start again.

At first I thought Python might be the ideal language, but I could not find a suitable free tutorial. (It has to be free because I don't have money.)

So I decided to learn Java. I googled and  found a promising  pdf  Teach Yourself JAVA in 21 Days by Laura Lemay and Charles L. Perkins. It  was was a free download, presumably because it's an old edition dated 1996. I hope it's useful. (I haven't cracked it open yet.)

Next step is to get the software, and my journey begins...