Archive for: September, 2014

A Closer Look at Methods and Classes

A Closer Look at Methods and Classes This chapter continues the-discussion of methods and classes begun in the ?receding chapter. It examines several topics relating to methods, including. overloading, parameter passing, and recursion. The chapter, then returns to the class, discussing-access control, the use of the keyword static, and one of Java’s most important built-in classes: String, Overloading Methods…

Read More →

The Complete Reference

The Complete Reference ThiS chapter continues our discussion of java.util by examining those classes and interfaces that are not part of the collections framework. These include classes that tokenize strings, work with dates, compute random numbers, and observe . events. Also, the java.util.ztp and java.util.jar packages are briefly mentioned at the end of this chapter. Stringtokenizer The processing of text…

Read More →

Instance Variable Hiding

Instance Variable Hiding As you know, it is illegal in Java to two local variables with the same name inside the same or enclosing scopes. interestingly, you can have local variables, including formal parameters to methods, which overlap with the names of the class’ instance variables. However, when a local variable has the same name as an…

Read More →

Parameterized Constructors

Parameter Constructors While the Box( ) constructor in the preceding example does initialize a Box object, it is . not very useful=-all boxes have the same dimensions. What is needed is a way to construct Box objects of various dimensions. The easy solution is to add parameters to the constructor. As you can this makes them much more…

Read More →

Constructors

Constructors It can be tedious to initialize all of the variables in a class each time an instance is created. Even when you add convenience functions like set Dim( ), it would be simpler and more concise to have all of the setup done at the time the object is first created .. Because the requirement for…

Read More →

Returning a Value

Returning a Value While the implementation of volume( ) does move the computation of a box’s volume inside the Box class where it  it is not the best way’ to do it. For example, what if another part of your program wanted to know the volume of a box, but not display its value? A better way to…

Read More →

Problems with Native Methods

Problems with Native Methods Native methods seem to offer great promise, because they enable you to gain access. to your existing base of library routine’s, and they offer the possibility of faster run-time execution. But native methods also introduce two significant problems: II Potential security risk Because a native method executes actual machine code, it…

Read More →

Adding a Method to the Box Class

Adding a Method to the Box Class Although it is perfectly fine to create a class that contains only data, it rarely happens, Most of the time you will use methods to access the instance variables defined by the . . class. In fact, methods dcfir e the interface to most classes ..This allows the class implementor to…

Read More →

An Observer Example

An Observer Example Here is an ‘example that demonstrates an observable object. It creates an observer class, called Watcher, that implements the Observer interface. The class being monitored is called Being Watched, It extends Observable. Inside fleeing Watched is the method counter(), which simply counts down from a specified value. It uses sleep( )to wait a tenth of…

Read More →

Assigning Object Reference Variable

Assigning Object Reference Variable Object reference variables act differently than you might expect when an assignment , takes place. For example, what do you think the following fragment docs?You might think that  is being assigned a reference to a copy of the object referred to by That is, you might think that  to separate and distinct objects. However,…

Read More →

Back to Top