Chapter 4: Identifiers, Variables, Objects, and Collection Classes

 < Day Day Up > 



4.1 Introduction

The purpose of this chapter is to cover the concept of identifiers and variables in Java. The distinction between identifiers and variables is one of the biggest differences between languages that implement data types for runtime objects (such as Smalltalk and Java) and those that only use data types at compile time to generate runtime executable code to manipulate those objects (such as C/C++ and Ada). This distinction helps to account for the fact that, although the syntax of Java and C++ are similar, programming in the two languages feels very different. Objects are handled very differently at runtime, which impacts how objects are manipulated in the language in general. Understanding how Java treats objects will be important in subsequent chapters, when objects are passed between other objects or even around a network using tools such as RMI. Being aware of the nature of objects at compile time and runtime is also important in understanding the concept of an interface, which does not define any data or behavior for an object but simply what messages an object must accept.

This chapter first introduces identifiers and variables by showing how not understanding their differences can lead to incorrect programs. The way in which Java implements variables for objects is then covered, and it is shown how this approach is an improvement over languages that do not maintain the type with the variable. The implementation of arrays in Java is then addressed, and the special case of an array of objects is introduced to discuss the concept of a collection class. Finally, the Java Vector class is used to demonstrate a simple collection class built into Java.



 < Day Day Up > 



Creating Components. Object Oriented, Concurrent, and Distributed Computing in Java
The .NET Developers Guide to Directory Services Programming
ISBN: 849314992
EAN: 2147483647
Year: 2003
Pages: 162

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net