A Question about JAVA
Hi
Q:
What was LOST and What was GAIEND in java with not including the pointers in C++?
will i found that java have pointers.. they're just not explicit..and don't allow Pointer Arithmetic ...
so...can u plz answer the Q..
and plz.. give me an example "in C++" that i cannot do it in java..and how to get around it "in java"..
thank you ...
Both Java and C++ are Turing complete which means that anything computable is computable in both.Pointers just happen to be a tool available in C++. The trade off in simplicity and code maintainability are amongthe reasons why Java didnt provide that particular tool.
> What was LOST and What was GAIEND in java with not
> including the pointers in C++?
Less complexity and more stable applications. Downside: you can't randomly write into your RAM. Upside: you can't write randomly into your RAM.
Never rebooted my PC that much than when I was still writing C.
void pointer. Pointing to the void makes me feel like saying: "Let there be light".
thanks...waiting for an example using pointers in c++ v.s pointers in java"code example"thanks again..
> thanks...
>
> waiting for an example using pointers in c++ v.s
> pointers in java
> "code example"
You'll be waiting a while, dude...
Pointers do not exist in Java... they are abstracted away from us, and we do not have access to them as Java programmers, (with very few exceptions).
> waiting for an example using pointers in c++ v.s> pointers in java> "code example"Waiting for you to acquire some initiative. Yawmark (<-- not holding my breath)
ok.. i will write a c++ code and could someone
give me how its done in java <<i dont know java ..
void LinkList :: InsertSorted( int x)
{
if ( head == 0 || head ->data >x )
InsertFirst(x);
else
{
Node *q = head;
Node *p= head->next;
while( p != 0 && p->data < x)
{
q=p;
p= p->next;
}
node *r = new Node(x);
q->next= r;
r->next = p;
}
}
class LinkedList {
void insertSorted(int x) {
if (head == null || head.data > x) {
insertFirst(x);
}
else {
Node q = head;
Node p = head.next;
while (p != null && p.data < x) {
q = p;
p = p.next;
}
Node r = new Node(x);
q.next = r;
r.next = p;
}
}
}
the last example was simplewhat about thisT[] ta= new T[54];T* pT= &ta[41]; pT++; ta= null;can i do it in java ...?and howplease show me...thanks
> pT++; >> can i do it in java ...?and how please show me...The question is: what exactly do you want to achieve? There's no direct conversion to the code you posted as it uses pointer arithmetics. Though, the result is achievable in Java, too.
Very true. You should be bothered about what you need to achieve rather than try to achive some language syntax in some other language.
NuSina at 2007-7-12 17:38:38 >

ok..ok
the last code have some problems..
this is the right one
int T[100];
for (int i=0; i<99; i++)
T[i]=i;
int *ta= &T[54]; // is this possible in Java ?
// if yes then write it down please;
// if no.. then is their a way to get it done ..?
int *pT= &ta[41];//the same as the last commente;
pT++;//can this be done in java ?
// if yes then write it down please;
// if no.. then is their a way to get it done ..?
ta= NULL;
i hope i find the answer...
> Very true. You should be bothered about what you need
> to achieve rather than try to achive some language
> syntax in some other language.
in my first post their was a Q ..
that Q is a part of an assignment from my
doctor in Computer Science College...
and i want to put some examples for him...
> and i want to put some examples for him...You want to have other people write the examples for you? Why not just cut out the middle man (i.e., you), and have your professor come talk to us directly?~
> ok..ok
> the last code have some problems..
> this is the right one
>
> > int T[100];
> for (int i=0; i<99; i++)
> T[i]=i;
>
> int *ta= &T[54]; // is this possible in Java
> ?
> // if yes then write
> it down please;
> // if no.. then is
> their a way to get it done ..?
>
> int *pT= &ta[41];//the same as the last
> commente;
>
>pT++;//can this be done in java ?
> // if yes then write it down
> please;
> // if no.. then is their a way to
> get it done ..?
>
>ta= NULL;
> pe i find the answer...
No, pointer arithmetic cannot be done in Java. It's a higher-level language than that. That's not to say that the actual problem - as opposed to "how do I do pointer arithmetic?" which relates to a proposed solution to a problem, not a problem itself - can't be solved in Java
T* tp=new T[54]; // worksT[] ta= new T[54];// does not even compile