Controlling cloneability: The copy-constructor
Controlling cloneability You might suggest that, to remove clonability, the clone( ) method simply be made private, but this won’t work since you cannot take a base-class method and make it more private in a derived class. So it’s not thatCiteste tot ... 1795 cuvinte
Dimensiune medie - fara imagini |
|
|
protected: “sort of friendly”
protected: “sort of friendly” The protected access specifier requires a jump ahead to understand. First, you should be aware that you don’t need to understand this section to continue through the book up through the inheritance chapter. But forCiteste tot ... 201 cuvinte
Dimensiune mica - fara poza |
|
|
Collections - Disadvantage: unknown type
Collections To summarize what we’ve seen so far, your first, most efficient choice to hold a group of objects should be an array, and you’re forced into this choice if you want to hold a group of primitives. In the remainder of the chapter we’lCiteste tot ... 1228 cuvinte
Dimensiune mica - fara poza |
|
|
Sharing limited resources: Improperly accessing resources
Sharing limited resources You can think of a single-threaded program as one lonely entity moving around through your problem space and doing one thing at a time. Because there’s only one entity, you never have to think about the problem of twoCiteste tot ... 2548 cuvinte
Dimensiune medie - fara imagini |
|
|
Unsupported operations
Unsupported operations It’s possible to turn an array into a List with the static Arrays.toList( ) method: //: Unsupported.java // Sometimes methods defined in the Collection // interfaces don't work! package c08.newcollectioCiteste tot ... 591 cuvinte
Dimensiune mica - fara poza |
|
|
Java programming guidelines
Java programming guidelines This appendix contains suggestions to help guide you while performing low-level program design, and also while writing code. 1. Capitalize the first letter of class names. The fCiteste tot ... 1533 cuvinte
Dimensiune medie - fara imagini |
|
|
The new AWT: The new event model
The new AWT In Java 1.1 a dramatic change has been accomplished in the creation of the new AWT. Most of this change revolves around the new event model used in Java 1.1: as bad, awkward, and non-object-oriented as the old event model was, theCiteste tot ... 7526 cuvinte
Dimensiune mare - fara imagini |
|
|
Text fields
Text fields A TextField is a one line area that allows the user to enter and edit text. TextField is inherited from TextComponent, which lets you select text, get the selected text as a String, get or set the text, and set whether the TextFieldCiteste tot ... 208 cuvinte
Dimensiune mica - fara poza |
|
|
Specifying initialization
Specifying initialization What happens if you want to give a variable an initial value? One direct way to do this is simply to assign the value at the point you define the variable in the class. (Notice you cannot do this in C++, although C++ nCiteste tot ... 150 cuvinte
Dimensiune mica - fara poza |
|
|
RTTI syntax
RTTI syntax Java performs its RTTI using the Class object, even if you’re doing something like a cast. The class Class also has a number of other ways you can use RTTI. First, you must get a handle to the appropriate Class object. One way toCiteste tot ... 547 cuvinte
Dimensiune mica - fara poza |
|
|
The twist - Method call binding
The twist The difficulty with Music.java can be seen by running the program. The output is Wind.play( ). This is clearly the desired output, but it doesn’t seem to make sense that it would work that way. Look at the tune( ) method:Citeste tot ... 1219 cuvinte
Dimensiune mica + cu imagini |
|
|
Class access
Class access In Java, the access specifiers can also be used to determine which classes within a library will be available to the users of that library. If you want a class to be available to a client programmer, you place the public keywordCiteste tot ... 500 cuvinte
Dimensiune mica - fara poza |
|
|
Performance: Locating the bottleneck
Performance This appendix was contributed by and used with the permission of Joe Sharp, consultant (SharpJoe@aol.com). The Java language emphasizes accurate, reliable behavior at the expense of performance. This is reflected in features suchCiteste tot ... 2531 cuvinte
Dimensiune medie - fara imagini |
|
|
The generic collection library
The generic collection library You’ve seen in this chapter that the standard Java library has some fairly useful collections, but far from a complete set. In addition, algorithms like sorting are not supported at all. One of the strengths of C+Citeste tot ... 2170 cuvinte
Dimensiune medie + cu poze |
|
|
switch
switch The switch is sometimes classified as a selection statement. The switch statement selects from among pieces of code based on the value of an integral expression. Its form is: switch(integral-selector) Integral-selector is an expresCiteste tot ... 379 cuvinte
Dimensiune mica - fara poza |
|
|
Connecting to databases with JDBC
Connecting to databases with JDBC It has been estimated that half of all software development involves client/server operations. A great promise of Java has been the ability to build platform-independent client/server database applications. InCiteste tot ... 2418 cuvinte
Dimensiune medie - fara imagini |
|
|
Simulating the trash recycler
Simulating the trash recycler The nature of this problem is that the trash is thrown unclassified into a single bin, so the specific type information is lost. But later, the specific type information must be recovered to properly sort the trashCiteste tot ... 3357 cuvinte
Dimensiune medie - fara imagini |
|
|
The this keyword
The this keyword If you have two objects of the same type called a and b, you might wonder how it is that you can call a method f( ) for both those objects: class Banana } Banana a = new Banana(), b = new Banana(); a.f(1); bCiteste tot ... 344 cuvinte
Dimensiune mica - fara poza |
|
|
Overriding vs
Overriding vs. overloading Let’s take a different look at the first example in this chapter. In the following program, the interface of the method play( ) is changed in the process of overriding it, which means that you haven’t overriddenCiteste tot ... 274 cuvinte
Dimensiune mica - fara poza |
|
|
Constructors and polymorphism - Order of constructor calls
Constructors and polymorphism As usual, constructors are different from other kinds of methods. This is also true when polymorphism is involved. Even though constructors are not polymorphic (although you can have a kind of “virtual constructorCiteste tot ... 1636 cuvinte
Dimensiune medie - fara imagini |
|
|
Alte pagini