Member initialization
Member initialization Java goes out of its way to guarantee that any variable is properly initialized before it is used. In the case of variables that are defined locally to a method, this guarantee comes in the form of a compile-time error. SCiteste tot ... 248 cuvinte
Dimensiune mica - fara poza |
|
|
Blocking: Becoming blocked
Blocking A thread can be in any one of four states: 1. New: the thread object has been created but it hasn’t been started yet so it cannot run. 2. Runnable: This mCiteste tot ... 2837 cuvinte
Dimensiune medie - fara imagini |
|
|
public: interface access
public: interface access When you use the public keyword, it means that the member declaration that immediately follows public is available to everyone, in particular to the client programmer who uses the library. Suppose you define a package deCiteste tot ... 319 cuvinte
Dimensiune mica - fara poza |
|
|
Standard Java exceptions: The special case of RuntimeException
Standard Java exceptions Java contains a class called Throwable that describes anything that can be thrown as an exception. There are two general types of Throwable objects (“types of” = “inherited from”). Error represents compile-time and systCiteste tot ... 710 cuvinte
Dimensiune mica - fara poza |
|
|
Name hiding
Name hiding Only C++ programmers might be surprised by name hiding, since it works differently in that language. If a Java base class has a method name that’s overloaded several times, redefining that method name in the derived class will notCiteste tot ... 138 cuvinte
Dimensiune mica - fara poza |
|
|
The need for RTTI: The Class object
The need for RTTI Consider the now familiar example of a class hierarchy that uses polymorphism. The generic type is the base class Shape, and the specific derived types are Circle, Square, and Triangle:Citeste tot ... 2300 cuvinte
Dimensiune medie + cu poze |
|
|
The “visitor” pattern
The “visitor” pattern Now consider applying a design pattern with an entirely different goal to the trash-sorting problem. For this pattern, we are no longer concerned with optimizing the addition of new types of Trash to the system. IndeedCiteste tot ... 961 cuvinte
Dimensiune mica + cu imagini |
|
|
StreamTokenizer: StringTokenizer
StreamTokenizer Although StreamTokenizer is not derived from InputStream or OutputStream, it works only with InputStream objects, so it rightfully belongs in the IO portion of the library. The StreamTokenizer class is used to break any InputCiteste tot ... 937 cuvinte
Dimensiune mica - fara poza |
|
|
Array initialization
Array initialization Initializing arrays in C is error-prone and tedious. C++ uses aggregate initialization to make it much safer.[1] Java has no “aggregates” like C++, since everything is an object in Java. It does have arrays, and these areCiteste tot ... 1021 cuvinte
Dimensiune mica - fara poza |
|
|
Exception matching
Exception matching When an exception is thrown, the exception-handling system looks through the “nearest” handlers in the order they are written. When it finds a match, the exception is considered handled, and no further searching occurs. MaCiteste tot ... 316 cuvinte
Dimensiune mica - fara poza |
|
|
Grouping constants
Grouping constants Because any fields you put into an interface are automatically static and final, the interface is a convenient tool for creating groups of constant values, much as you would with an enum in C or C++. For example: //: MCiteste tot ... 391 cuvinte
Dimensiune mica - fara poza |
|
|
Java 1.1 IO streams: Sources and sinks of data
Java 1.1 IO streams At this point you might be scratching your head, wondering if there is another design for IO streams that could require more typing. Could someone have come up with an odder design?” Prepare yourself: Java 1.1 makes some siCiteste tot ... 1885 cuvinte
Dimensiune medie - fara imagini |
|
|
Sorting
Sorting One of the things missing in the Java 1.0 and 1.1 libraries is algorithmic operations, even simple sorting. So it makes sense to create a Vector that sorts itself using the classic Quicksort. A problem with writing generic sorting coCiteste tot ... 1036 cuvinte
Dimensiune mica - fara poza |
|
|
Overloading on return values
Overloading on return values It is common to wonder “Why only class names and method argument lists? Why not distinguish between methods based on their return values?” For example, these two methods, which have the same name and arguments, areCiteste tot ... 138 cuvinte
Dimensiune mica - fara poza |
|
|
if-else
if-else The if-else statement is probably the most basic way to control program flow. The else is optional, so you can use if in two forms: if(Boolean-expression) statement or if(Boolean-expression) statement else statementCiteste tot ... 115 cuvinte
Dimensiune mica - fara poza |
|
|
Initializing the base class
Initializing the base class Since there are now two classes involved – the base class and the derived class – instead of just one, it can be a bit confusing to try to imagine the resulting object produced by a derived class. From the outside, iCiteste tot ... 441 cuvinte
Dimensiune mica - fara poza |
|
|
return
return The return keyword has two purposes: it specifies what value a method will return (if it doesn’t have a void return value) and it causes that value to be returned immediately. The test( ) method above can be rewritten to take advantCiteste tot ... 55 cuvinte
Dimensiune mica - fara poza |
|
|
Introduction to Swing: Buttons, Icons, Menus
Introduction to Swing[1] [SE1] After working your way through this chapter and seeing the huge changes that have occurred within the AWT (although, if you can remember back that far, Sun claimed Java was a “stable” language when it first aCiteste tot ... 4327 cuvinte
Dimensiune medie - fara imagini |
|
|
Returning an array
Returning an array Suppose you’re writing a method and you don’t just want to return one thing, but a whole bunch of things. Languages like C and C++ make this difficult because you can’t just return an array, only a pointer to an array. This iCiteste tot ... 406 cuvinte
Dimensiune mica - fara poza |
|
|
Multidimensional arrays
Multidimensional arrays Java allows you to easily create multidimensional arrays: //: MultiDimArray.java // Creating multidimensional arrays. import java.util.*; public class MultiDimArray public static void main(StrCiteste tot ... 468 cuvinte
Dimensiune mica - fara poza |
|
|
Alte pagini