CORE JAVA 9TH EDITION PDF

adminComment(0)

Core Java™. Volume I—Fundamentals. Ninth Edition. Cay S. Horstmann. Gary Cornell. Upper Saddle River, NJ • Boston • Indianapolis • San Francisco. The Complete Reference, C++: McGraw-Hill has no responsibility for the content of any information Java The Comp Core Java Volume I F. pdfs/Core Java Volume I- Fundamentals 9th Edition- Horstmann, Cay S. & Cornell, Gary_pdf. Find file Copy path. Fetching contributors Cannot retrieve.


Core Java 9th Edition Pdf

Author:LISSETTE WILBUR
Language:English, Japanese, Dutch
Country:Saudi Arabia
Genre:Environment
Pages:226
Published (Last):11.11.2015
ISBN:556-7-75620-349-9
ePub File Size:21.41 MB
PDF File Size:19.21 MB
Distribution:Free* [*Register to download]
Downloads:48274
Uploaded by: MCKINLEY

CompRef_ / Java The Complete Reference, Ninth Edition /Schildt / At the core of the problem is the fact that malicious code can cause its. The Definitive Java Programming Guide Fully updated for Java SE 8, Java: The Complete Reference, Ninth Edition explains how to develop, compile, debug. Library of Congress Cataloging-in-Publication Data. Names: Horstmann, Cay S., author. Title: Core Java / Cay S. Horstmann. Description: Tenth edition.

Fully updated for Java SE 8, Java: The Complete Reference, Ninth Edition explains how to develop, compile, debug, and run Java programs. Bestselling programming author Herb Schildt covers the entire Java language, including its syntax, keywords, and fundamental programming principles, as well as significant portions of the Java API library.

JavaBeans, servlets, applets, and Swing are examined and real-world examples demonstrate Java in action. New Java SE 8 features such as lambda expressions, the stream library, and the default interface method are discussed in detail.

Stay ahead with the world's most comprehensive technology and business learning platform. With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial No credit card required. Java The Complete Reference, 9th Edition 23 reviews. View table of contents. Resource Bundles Message Formatting Advanced Swing Progress Indicators Text Components Component Organizers and Decorators Transparency and Composition The Clipboard Rendering Hints Drag and Drop Coordinate Transformations Image Manipulation Readers and Writers for Images Advanced AWT JavaBeans Persistence Bean Property Types JavaBeans Components The Bean-Writing Process Property Editors.

BeanInfo Classes Using Beans to Build an Application Naming Patterns for Bean Properties and Events User Authentication Code Signing Digital Signatures Security Managers and Permissions The Compiler API Distributed Objects Annotation Syntax Bytecode Engineering Native Methods Annotating Event Handlers Scripting GUI Events Standard Annotations Source-Level Annotation Processing Using Annotations Dynamic Java Code Generation..

Accessing the Windows Registry. About This Book The chapters in this book are. Streams let you deal. We then move on to regular xv. While we do refer to sections of the previous volume when appropriate and. Of course. We include detailed coverage of the reader and writer classes that make it easy to deal with Unicode. Strategically placed at the end of the bug report web page to encourage you to read the previous reports is a form that you can use to report bugs or problems and to send suggestions for improvements to future editions.

You should be able to delve into whatever topic interests you the most and read the chapters in any order. For this reason. In Java. Please note: If you are an experienced developer who is comfortable with advanced language features such as inner classes and generics. We show you what goes on under the hood when you use the object serialization mechanism.

As a useful example. Chapter 2 covers XML. As a result. We show you how to make network connections to servers. The Java programming language is one of the few languages designed from the start to handle Unicode. For example. The main focus is on JDBC.

Java makes it phenomenally easy to do complex network programming. We show you how to write your own beans that. Chapter 4 covers database programming. Chapter 3 covers the networking API. We show the basic uses of editor panes. Chapter 5 discusses a feature that we believe can only grow in importance: We show you how to write useful programs to handle realistic database chores. These features include printing and the APIs for cut-and-paste and drag-and-drop.

This API lets you work with Java objects that are distributed over multiple machines. Chapter 11 discusses three techniques for processing code. Chapter 10 covers distributed objects. We conclude this chapter by showing you how you can use JavaBeans persistence to store your data in a format that—unlike object serialization—is suitable for long-term storage.

At times. Outdated material has been removed. Preface other programmers can manipulate in integrated builder environments. Conventions As is common in many computer books. Chapter 9 takes up the Java security model. As always. Annotations are only useful with tools. We show you how to write your own class loaders and security managers for special-purpose applications.

Annotations allow you to add arbitrary information sometimes called metadata to a Java program. Chapter 12 takes up native methods. Use native methods. The Java platform was designed from the ground up to be secure. When there is danger ahead. Java comes with a large programming library. Application Programming Interface 1. These descriptions are a bit more informal but.

Listing 1.

The number after a class. The names of interfaces are in italics. Greg Doench. Nicholas J. David Brown. Doug Langston. Vladimir Ivanovic PointBase. Making a book a reality takes many dedicated people. Rob Gordon. Jerry Jackson ChannelPoint Software. Dan Gordon. Tim Kimmet Preview Systems. Charlie Lai. Vincent Hardy. Chris Crane devXsolution. Cliff Berg iSavvix Corporation. Bob Lynch Lynch Associates. John Gray University of Hartford.

Jim Gish Oracle. Rich Rosen Interactive Data Corporation. Angela Gordon. Chris Laffra. A large number of individuals at Prentice Hall provided valuable assistance. Reviewers of this and earlier editions include Chuck Allison Contributing Editor. Frank Cohen PushToTest. Paul Philion. William Higgins IBM. Blake Ragsdell. Acknowledgments Writing a book is always a monumental effort. Corky Cartwright. Peter Sanders xix. Gregory Longshore. Stuart Reges University of Arizona.

Lance Anderson Oracle. Brian Goetz Principal Consultant.

Stay ahead with the world's most comprehensive technology and business learning platform.

Joshua Bloch. De Lillo Manhattan College. Robert Evans Senior Staff. Quiotix Corp. Mark Lawrence. Philip Milne consultant. David Geary Sabreware. Hao Pham. Alec Beaton PointBase. I am particularly grateful to the excellent reviewing team that went over the manuscript with an amazing eye for detail and saved me from many more embarrassing errors.

I am very grateful to Julie Nahil for production support. Hang Lau McGill University. Mahesh Neelakanta Florida Atlantic University. Thanks to the many readers of earlier editions who reported embarrassing errors and made lots of thoughtful suggestions for improvement. Cameron Gregory olabs. Ylber Ramadani Ryerson University. Rakesh Dhoopar Oracle. Angelika Langer. 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. MIME type. Table Java SE 7 includes a version of Rhino.

Core Java Volume I--Fundamentals (9th Edition): 1 (Core Series)

Scripting languages have a number of advantages: When the virtual machine starts. For example: In the following sections. The other direction—accessing Java from the scripting language—is the responsibility of the scripting language provider. Most scripting languages that run on the Java virtual machine have this capability.

The site http: To enumerate them. It enables you to invoke scripts written in JavaScript. MIME types. It is therefore tempting to combine the advantages of scripting and traditional languages. 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.

Object value gets or puts a binding in the engine scope. Object value gets or puts a binding in the global scope. The Rhino engine does not have the notion of a standard input source. Any output written with the JavaScript print or println functions is sent to writer. Calling setReader has no effect. You can pass any Writer to the setWriter method. The script engines that offer this functionality implement the Invocable interface. 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. By default it reads the ButtonFrame class in Listing BLUE redButton. This seems like a good idea in general. Chapter 6. Let us look at the yellowButton in more detail. When the event occurs.

The details are a bit technical. The essential part. You might want to read the section on proxies in Volume I. We then process a script init. You can run this program with the JavaScript event handlers. 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.

Customers who viewed this item also viewed

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.

Core Java Volume I--Fundamentals (9th Edition): 1 (Core Series)

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.You dont find toy programs which illustrate the feature and do some printing on the console. To obtain permission to use material from this work. You cannot use the same annotation type more than once when annotating a particular item. FileLock API. Annotation processors may choose to generate XML descriptors.

For example, the following annotation has two elements, assignedTo and severity: