Core Java®. Volume II—Advanced Features Chapter 1: The Java SE 8 Stream Library .. 2 . Chapter 2: Input and Output. Core Java 2, Volume 1-Fundamentals covers the fundamentals of. Java 2 Platform Standard Edition, Version and includes completely revised discussions of. A TEXTBook OF. ELECTRICAL. TECHNOLOGY. IN. S.I. UNITS. Volume II. AC & DC MACHINES. paidestparpoisun.ml ELECTR.
|Language:||English, Spanish, Dutch|
|Genre:||Children & Youth|
|Distribution:||Free* [*Register to download]|
Core Java / Cay S. Horstmann, Gary Cornell.—Ninth edition. pages cm. Includes index. . Chapter 2: XML. The book you have in your hands is the second volume of the ninth edition of. Core Java®, fully PDF format, printing, Core Java / Cay S. Horstmann, Gary Cornell.—Ninth edition. pages cm. Includes index. . Chapter 2: XML. Chapter 6 contains all the Swing material that didn 't make it into Volume I, especially the important PDF format, printing, Request PDF on ResearchGate | Core Java, Vol. 2: Advanced Features, 8th Edition | The revised edition of the classic Core Java, Volume IIAdvanced Features.
We show you how to make network connections to servers, how to implement your own servers, and how to make HTTP connections. Chapter 4 covers database programming. Chapter 5 discusses a feature that we believe can only grow in importance: internationalization. The Java programming language is one of the few languages designed from the start to handle Unicode, but the internationalization support in the Java platform goes much further. As a result, you can internationalize Java applications so that they not only cross platforms but cross country boundaries as well.
For example, we show you how to write a retirement calculator that uses either English, German, or Chinese languages. Chapter 6 contains all the Swing material that didnt make it into Volume I, especially the important but complex tree and table components. We show the basic uses of editor panes, the Java implementation of a multiple document interface, progress indicators used in multithreaded programs, and desktop integration features such as splash screens and support for the system tray.
Again, we focus on the most useful constructs that you are likely to encounter in practical programming because an encyclopedic coverage of the entire Swing library would ll several volumes and would only be of interest to dedicated taxonomists.
Chapter 7 covers the Java 2D API, which you can use to create realistic drawings and special effects. The chapter also covers some advanced features of the AWT Abstract Windowing Toolkit that seemed too specialized for coverage in Volume I but should, nonetheless, be part of every programmers toolkit.
Monitoring the Progress of Input Streams 6. Component Organizers and Decorators 6. Split Panes 6. Tabbed Panes 6. Desktop Panes and Internal Frames 6.
Cascading and Tiling 6. Vetoing Property Settings Chapter 7. Advanced AWT 7. The Rendering Pipeline 7. Shapes 7. Using the Shape Classes 7. Areas 7. Strokes 7. Paint 7.
Coordinate Transformations 7. Clipping 7. Transparency and Composition 7. Rendering Hints 7. Readers and Writers for Images 7. Reading and Writing Files with Multiple Images 7. Image Manipulation 7.
Constructing Raster Images 7. Filtering Images 7. Printing 7. Graphics Printing 7.
Multiple-Page Printing 7. Print Preview 7. Print Services 7. Stream Print Services 7. Printing Attributes 7. The Clipboard 7. Classes and Interfaces for Data Transfer 7.
Transferring Text 7. The Transferable Interface and Data Flavors 7. Building an Image Transferable 7. Transferring Java Objects via the System Clipboard 7. Drag and Drop 7. Data Transfer Support in Swing 7.
Drag Sources 7. Drop Targets 7. Platform Integration 7. Splash Screens 7. Launching Desktop Applications 7.
The System Tray Chapter 8. JavaBeans Components 8. Why Beans? The Bean-Writing Process 8. Using Beans to Build an Application 8. Composing Beans in a Builder Environment 8. Naming Patterns for Bean Properties and Events 8. Bean Property Types 8. Simple Properties 8. Indexed Properties 8. Bound Properties 8. Constrained Properties 8.
BeanInfo Classes 8. Property Editors 8. Writing Property Editors 8. Customizers 8. Writing a Customizer Class 8. JavaBeans Persistence 8. Security 9. Class Loaders 9. The Class Loader Hierarchy 9.
Using Class Loaders as Namespaces 9. Writing Your Own Class Loader 9. Bytecode Verification 9. Security Managers and Permissions 9. Java Platform Security 9. Security Policy Files 9. Custom Permissions 9. Implementation of a Permission Class 9. User Authentication 9. Digital Signatures 9. Message Digests 9. Message Signing 9. Verifying a Signature 9. The Authentication Problem 9. Certificate Signing 9. Certificate Requests 9. Code Signing 9. JAR File Signing 9. Software Developer Certificates 9.
Encryption 9. Symmetric Ciphers 9. Key Generation 9. Cipher Streams 9. Public Key Ciphers Chapter Scripting, Compiling, and Annotation Processing Scripting for the Java Platform Getting a Scripting Engine Script Evaluation and Bindings Redirecting Input and Output Calling Scripting Functions and Methods Compiling a Script Christopher Taylor. Peter van der Linden. Burt Walsh. Cay Horstmann San Francisco. Janet Traub. Steven Stelting.
Bradley A. California December Joe Wang Oracle. George Thiruvathukal. Second Edition. Paul Tyma consultant. Paul Sevinc Teamup AG.
Luke Taylor Valtech.
Devang Shah. As you will see. You can use the compiler API when you want to compile Java code inside your application.
The scripting API lets you do just that for the Java platform. You can ask each engine factory for the supported engine names. Concurrent execution is safe. In addition to the engine scope. Effects from one thread might be visible from another thread.
Instead of adding bindings to the engine or global scope. You will often want to add variable bindings to the engine. Any bindings that you add to the ScriptEngineManager are visible to all engines. The returned value is one of the following: Concurrent execution is not safe. A binding consists of a name and an associated Java object.
Bindings bindings evaluates the script given by the string or reader. You will need to write a class that implements the ScriptContext interface. The standard library provides a SimpleScriptContext class. You might want to have scopes other than the engine and global scopes. Object value gets or puts a binding into the scope represented by this Bindings object. Bindings bindings Object eval Reader reader. This is useful if a set of bindings should not persist for future calls to the eval method.
In particular. Then you can call scripting functions and methods with the Java method call syntax. If the scripting language is object-oriented. The details depend on the scripting engine. If the script engine does not implement the Invocable interface. You can go a step further and ask the scripting engine to implement a Java interface.
It must be the result of a prior call to the scripting engine. The getMethodCallSyntax method of the ScriptEngineFactory interface produces a string that you can pass to the eval method.
Invocable engine. This is useful if you allow users to implement a service in a scripting language of their choice. To call a function. Fifth Edition. Behind the scenes. String name. This approach is similar to making a remote method call. When you call g. In summary.
In an object-oriented scripting language. The result is a string "Goodbye.. Once the script is compiled. Have a look at the program in Listing Those engines implement the Compilable interface. The following code executes the compiled script if compilation was successful.
When the line yellowButton. For each property. We then attach an ActionListener with an actionPerformed method that executes the script panel.
For the Groovy handlers, use java -classpath.: Here, groovy is the directory into which you installed Groovy, and jsrengines is the directory that contains the engine adapters from http: This application demonstrates how to use scripting for Java GUI programming.
Note the similarity to a dynamic HTML page or a dynamic server-side scripting environment. Listing Container c. There are quite a few tools that need to invoke the Java compiler. This section explains the compiler API.
A result value of 0 indicates successful compilation. As of Java SE 6. The run method is inherited from a generic Tool interface Now we turn to a different scenario: Java programs that compile Java code. In particular.. The compiler sends output and error messages to the provided streams. The remaining parameters of the run method are simply the arguments that you would pass to javac if you invoked it on the command line. You can set these parameters to null.
As the compiler takes no console input. Here is a sample call: To obtain a CompilationTask object. The listener receives a Diagnostic object whenever the compiler reports a warning or error message. It simply collects all diagnostics so that you can iterate through them after the compilation is complete. To listen to error messages. The DiagnosticCollector class implements this interface. You need to specify: CompilationTask null. FALSE indicates failure. In our situation. We achieve this with the following outline: You can pass it to an Executor for execution in another thread.
The class extends the SimpleJavaFileObject convenience class and overrides the getCharContent method to return the content of the string builder. Kind kind. A return value of Boolean. You can capture the output and error messages. Its API is quite complex. You can supply null for default error reporting..
Returns 0 for success. Continues Locale locale. OutputStream out. OutputStream err. JavaFileManager fileManager. Pass null for the default locale. CompilationTask getTask Writer out. See the discussion in the preceding section for details. We leave it as the proverbial exercise to the reader to extend the code generation to other event types. Our code generator will produce a subclass that implements the addEventHandlers method. String className. In our sample application.
We place the subclass into a package with the name x. The generated code has the form Location location. Note that the constructor of the frame class calls an abstract method addEventHandlers.
Note that compiling the x. Now the Yellow button is disabled after you click it. A simple class loader shown in Listing We ask the class loader to load the class that we just compiled. Frame class is compiled.
To see that the actions are dynamically compiled. That object is passed to the Java compiler. Run the program again. Also have a look at the code directories. When you click the buttons.. After compilation. Annotations do not change the way in which your programs are compiled. The Java compiler generates the same virtual machine instructions with or without the annotations. You need to use annotations that your processing tool understands, then apply the processing tool to your code.
Here are some uses for annotations: We will mark methods as event listeners for AWT components, and show you an annotation processor that analyzes the annotations and hooks up the listeners.
Here is an example of a simple annotation: The annotation Test annotates the checkRandomInsertions method. The name of each annotation is preceded by an symbol, similar to Javadoc comments. By itself, the Test annotation does not do anything. It needs a tool to be useful. For example, the JUnit 4 testing tool available at http: These elements can be processed by the tools that read the annotations.
The methods of the interface correspond to the elements of the annotation. Target ElementType. The interface declaration creates an actual Java interface. Tools that process annotations receive objects that implement the annotation interface. A tool would call the timeout method to retrieve the timeout element of a particular Test annotation. The Target and Retention annotations are meta-annotations. You have now seen the basic concepts of program metadata and annotations. Annotating Event Handlers One of the more boring tasks in user interface programming is the wiring of listeners to event sources.
Many listeners are of the form. The annotation. The classes Method. That is the job of the ActionListenerInstaller class. The code is in Listing We retrieve it by calling the source method. This shows a limitation of our annotation.
Chapter 8. The static processAnnotations method enumerates all methods of the object it received. In this section. For each method. We now need a mechanism to analyze them and install action listeners. It cannot be a local variable. In fact. The details are not important. In this example. EventHandler class tries to do just that. You can see an example in Section Figure For more information about proxies.
A utility method for adding a listener could be just as convenient for the programmer as the annotation. The key observation is that the functionality of the annotations was established by the processAnnotations method. It is also possible to process them at the source level.
This sounds complex. For each annotated method. Our example was not intended as a serious tool for user interface programmers.
You could make the class truly useful by supplying a method that adds the event handler instead of just constructing it. Having seen a concrete example. AnnotatedElement 5. If no annotations are present, an array of length 0 is returned. For example, the following annotation has two elements, assignedTo and severity: Two special shortcuts can simplify annotations.
The other shortcut is the single value annotation. Defaults are not stored with the annotation. String assignedTo default "[none]". The type of an annotation element is one of the following: The methods of an annotation interface can have no parameters and no throws clauses. Method m. See the API notes at the end of this section for the methods provided by this interface. You never supply classes that implement annotation interfaces.
You cannot extend annotation interfaces. Annotation interface. In other words. The element declarations in the annotation interface are actually method declarations.
That interface is a regular interface. Reference ref default Reference. Not even a default of null is permissible. If an element value is an array. An annotation element can never be set to null.
It is an error to introduce circular dependencies in annotations. You can add annotations to the following items: BugReport has an element of the annotation type Reference. This can be rather inconvenient in practice. If this is a problem. An item can have multiple annotations.
Annotation 5. Note that calling getClass on an annotation object would return the actual class. You cannot use the same annotation type more than once when annotating a particular item. Generated All Marks an item as source code that has been generated by a tool. Override Methods Checks that this method overrides a superclass method.
PostConstruct PreDestroy Methods The marked method should be invoked immediately after construction or before removal. Four of them are meta-annotations that describe the behavior of annotation interfaces. The others are regular annotations that you can use to annotate items in your source code.
SuppressWarnings All but packages and annotations Suppresses warnings of the given type. Resource Classes. The Generated annotation is intended for use by code generator tools. A date string in ISO format and a comment string are optional. SuppressWarnings "unchecked" The Override annotation applies only to methods. The compiler will warn when you use a deprecated item. The Resource annotation is intended for resource injection. Any generated source code can be annotated to differentiate it from programmer-provided code.
In the web application. Methods tagged with these annotations should be invoked immediately after an object has been constructed or immediately before it is being removed. The compiler checks that a method with this annotation really overrides a method from the superclass. The SuppressWarnings annotation tells the compiler to suppress warnings of a particular type. After all.. Generated "com. This annotation has the same role as the deprecated Javadoc tag. You can specify at most one of the values in Table In Listing They belong to the enumerated type ElementType.
You can specify any number of element types. In the following two sections. The compiler checks that you apply an annotation only to a permitted item. The default is RetentionPolicy. An annotation without an Target restriction can be applied to any item.
The Documented meta-annotation gives a hint to documentation tools such as Javadoc. When a class has an inherited annotation. The use of other annotations is not included in the documentation. If an annotation is transient such as BugReport. The Inherited meta-annotation applies only to annotations for classes. This makes it easy to create annotations that work as marker interfaces. Documented Target ElementType. An annotation describes this fact better than does interface inheritance. It is legal to apply an annotation to itself.