Contents | Prev | Next
Latest Thinking In Java Articles - Page 3
When you create an object, it exists for as long as you need it, but under no circumstances does it exist when the program terminates. While this makes sense at first, there are situations in which it would be incredibly useful if an object could exist and hold its information even while the program wasn’t running. Then the next time you started the program, the object would be there and it would have the same information it had the previous time the program was running. Of course you can get a similar effect now by writing the information to a file or to a database, but in the spirit of making everything an object it would be quite convenient to be able to declare an object persistent and have all the details taken care of for you.
In this chapter you have seen enough of Java programming to understand how to write a simple program, and you have gotten an overview of the language and some of its basic ideas. However, the examples so far have all been of the form “do this, then do that, then do something else.” What if you want the program to make choices, such as “if the result of doing this is red, do that, if not, then do something else”? The support in Java for this fundamental programming activity will be covered in the next chapter.
This chapter concludes the study of fundamental features that appear in most programming languages: calculation, operator precedence, type casting, and selection and iteration. Now you’re ready to begin taking steps that move you closer to the world of object-oriented programming. The next chapter will cover the important issues of initialization and cleanup of objects, followed in the subsequent chapter by the essential concept of implementation hiding.
The seemingly elaborate mechanism for initialization, the constructor, should give you a strong hint about the critical importance placed on initialization in the language. As Stroustrup was designing C++, one of the first observations he made about productivity in C was that improper initialization of variables causes a significant portion of programming problems. These kinds of bugs are hard to find, and similar issues apply to improper cleanup. Because constructors allow you to guarantee proper initialization and cleanup (the compiler will not allow an object to be created without the proper constructor calls), you get complete control and safety.
Latest Developer VideosMore...
Latest CodeGuru Developer Columns
Become more proficient on the usage of statements to control the flow of execution through a C++/CLI application.
Because it's often easier to address pixels/cells directly than to use Windows Forms or something similar, it's very often simpler to manipulate raw pixel data directly.
The concepts of boxing and unboxing data might be second nature for many, but for newbies it's worth covering. And, the "old hands" may learn something new, as well.
Most developers face a grueling challenge to please their end users. We asked their top challenge is. With over 3,000 responses, the results are now available!