You manipulate objects with handles | CodeGuru

You manipulate objects with handles

Bruce Eckel’s Thinking in Java Contents | Prev | Next with handles Each programming language has its own means of manipulating data. Sometimes the programmer must constantly be aware of what type of manipulation is going on. Are you manipulating the object directly or are you dealing with some kind of indirect representation (a pointer […]

Written By
CodeGuru Staff
CodeGuru Staff
Mar 1, 2001
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

with
handles

Each


programming language has its own means of manipulating data. Sometimes the


programmer must constantly be aware of what type of manipulation is going on.


Are you manipulating the object directly or are you dealing with some kind of


indirect representation (a pointer in C or C++) that must be treated with a


special syntax?

All


this is simplified in Java. You treat everything as an object, so there is a


single consistent syntax that you use everywhere. Although you


treat

everything


as an object, the identifier you manipulate is actually a “handle”


to an object. (You might see this called a


reference

or even a pointer in other discussions of Java.) You might imagine this scene


as a television (the object) with your remote control (the handle). As long as


you’re holding this handle, you have a connection to the television, but


when someone says “change the channel” or “lower the


volume,” what you’re manipulating is the handle, which in turn


modifies the object. If you want to move around the room and still control the


television, you take the remote/handle with you, not the television.

Also,


the remote control can stand on its own, with no television. That is, just


because you have a handle doesn’t mean there’s necessarily an


object connected to it. So if you want to hold a word or sentence, you create a


String

handle:

String
s;

But


here you’ve created


only

the handle, not an object. If you decided to send a message to


s

at this point, you’ll get an error (at run-time) because


s

isn’t actually attached to anything (there’s no television). A


safer practice, then, is always to initialize a handle when you create it:

String
s = "asdf";

However,


this uses a special case: strings can be initialized with quoted text.


Normally, you must use a more general type of initialization for objects.


Contents

|

Prev

|

Next
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.