1. Home
  2. Computing & Technology
  3. Java
photo of Paul Leahy

Paul's Java Blog

By Paul Leahy, About.com Guide to Java

Poll: What's Your Java Experience Level?

Friday October 10, 2008

Friday is fast becoming poll day and as you can see this week turns out to be no different. After a few chats with a couple of Java regulars I'm interested to know more about you. Don't worry nothing too personal. All I want to know is how much experience you feel you have programming with Java.

Design and Create an Object in Java

Thursday October 9, 2008

Yesterday there was an introduction to object-oriented programming that dealt with the beginning theory of working with objects.

Today I thought you might fancy getting your hands dirty by looking at how to design and create an object in Java. After all you know what they say, all theory and no practice makes Jack a dull programmer.

Looking at Object-Oriented Programming

Wednesday October 8, 2008

Today sees the start of a series of articles on object-oriented programming. Learning about objects is fundamental to becoming a good Java programmer.

Before I start looking at how Java creates and uses objects it's best to introduce some theory behind object-oriented programming. You will learn what it means to create programs that are object-oriented, what objects are, their states and behaviors, and how they relate to data encapsulation.

A Mandelbrot Displaying Java Applet

Tuesday October 7, 2008

I'm still hunting around looking for any cool Java applets that might be out there. Today I came across StarFractal on the CodingMagic website, an applet that displays the Mandelbrot set. You can keep zooming in and see the same patterns emerge time and time again.

There's a couple of other Java Applets such as a 2D maze game and 3D boxes that bounce around and can be viewed from different angles, but it's the crazy fractal images that really caught my eye.

Monday's Programming Question

Monday October 6, 2008

Last week the challenge was to make a decoding program. It would seem silly not to make the encoder that goes with it.

Here's the same letter switch code:

Decodedabcdefghijklm
Encodedprjitgcoxbsyn
Decodednopqr stuvwx yz
Encodedwdemh uvlzfq ka
For example, the name "bob" becomes "rdr" (i.e., b=r, o=d, b=r). Don't worry about capital letters, just assume that all of the text is in lowercase.

This week write an encoder along the same principles of the decoder, except I want to highlight the difference between using a normal for loop and a "for each" loop. Your program should take a line of text entered by the user, use a combination of a for each loop and switch statement to encode it, and finally display the encoded line to the user.

The question is can your program encode this line?

it was a dark and stormy night

Answer to Monday's Encoded Line Question

Sunday October 5, 2008

The question on Monday was concerned with writing a program to decode this first line from a book by Iain Banks:

xv fpu vot ipk nk chpwindvoth tqeyditi

which turns out to be from The Crow Road:

it was the day my grandmother exploded

The program needed to take an encoded line from a user, use a combination of a normal for loop and switch statement, and finally display the result. I have to say that even though it was somewhat unexpected, the solution in c++ was most welcome. Well done to everyone who decoded the line.

Here's my version:

import java.util.Scanner;

public class Decoder {

  public static void main(String[] args) {

    //Get the input from the user
    Scanner input = new Scanner(System.in);
    System.out.println("Enter in text to be decoded: ");
    String codedText = input.nextLine();

    //Make sure the line is in lowercase
    codedText = codedText.toLowerCase();

    //Split the string into an array of chars
    char letters[] = codedText.toCharArray();

    //Decode the line of text
    char decodedLetter = ' ';
    for (int i=0; i     {
      switch(letters[i])
      {
        case 'a':
          decodedLetter = 'z';
          break;
        case 'b':
          decodedLetter = 'j';
          break;
        case 'c':
          decodedLetter = 'g';
          break;
        case 'd':
          decodedLetter = 'o';
          break;
        case 'e':
          decodedLetter = 'p';
          break;
        case 'f':
          decodedLetter = 'w';
          break;
        case 'g':
          decodedLetter = 'f';
          break;
        case 'h':
          decodedLetter = 'r';
          break;
        case 'i':
          decodedLetter = 'd';
          break;
        case 'j':
          decodedLetter = 'c';
          break;
        case 'k':
          decodedLetter = 'y';
          break;
        case 'l':
          decodedLetter = 'u';
          break;
        case 'm':
          decodedLetter = 'q';
          break;
        case 'n':
          decodedLetter = 'm';
          break;
        case 'o':
          decodedLetter = 'h';
          break;
        case 'p':
          decodedLetter = 'a';
          break;
        case 'q':
          decodedLetter = 'x';
          break;
        case 'r':
          decodedLetter = 'b';
          break;
        case 's':
          decodedLetter = 'k';
          break;
        case 't':
          decodedLetter = 'e';
          break;
        case 'u':
          decodedLetter = 's';
          break;
        case 'v':
          decodedLetter = 't';
          break;
        case 'w':
          decodedLetter = 'n';
          break;
        case 'x':
          decodedLetter = 'i';
          break;
        case 'y':
          decodedLetter = 'l';
          break;
        case 'z':
          decodedLetter = 'v';
          break;
        default:
          decodedLetter = letters[i];
          break;
      }
      System.out.print(decodedLetter);
    }
  }
}

Java Term of the Week: Garbage Collection

Saturday October 4, 2008

Every time a Java program makes a new object it is allocated a certain amount of space in memory. When that object is no longer used by the program we want to free up the space it was using so that it can be used for something else.

"Garbage Collection" is the name that is given to the automated process of detecting objects that are no longer used by a program and freely up the memory that is associated with them. This process saves Java programmers from having to explicitly dispose of objects to free up memory.

Poll: What Did You Use to Learn Java?

Friday October 3, 2008

Talking with a few Java programmers who are just starting out I've been thinking about text editors and IDEs. I've become curious how most people started out learning Java.

This poll couldn't be simpler. Did you use a super duper IDE? A simple text editor or one that at least did some syntax highlighting?

Using an IDE Versus a Text Editor

Thursday October 2, 2008

Over the past couple of weeks I've been asked the same question a few times by people just beginning to learn Java. What tool should I use to write my programs in? There are plenty of choices out there from simple text editors to integrated development environments.

I always think the best place to start is to use something in between. I call them programming text editors as they are written with programming in mind (e.g., TextPad, JEdit). They offer helpful features like syntax highlighting and the ability to compile code without the need to use command-line tools in a terminal window. But, they don't overwhelm you with a lot of tools that you're not going to use until you become more experienced.

Playing Games on the JPC Emulator Applet

Wednesday October 1, 2008

I love old PC emulators. They are applications that simulate the architecture of computers that were in their heyday about twenty years ago. The obvious question is why bother? Well, the same reason anyone had a computer back then, to play games! I'm not sure why but there is something really entertaining in playing a game I used to spend hours trying to master when I was a kid. Anyone remember Chuckie Egg?

So, I was delighted to find that there's a cool Java Applet that emulates the old x86 machines. Anything that used to run on the IBM PCsOn the website they claim that the JPC applet came about because of number crunching particle physicists. But secretly I think they just wanted to spend their afternoons playing Space Invaders.

Read Archives

Explore Java

More from About.com

  1. Home
  2. Computing & Technology
  3. Java

©2008 About.com, a part of The New York Times Company.

All rights reserved.