🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #545

Re: java semantics vs C++

#545
From: Paul Murray
Date: Sun, 20 Aug 2000 00:00
53 lines
2396 bytes
"Ihug" <sammuel@ihug.com.au> wrote in message
news:966728868.782876@ns2.1earth.net...

> when I declare an instance of an object in Java
>
> public static void main(String []arguments)
> {
>     obj x = new obj();
> }

> now is the new operator explicitly asking for memory ?

Yes.

>..... and is x a pointer of my type obj ?....

Yes, but you are not supposed to think about it that way.

> If so then what is the difference if I have
> obj x;
>  // or
> obj y = new obj();

If you insist, obj x is a pointer, initialised to null.

What you can't do in java is declare an object "inline" in another object,
or on stack. You only ever have control of pointers to objects, not the
objects themselves.

This ** IN C **
struct x { int xx; }

void foo() {
    struct x xxx;

    xxx.xx = 3;
}

Which assigns a two (or four) byte chunk of stack to be used by a struct x,
has no equivalent in Java. In Java, you don't control memory *at all*,
except to ask for storage via the new() operator. And what you get back are
not pointers, but references - you can't do arithmetic on them, you can't
decompose them into memory adresses. A java reference is more like a windows
"handle". Maybe it helps to think of it that way. Java does not use '->' or
'*' to dereference, because a java programmer never dereferences anything -
only the underlying engine does. In effect, the C element selection oprator
'.' is not implemented in java, so java uses a dot for the job for which C
uses the arrow.

--------------------------------------------------------------
Repent! Quit your job! Slack off!
http://www.users.bigpond.com/pmurray/index-2.html
ICQ: 26066755
Technical Details
Message-ID: <Ah6o5.35051$c5.97064@newsfeeds.bigpond.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <966728868.782876@ns2.1earth.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,d85a1064ac7a86a7
X-Google-Attributes: gid10d6db,public
From: "Paul Murray" <pmurray@nospam.bigpond.com>
Subject: Re: java semantics vs C++
Date: 2000/08/20
Message-ID: <Ah6o5.35051$c5.97064@newsfeeds.bigpond.com>
X-Deja-AN: 660651254
References: <966728868.782876@ns2.1earth.net>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300
X-Trace: newsfeeds.bigpond.com 966848736 139.134.123.3 (Mon, 21 Aug 2000 19:05:36 EST)
Organization: Telstra BigPond Internet Services (http://www.bigpond.com)
X-MSMail-Priority: Normal
NNTP-Posting-Date: Mon, 21 Aug 2000 19:05:36 EST
Newsgroups: aus.computers.java