Ask
 
Answer
 
Forum
 
Debate
 
Blog
 
Categories
Entertainment & Music

Computers

Internet

Science & Mathematics

Health

Consumer Electronics

Sports

Society & Culture

Food & Drink

Education & Reference

 
More >>

 
Sign Up
Languages
English

Finnish

Arabic

Italian

Korean

French

Chinese(Traditional)

Chinese(Simplified)

Swedish

Czech

Hindi

Dutch

Norwegian

Russian

Croatian

German

Japanese

Bulgarian

Portuguese

Chinese

Spanish

Greek

 
Login


Remember:
Signin With:
 
OpenID

Google

Yahoo!

Facebook

Ning

 

Ok

QuestionBin for Sale!


For Sale Buy QuestionBin!
QuestionBin.com is for sale! Bid Now

Ask a Question



Search

Advanced

Topics

code computer difference download facebook file game internet justin linux money mysql name number online page php poptropica someone something system time ubuntu way web wii windows wordpress world year

More >>

Categories

  • ■Computers (18639) Subcategory Available
  • ■Internet (13676) Subcategory Available
  • ■Entertainment & Music (9481) Subcategory Available
  • ■Health (6766) Subcategory Available
  • ■Programming (6094) Subcategory Available
  • ■Video & Online Games (4842) Subcategory Available
  • ■Science & Mathematics (3860) Subcategory Available
  • ■Business & Finance (3657) Subcategory Available
  • ■Politics & Government (1535) Subcategory Available
  • ■Arts & Humanities (1395) Subcategory Available

More >>

Question Library

# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  • Manage Blogs
  • Add Blog
  • All Blogs

 

 

On pointers and references, C++ vs Java

By: Winged ... 1 month ago : Comments (2)
In Programming
I am SO tired of Java books insisting that Java references are NOT pointers!  I'm working on picking up Java (again) and ran across this statement.  It's nonsense!

C++ has two types for referring to other objects: pointers and references.  Pointers are an integer type that can be used to access other memory addresses.  They can be manipulated through pointer arithmatic, assigned manually, etc.  Most of the time, however, they are used to either point directly to another, existing, object, or used to keep a handle on newly acquired memory through the new operator.  They can be used to acquire arrays dynamically, or most anything else.

C++ references serve as an alias for an object that already exists.  As such, it doesn't allocate memory, or anything else.  It's primary purpose is to act as a "first order object" when receiving a parameter into a function that needs to be able to modify that parameter.

Now look at Java references.  You assign them to existing data (causing two references to point to the same location in memory) or through the new operator.  They are not integral types, and are automatically dereferenced under normal circumstances.  They are used to acquire arrays and classes dynamically.  They cannot be used as a handle on a primitive type.

If you look at the three types, it is clear that a Java references IS a pointer.  Because they are not implemented the same way (integral vs non-integral), they have some differences.  Nevertheless, they are pointers, and any C++ programmer will be unable to think of them as anything else.


  • Total views:  460
  • Total comments:  2
  • Tick This

Rate Now: 1 2 3 4 Average Rating: 4.00 / 2 ratings

Add Comments

Taley

Any idea why they keep being referred to as not pointers? I mean, is it just this one author or every author/book?

  • Posted by:   Taley
  • Date Added:   1 month ago
  • reply

Winged ...

Every author I have read refuses to acknowledge them as pointers. I think it comes from the association with C/C++ pointers as being a major source of insecurity/errors. Java's references are more restricted, which helps prevent the types of problems they can lead to in other languages. I suspect it's a marketing thing to help beef up their reputation for a secure environment: "We don't have pointers, so we can't have those problems!"

  • Replied by:   Winged ...
  • Date Added:   1 month ago
  • Posted by:   Taley
  • Date Added: 1 month ago

dax

What books are you reading?

  • Posted by:   dax
  • Date Added:   1 month ago
  • reply

Winged ...

I've read a few. The current one is Java: the complete reference, 7th edition.

  • Replied by:   Winged ...
  • Date Added:   1 month ago
  • Posted by:   dax
  • Date Added: 1 month ago
Disclaimer | Privacy Policy | Terms | Report Bugs | ■ RSS | Sitemap | Contact Us | ■ Invite | Create your Widget | ■ Twitter
■ Howto Tutorials | ■ Linux Questions | ■ URLTick | ■ Gamers Forum

© 2009 QuestionBin. All rights reserved

QuestionBin does not evaluate or guarantee the accuracy of any QuestionBin content. Click here for the Full Disclaimer.