Your Computer Science Resource

Archive for December, 2008

Dec
31st

Eclipse: Generate getters and setters

Suppose you have a relatively large class file consisting of 20 or more fields. How long will it take you to write getters and setters so that these fields may be accessed by other classes? Even a fast typist will consider this to be a very tedious task. Isn’t there some way to do this faster? Or perhaps automatically…? Alas, Eclipse can do it for us.

(more…)

Dec
31st

Eclipse: Externalize Strings

I don’t use this often, and only recently discovered this feature. Eclipse allows you to “externalize” all or specific strings in your project. This means that any string you’re using in your application can be stored in a properties file outside of your program. This essentially separates your text from the programming. Why would this be useful? Suppose you’re building an application that you want to translate into other languages. Rather than hard-code the text into your program, you can simply load up different property files depending on the language. See the potential? Now let’s see how it’s done.

(more…)

Dec
28th

MD5 and SHA-1 Encryption in Java

Java has a built-in MessageDigest class which makes it easy to implement an MD5 or SHA-1 hash (among others). Both of these algorithms produce one-way hashes (they cannot be changed back to their original form), and they are usually used for encryption and for checking the integrity of files (checksum). Although they are probably deemed partially insecure, they are still very widely used.

(more…)

Dec
28th

Doubly Linked List – Delete Middle Without Counting

The middle of a list is one record with equal number of records to the left and right (assuming the list has odd number of elements). If this number is even, the middle consists of two records. Write a pseudo-code procedure to delete the middle (one or two) record(s) of a doubly linked list without counting first or knowing the total number of elements in the list.

(more…)

Dec
28th

Reverse a Doubly Linked List

This question comes up often in undergraduate CS classes, specifically Data Structures and Algorithms: How do you reverse a doubly linked list? Let’s find out! :)

(more…)

Dec
28th

Sorting Algorithms

A while back I had to write a program that would compare different sorting algorithms in Java. The algorithms were Heap Sort, Merge Sort, and Quick Sort. I will leave the analysis up to you, but I will share the algorithms below.

(more…)

Dec
27th

HOW-TO: Screen Capture Using Java’s Robot Class

At some point or another, you may come across a time when you need to capture the user’s screen and save it as an image. Maybe you’re making your own “print screen” program, or doing some other image analysis. Regardless, there is a really simple way to capture the user’s screen, and here it is.

(more…)

Dec
27th

PROJECT: Huffman Coding

In the field of computer science, data compression is an extremely important tool used in many different types of applications. One way to compress data is to convert the data to binary code, using a shorter code for more frequently used values and a longer code for less frequently used values. Doing so allows you to save larger values in a much smaller space, thus saving you space overall. This is essentially how Huffman Coding works, and how I have implemented data compression in this application. To download the complete source to this project in C++, click here.

(more…)

Dec
26th

Distributed Search Using Nutch

This past semester for a Computer Architecture class I was taking, we were assigned a project to implement a distributed search engine using Nutch. The following notes describe the installation procedure for installing and configuring Nutch as a distributed search engine on Windows XP using Cygwin (a Linux emulator) and Apache Tomcat. Note that the master computer was running Windows XP while the slave machines were running Mac OS X, showing that the search engine works across multiple platforms.

(more…)