magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 1997 > 04 > Java Alley  

Cloning Objects

By Bruce Eckel

By this time you are probably comfortable with the idea that when you're "passing" an object, you're actually passing a handle (a reference). In many, if not all, programming languages, you can usually pass objects around the "regular" way and everything works fine. But there always comes a point where you must do something irregular, and suddenly things get a bit more complicated (or in the case of C++, very complicated). Java is no exception, and it's important to understand exactly what's happening with your object handles as you pass them around and assign to them. This and next month's columns will provide that insight.

Another way to pose the question, if you're coming from a pointer-equipped programming language, is, Does Java have pointers? Some have claimed that pointers are hard and dangerous and therefore bad, and since Java is all goodness and light and will lift your earthly programming burdens, it cannot possibly contain such things. However, it's more accurate to say that Java has pointers; indeed, everything that has a name in Java is one of these pointers, but their use is very restricted and guarded by both the compiler and the runtime system. These are what I've been calling handles, and you can think of them as "safety pointers," not unlike the safety scissors of early elementary school. They aren't sharp, so you cannot hurt yourself without a very great effort, but they can sometimes be slow and tedious.

Passing Handles Around

It's worth performing an experiment to show that when you pass a handle into a method, you're still pointing to the same object.




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2