Java Data Structures |
|||
|
ISBN : - |
Order a printed copy of this book from Amazon --UNAVAILABLE-- |
||
![]() Cover Design - Java Data Structures |
For your free electronic copy of this book please verify the numbers below. (We need to do this to make sure you're a person and not a malicious script) | ||
|
Sample Chapter From Java Data Structures Copyright © Particle |
|||
IntroductionIn contrast to what most people think about Java, it being a language with no pointers, data structures are quite easy to implement. In this section, I\'ll demonstrate few basic data structures. By learning how easy they are to implement in Java, you\'ll be able to write any implementation yourself. I also think that this document is a pretty good introduction to Data Structures in general. All these concepts can be applied in any programming language. Incidentally, most of these programs are ported from their C++ counterparts. So, if you want to learn Data Structures in C/C++, you\'ll still find this document useful! Java is an Object Oriented language, but more so than C++, so, most data structure concepts are expressed and illustrated \'more naturally\' in Java! (try not to raise your blood pressure from all the caffeine) I suggest that you be familiar with Java format, and know some other programming language in advance. Coincidentally, I and a couple of my friends are in the process of writing a C language book, which deals with all that \'start up\' stuff. The way
most examples are executed is through the JDK\'s command line Java
interpreter. (at the prompt, you just type Variables...Variables are the key to any program. There are variables called registers inside every CPU (Central Processing Unit). Every program ever written uses some form of variables. Believe it or not, the way you use variables can significantly impact your program. This section is a very simple introduction to what variables are, and how they\'re used in programs. Usually, a variable implies a memory location to hold one instance of one specific type. What this means is that if there is an integer variable, it can only hold one integer, and if there is a character variable, it can only hold one character. There can be many different types of variables, including of your own type. A sample declaration for different variable types is given below.
I
believe the above is straight forward, and doesn\'t need much
explanation. Variable The
above variables are what\'s know as primitive types. Primitive types in
Java means that you don\'t have to create them, they\'re already
available as soon as you declare them. (you\'ll see what I mean when we
deal with Objects) It also means that there is usually some hardware
equivalent to these variables. For example, an The other types of variables are instances of classes or Objects. Java is a very Object Oriented language, and everything in it, is an object. An object is an instance of a class. Your Java programs consist of classes, in which you manipulate objects, and make the whole program do what you want. This concept will be familiar to you if you\'ve ever programmed C++, if not, think of objects as structures. An example of a simple class would be:
As you
can see, first we specify that the class is The way you declare a variable, or in this case, an object of that class, is:
or
The
first example illustrates how you declare an object named If you\'re familiar with C/C++, think of objects as pointers. First, you declare it, and then you allocate a new object to that pointer. The only limitation seems to be that you can\'t do math on these pointers, other than that, they behave as plain and simple C/C++ pointers. (You might want to think of objects as references however.) Using variables is really cool, and useful, but sometimes we\'d like to have more. Like the ability to work with hundreds or maybe thousands of variables at the same time. And here\'s where our next section starts, the Arrays!
|
|||