• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

If java has pointers

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am going to write java certification in three weeks time. Now studying OCP Oracle Certified Professional Java SE 11 Developer Complete Study Guide book. It is a great book with detailed and simple explanations.


I understood that unlike C++ java don't have pointers, but  java use memory location to handle variables.

Anybody please explain me why this point is false

Java has pointers to specific locations in memory

Chapter 1, Question 1 , OCP Oracle Certified Professional Java SE 11 Developer Complete Study Guide

Thanks and advance
 
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only place you'll ever see the word Pointer is NullPointerException.

Some of the differences between Java's references and C or C++ pointers include:
no notion whatsoever of pointer arithmetic, no --p or p++
There is nothing to de-reference, you do not have * or -> operators for references (the -> symbols are instead used to define lambdas)

There is no notion of > or < for references, == and != can test them for being identical, only.

Tho the .hashCode() method inherited from Object is somehow "based on" an actual address, in some not very clearly defined manner, there is no code you can write in Java that will even show you an address for any variable.  So not only no * or -> for references, but no & either.

There are more differences, that was just right off the top of my head.

Old Java books used to warn people not to think they knew Java because they knew C++ and parts of Java look like C++.  Perhaps nowhere is this more true than Java References, which have some features in common with C++ references, and some similarities to its pointers, but a lot of differences to both.

Staring at the point that bothers you, maybe I read too much into all this, as:

Java has pointers to specific locations in memory



Might just make you ask: "How can the language work without this??"

The answer is that it has obviously, all kinds of stuff going on at the bytecode level or lower.
There is no place that specific locations of memory are accessible to you as a Java programmer.
The closest that you come to that is the value of .hashCode() for classes that do not override Object's definition, even that isn't really an address like you would get from id(someRef) in Python or &whatever in C++.
 
prriya pratheep
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesse Silverman for the detailed explanation. Now I am clear
 
And inside of my fortune cookie was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic