Computer Chess Club Archives




Subject: Java has pointers

Author: Steffen Jakob

Date: 03:54:19 05/18/01

Go up one level in this thread

On May 17, 2001 at 10:25:17, Vincent Diepeveen wrote:

>I'm not a big JAVA expert but a major problem of JAVA is that
>it doesn't have pointers.

Thatīs wrong. Java has pointers. Correct is: Java cannot manipulate its object
references arithmetically to alter where they point. In the terminology of Java
a pointer is called a "reference".


Board board = new Board();

Then "board" is a reference to a board object. "board" is *not* the board object
itself. So you can even say that Java has *only* pointers (exect for the
primitive datatypes).

Another fact is that Java passes method arguments always by value.

Lets see the consequences of those both attributes of the Java language:


class Engine
    Board board;

    public void resetBoard(Board board)
        board = null; // this has no effect

In the method resetBoard(Board board) the argument "board" is passed by value.
"board" is a reference to a Board instance. So you are able to modify the state
of the board object with board.reset() but you cannot change the board object
outside the resetBoard member function.

After having left the resetBoard function the board is reset but it still has a
pointer to the same Board instance.


>The only way to index an array is by means of
>  a[i]
>anything like next is not working:
>  *(a+i)  ,  *a++ = i , a = &movearray[i];
>Nevertheless the few experiments i did with java over the course of
>one full year (whole project in JAVA) i did get nullpointer after
>nullpointer... ...which theoretical is not possible in JAVA as it
>has no pointers...
>You can ask a pointer from the system, but that's not how we WANT to use
>a pointer in a chessprogram.
>In short i quickly understood that JAVA will be never able to optimize
>a program to the same extend as a C++ compiler can. A big penalty there
>will always be for using JAVA.
>C++ rules.
>Best regards,

This page took 0.03 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.