Complexity theory
Complexity theory This program was modified from code originally created by Larry O’Brien, and is based on the “Boids” program created by Craig Reynolds in 1986 to demonstrate an aspect of complexity theory called “emergence.” The goal hereCiteste tot ... 473 cuvinte
Dimensiune mica - fara poza |
|
|
Design patterns: The singleton
Design patterns This chapter introduces the important and yet non-traditional “patterns” approach to program design. Probably the most important step forward in object-oriented design is the “design patterns” movement, chronicled in Design PCiteste tot ... 1912 cuvinte
Dimensiune medie - fara imagini |
|
|
Constructors
Constructors When writing code with exceptions, it’s particularly important that you always ask, “If an exception occurs, will this be properly cleaned up?” Most of the time you’re fairly safe, but in constructors there’s a problem. The construCiteste tot ... 860 cuvinte
Dimensiune mica - fara poza |
|
|
Passing handles around: Aliasing
Passing handles around When you pass a handle into a method, you’re still pointing to the same object. A simple experiment demonstrates this: (See page 97 if you have trouble executing this program.) //: PassHandles.java // Passing haCiteste tot ... 562 cuvinte
Dimensiune mica - fara poza |
|
|
Network programming: Servers and clients
Network programming Historically, network programming has been error-prone, difficult, and complex. The programmer had to know many details about the network and sometimes even the hardware. You usually needed to understand the various “layeCiteste tot ... 9295 cuvinte
Dimensiune mare - fara imagini |
|
|
The comma operator
The comma operator Earlier in this chapter I stated that the comma operator (not the comma separator, which is used to separate function arguments) has only one use in Java: in the control expression of a for loop. In both the initialization anCiteste tot ... 117 cuvinte
Dimensiune mica - fara poza |
|
|
Using Maps
Using Maps Map (interface) Maintains key-value associations (pairs), so you can look up a value using a key. HashMap* Implementation based on a hash table. (Use this instead of Hashtable.) PrCiteste tot ... 466 cuvinte
Dimensiune mica - fara poza |
|
|
The Java Native Interface: Calling a native method
The Java Native Interface JNI is a fairly rich programming interface that allows you to call native methods from a Java application. It was added in Java 1.1, maintaining a certain degree of compatibility with its Java 1.0 equivalent, the nativCiteste tot ... 2178 cuvinte
Dimensiune medie - fara imagini |
|
|
Catching an exception: The try block, Exception handle
Catching an exception If a method throws an exception, it must assume that exception is caught and dealt with. One of the advantages of Java exception handling is that it allows you to concentrate on the problem you’re trying to solve in one plCiteste tot ... 1634 cuvinte
Dimensiune medie - fara imagini |
|
|
Package: the library unit
package: the library unit A package is what you get when you use the import keyword to bring in an entire library, such as import java.util.*; This brings in the entire utility library that’s part of the standard Java distribCiteste tot ... 846 cuvinte
Dimensiune mica - fara poza |
|
|
Raw Native Interface (RNI)
Raw Native Interface (RNI) Compared to J/Direct, RNI is a fairly complex interface to non-Java code, but it’s much more powerful. RNI is closer to the JVM than J/Direct, and this lets you write much more efficient code, manipulate Java objectsCiteste tot ... 486 cuvinte
Dimensiune mica - fara poza |
|
|
Creating windows and applets
Creating windows and applets The original design goal of the graphical user interface (GUI) library in Java 1.0 was to allow the programmer to build a GUI that looks good on all platforms. That goal was not achieved. Instead, the Java 1.0 Citeste tot ... 2856 cuvinte
Dimensiune medie - fara imagini |
|
|
Upcasting
Upcasting In Chapter 6 you saw how an object can be used as its own type or as an object of its base type. Taking an object handle and treating it as the handle of the base type is called upcasting because of the way inheritance trees are drawnCiteste tot ... 466 cuvinte
Dimensiune mica - fara poza |
|
|
Remote methods: Remote interfaces
Remote methods Traditional approaches to executing code on other machines across a network have been confusing as well as tedious and error-prone to implement. The nicest way to think about this problem is that some object happens to live on anCiteste tot ... 1660 cuvinte
Dimensiune medie - fara imagini |
|
|
Inner classes - Inner classes and upcasting
Inner classes In Java 1.1 it’s possible to place a class definition within another class definition. This is called an inner class. The inner class is a useful feature because it allows you to group classes that logically belong together and toCiteste tot ... 4738 cuvinte
Dimensiune medie - fara imagini |
|
|
Default constructors
Default constructors As mentioned previously, a default constructor is one without arguments, used to create a “vanilla object.” If you create a class that has no constructors, the compiler will automatically create a default constructor for yoCiteste tot ... 159 cuvinte
Dimensiune mica - fara poza |
|
|
Utilities: Making a Collection or Map unmodifiable
Utilities There are a number of other useful utilities in the Collections class: enumeration(Collection) Produces an old-style Enumeration for the argument. max(Collection) min(Collection)Citeste tot ... 640 cuvinte
Dimensiune mica - fara poza |
|
|
Capturing an event
Capturing an event You’ll notice that if you compile and run the applet above, nothing happens when you press the buttons. This is where you must step in and write some code to determine what will happen. The basis of event-driven programming,Citeste tot ... 955 cuvinte
Dimensiune mica - fara poza |
|
|
Making a button
Making a button Making a button is quite simple: you just call the Button constructor with the label you want on the button. (You can also use the default constructor if you want a button with no label, but this is not very useful.) Usually you’Citeste tot ... 189 cuvinte
Dimensiune mica - fara poza |
|
|
Calculation details
Calculation details The statement: char c = (char)(Math.random() * 26 + 'a'); deserves a closer look. Math.random( ) produces a double, so the value 26 is converted to a double to perform the multiplication, which also prCiteste tot ... 301 cuvinte
Dimensiune mica - fara poza |
|
|
Alte pagini