Users of this web page should have some basic knowledge on either an object-oriented or procedural programming language such as Java, C, Pascal or GW-Basic.
Knowledge of basic features, including primitive data types (int, char, long, short, float, double, boolean etc), operators, control structures, functions (methods) and input and output (but not necessarily arrays and classes) is assumed.
This tutorial is intended to provide a practical introduction to Algorithms and Data Structures using Java as a tutorial tool. Although Java language is chosen as a programming language to be used for this tutorial web page, the concepts presented can be easily applied to any typical programming language such as C, Eiffel or Prolog.
It is hoped that students and other users will be able to develop Java programming skills needed for the design and implementation of the common data structures to solve some of the common problems encountered in programming.
In particular, users should:
A. be familiar with some of the common existing data structures (sometimes called
user-defined data types):
1. stacks
2. queues
3. lists
B. and be able to implement these data structures using some of the common data
representations:
1. arrays
2. linked lists
Have fun !
You should use a PC running Windows 95 and have installed a Java compiler compatible with the JDK (Java Development Kit) version 1.1. The version I am currently using is JDK version 1.1.7B. The later versions now are JDK 1.1.8 and SDK 1.3. The different versions of the JDK & SDK may be downloaded directly from the Sun Java site at http://www.javasoft.com/products/index.html
You can use any text editor (Notepad, simple MS-DOS Editor, WordPad) to edit your program files but must save your source code as ASCII Text files.
My suggested references:
1. Bishop, J. M., Java Gently, 3rd Edition, Addison-Wesley, 2001. This gives a very good
introduction to Java.
2. Deitel, H. M. and Deitel, P. J., Java How to Program, 4th Edition, Prentice Hall, 2002.
Your first program can be as simple as this:
class FirstProgram {
public static void main(String[] args) {
// Say Hello to the user!
System.out.println("Hello, how do you do!");
}
}
Explanation:
FirstProgam is a class name. // is used for comments; so are /* ends with */ and
/** ends with **/
In Java, what is known as function or procedure in other language is called a method. public
is a method, so is static. void is a method return type. main
is the method name. String[] args is the parameter list. System is a
class, out is an object, println is a method.
The code prints a short phase to the terminal. Place the code in
the source file FirstProgram.java, compile and run it.
To compile:
c:\test>javac FirstProgram.java (FirstProgram.java is the source file name)
A class filename FirstProgram.class will be created.
To execute:
c:\test>java FirstProgram
(FirstProgram is the class file name)
©2001. William NWL6. All rights reserved.
Last Updated: February 7, 2002