JAVA IN A NUTSHELL O'REILLY. David Flanagan. Fifth Edition. Beijing Cambridge Farnham Köln Sebastopol Tokyo



Similar documents
JAVA. EXAMPLES IN A NUTSHELL. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo. Third Edition.

core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt

The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0

Web Development in Java

Fundamentals of Java Programming

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

C#5.0 IN A NUTSHELL. Joseph O'REILLY. Albahari and Ben Albahari. Fifth Edition. Tokyo. Sebastopol. Beijing. Cambridge. Koln.

Tools in the Box. Quick overview on helpful tools in the JDK and use cases for them. Florin Bunau

JAVA r VOLUME II-ADVANCED FEATURES. e^i v it;

Java Application Developer Certificate Program Competencies

Java Interview Questions and Answers

An Overview of Java. overview-1

AP Computer Science Java Subset

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE. CISY 105 Foundations of Computer Science

Java Programming Fundamentals

PYTHON IN A NUTSHELL. O'REILLY Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo. Alex Martelli. Second Edition

Java SE 7 Programming

Java (12 Weeks) Introduction to Java Programming Language

Crash Course in Java

JavaScript Patterns. Stoyan Stefanov. O'REILLY' Beijing Cambridge Farnham Koln Sebastopol Tokyo

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

Java SE 8 Programming

Java the UML Way: Integrating Object-Oriented Design and Programming

Java SE 7 Programming

Java SE 7 Programming

Windows PowerShell Cookbook

DIPLOMADO DE JAVA - OCA

Computing Concepts with Java Essentials

JAVA 2 Network Security

Course Number: IAC-SOFT-WDAD Web Design and Application Development

The C Programming Language course syllabus associate level

CS 111 Classes I 1. Software Organization View to this point:

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Enterprise Java. Where, How, When (and When Not) to Apply Java in Client/Server Business Environments. Jeffrey Savit Sean Wilcox Bhuvana Jayaraman

Java EE Web Development Course Program

Enterprise JavaBeans 3.1

Glossary of Object Oriented Terms

Pemrograman Dasar. Basic Elements Of Java

Programmation 2. Introduction à la programmation Java

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

El Dorado Union High School District Educational Services

C++ INTERVIEW QUESTIONS

TYLER JUNIOR COLLEGE School of Continuing Studies 1530 SSW Loop 323 Tyler, TX

Course Title: Software Development

Computer Programming I

Lecture 5: Java Fundamentals III

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

The Designer's Guide to VHDL

Java Programming Language

CS 209 Programming in Java #1

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

The HTTP Plug-in. Table of contents

MarkLogic Server. Java Application Developer s Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

BHARATHIAR UNIVERSITY COIMBATORE SCHOOL OF DISTANCE EDUCATION

Chapter 1 Fundamentals of Java Programming

JavaCard. Java Card - old vs new

Oracle PL/SQL Programming

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

Chapter 2: Elements of Java

Contents. 9-1 Copyright (c) N. Afshartous

Object-Oriented Programming in C# (VS 2010)

: provid.ir

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Basic Programming and PC Skills: Basic Programming and PC Skills:

Programming Language Pragmatics

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Android Application Development Course Program

Specialized Programme on Web Application Development using Open Source Tools

Java CPD (I) Frans Coenen Department of Computer Science

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Certified PHP Developer VS-1054

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Yarmouk University Faculty of Science and Information Technology Department of Computer Information Systems CIS 282 Developing Web Applications

Agent Languages. Overview. Requirements. Java. Tcl/Tk. Telescript. Evaluation. Artificial Intelligence Intelligent Agents

ARIZONA CTE CAREER PREPARATION STANDARDS & MEASUREMENT CRITERIA SOFTWARE DEVELOPMENT,

COMMUNITY COLLEGE OF CITY UNIVERSITY CITY UNIVERSITY OF HONG KONG

Syllabus for CS 134 Java Programming

Paillier Threshold Encryption Toolbox

#820 Computer Programming 1A

70-536VB:.NET Framework Application Development Foundation Course Introduction

Programming Flash Communication Server

Java Power Tools. John Ferguson Smart. ULB Darmstadt 1 PI. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Object Oriented Software Design

Programming Languages

Web Security Testing Cookbook*

CS506 Web Design and Development Solved Online Quiz No. 01

Computer Programming I

Specialized Programme on Web Application Development using Open Source Tools

Java from a C perspective. Plan

To Java SE 8, and Beyond (Plan B)

DC60 JAVA AND WEB PROGRAMMING JUNE b. Explain the meaning of the following statement public static void main (string args [ ] )

Introduction...3 Terms in this Document...3 Conditions for Secure Operation...3 Requirements...3 Key Generation Requirements...

Transcription:

JAVA 1i IN A NUTSHELL Fifth Edition David Flanagan O'REILLY Beijing Cambridge Farnham Köln Sebastopol Tokyo

Table of Contents Preface xvii Part 1. Introducing Java 1. Introduction 1 What 1s Java? 1 The Java Programming Language 1 The Java Virtual Machine 2 The Java Platform 2 Versions of Java 3 Key Benefits of Java 4 Write Once, Run Anywhere 4 Security 5 Network-Centric Programming 5 Dynamic, Extensible Programs 5 Internationalization 6 Performance 6 Programmer Efficiency and Time-to-Market 6 An Example Program 7 Compiling and Running the Program 7 Analyzing the Program 9 Exceptions 15 2. Java Syntax from the Ground Up 17 Java Programs from the Top Down 18 vii

Lexical Structure 18 The Unicode Character Set 18 Case-Sensitivity and Whitespace 19 Comments 19 Reserved Words 20 Identifiers 20 Literals 21 Punctuation 21 Primitive Data Types 21 The boolean Type 22 The char Type 22 Strings 24 Integer Types 24 Floating-Point Types 25 Primitive Type Conversions 26 Expressions and Operators 28 Operator Summary 28 Arithmetic Operators 32 String Concatenation Operator 33 Increment and Decrement Operators 34 Comparison Operators 34 Boolean Operators 35 Bitwise and Shift Operators 37 Assignment Operators 39 The Conditional Operator 39 The instanceof Operator 40 Special Operators 40 Statements 42 Expression Statements 42 Compound Statements 43 The Empty Statement 43 Labeled Statements 43 Local Variable Declaration Statements 43 The if/else Statement 44 The switch Statement 46 The while Statement 48 The do Statement 49 The for Statement 49 The for/in Statement 50 The break Statement 54 The continue Statement 54 The return Statement 55 The synchronized Statement 55 The throw Statement 56 The try/catch/finally Statement 58 The assert Statement 60 viii I Table of Contents

Methods 64 Defining Methods 64 Method Modifiers 66 Declaring Checked Exceptions 68 Variable-Length Argument Lists 69 Covariant Return Types 70 Classes and Objects Introduced 71 Defining a Class 72 Creating an Object 72 Using an Object 73 Object Literals 73 Arrays 74 Array Types 75 Creating and Initializing Arrays 76 Using Arrays 77 Multidimensional Arrays 80 Reference Types 81 Reference vs. Primitive Types 82 Copying Objects 83 Comparing Objects 85 Terminology: Pass by Value 86 Memory Allocation and Garbage Collection 86 Reference Type Conversions 86 Boxing and Unboxing Conversions 88 Packages and the Java Namespace 89 Package Deciaration 90 Globally Unique Package Names 90 Importing Types 90 Importing Static Members 92 Java File Structure 93 Defining and Running Java Programs 94 Differences Between C and Java 95 3. Object-Oriented Programming in Java 98 Class Definition Syntax 99 Fields and Methods 100 Field Deciaration Syntax 101 Class Fields 102 Class Methods 102 Instance Fields 103 Instance Methods 104 Case Study: System. out. prin tln ( ) 106 Creating and Initializing Objects 106 Defining a Constructor 107 Table of Contents ix

Defining Multiple Constructors 108 Invoking One Constructor from Another 108 Field Defaults and Initializers 109 Destroying and Finalizing Objects 111 Garbage Collection 111 Memory Leaks in Java 112 Object Finalization 113 Subclasses and Inheritance 114 Extending a Class 114 Superclasses, Object, and the Class Hierarchy 116 Subclass Constructors 116 Constructor Chaining and the Default Constructor 117 Hiding Superclass Fields 119 Overriding Superclass Methods 120 Data Hiding and Encapsulation 123 Access Control 124 Data Accessor Methods 127 Abstract Classes and Methods 128 Important Methods of java.lang.object 130 tostring() 132 equals( ) 132 hashcode( ) 133 Comparable.compareTo( ) 133 clone() 134 Interfaces 135 Defining an Interface 135 Implementing an Interface 136 Interfaces vs. Abstract Classes 138 Marker Interfaces 139 Interfaces and Constants 139 Nested Types 140 Static Member Types 141 Nonstatic Member Classes 143 Local Classes 147 Anonymous Classes 151 How Nested Types Work 154 Modifier Summary 156 C++ Features Not Found in Java 157 4. Java 5.0 Language Features 159 Generic Types 160 Typesafe Collections 160 Understanding Generic Types 163 Type Parameter Wildcards 166 x Table of Contents

Writing Generic Types and Methods 169 Generics Case Study: Comparable and Enum 176 Enumerated Types 178 Enumerated Types Basics 179 Using Enumerated Types 181 Advanced Enum Syntax 185 The Typesafe Enum Pattern 190 Annotations 191 Annotation Concepts and Terminology 192 Using Standard Annotations 194 Annotation Syntax 196 Annotations and Reflection 198 Defining Annotation Types 199 Meta-Annotations 201 5. The Java Platform 203 Java Platform Overview 203 Text 205 The String Class 205 The Character Class 206 The StringBuffer Class 206 The CharSequence Interface 207 The Appendable Interface 207 String Concatenation 208 String Comparison 208 Supplementary Characters 209 Formatting Text with printf() and format( ) 210 Logging 211 Pattern Matching with Regular Expressions 212 Tokenizing Text 215 StringTokenizer 216 Numbers and Math 217 Mathematical Functions 217 Random Numbers 218 Big Numbers 218 Converting Numbers from and to Strings 219 Formatting Numbers 220 Dates and Times 221 Milliseconds and Nanoseconds 221 The Date Class 222 The Calendar Class 222 Formatting Dates and Times 223 Arrays 224 Collections 225 Table of Contents I xi

The Collection Interface 225 The Set Interface 227 The List Interface 229 The Map Interface 231 The Queue and BlockingQueue Interfaces 234 Collection Wrappers 236 Special-Case Collections 236 Converting to and from Arrays 237 Collections Utility Methods 237 Implementing Collections 238 Threads and Concurrency 238 Creating, Running, and Manipulating Threads 238 Making a Thread Sleep 241 Running and Scheduling Tasks 241 Exclusion and Locks 245 Coordinating Threads 247 Thread Interruption 250 Blocking Queues 251 Atomic Variables 252 Files and Directories 252 RandomAccessFile 253 Input/Output with java. io 254 Reading Console Input 254 Reading Lines from a Text File 254 Writing Text to a File 255 Reading a Binary File 255 Compressing Data 255 Reading ZIP Files 256 Computing Message Digests 256 Streaming Data to and from Arrays 257 Thread Communication with Pipes 257 Networking with java.net 258 Networking with the URL Class 258 Working with Sockets 258 Secure Sockets with SSL 259 Servers 261 Datagrams 262 Testing the Reachability of a Host 263 I/O and Networking with java.nio 263 Basic Buffer Operations 264 Basic Channel Operations 265 Encoding and Decoding Text with Charsets 267 Working with Files 268 Client-Side Networking 271 Server-Side Networking 272 Nonblocking 273 xii Table of Contents

XML 276 Parsing XML with SAX 277 Parsing XML with DOM 278 Transforming XML Documents 280 Validating XML Documents 281 Evaluating XPath Expressions 283 Types, Reflection, and Dynamic Loading 283 Class Objects 284 Reflecting an a Class 284 Dynamic Class Loading 285 Dynamic Proxies 286 Object Persistence 286 Serialization 286 JavaBeans Persistence 287 Security 288 Message Digests 288 Digital Signatures 289 Signed Objects 290 Cryptography 290 Secret Keys 290 Encryption and Decryption with Cipher 291 Encrypting and Decrypting Streams 292 Encrypted Objects 292 Miscellaneous Platform Features 292 Properties 293 Preferences 294 Processes 295 Management and Instrumentation 296 6. Java Security 299 Security Risks 300 Java VM Security and Class File Verification 300 Authentication and Cryptography 301 Access Control 301 Java 1.0: The Sandbox 301 Java 1.1: Digitally Signed Classes 302 Java 1.2: Permissions and Policies 303 Security for Everyone 304 Security for System Programmers 304 Security for Application Programmers 304 Security for System Administrators 305 Security for End Users 305 Permission Classes 306 Table of Contents I xiii

7. Programming and Documentation Conventions 308 Naming and Capitalization Conventions 308 Portability Conventions and Pure Java Rules 310 Java Documentation Comments 312 Structure of a Doc Comment 313 Doc-Comment Tags 314 Inline Doc Comment Tags 316 Cross-References in Doc Comments 318 Doc Comments for Packages 319 JavaBeans Conventions 320 Bean Basics 320 Bean Classes 321 Properties 322 Indexed Properties 322 Bound Properties 322 Constrained Properties 323 Events 324 8. Java Development Tools 326 apt 326 extcheck 327 jarsigner 328 jar 329 java 332 javac 338 javadoc 342 javah 348 javap 349 javaws 351 jconsole 352 jdb 353 jinfo 357 jmap 358 jps 358 jsadebugd 359 jstack 359 jstat 360 jstatd 362 keytool 362 native2ascii 366 pack200 366 policytool 368 xiv I Table of Contents

serialver 370 unpack200 370 Part II. API Quick Reference How to Use This Quick Reference 375 9. java.io 385 10. java.lang and Subpackages 439 11. java.math 543 12. java.net 549 13. java.nio and Subpackages 586 14. java.security and Subpackages 638 15. java.text 724 16. java.util and Subpackages 750 17. javax.crypto and Subpackages 921 18. javax.net and javax.net.ssl 946 19. javax.security.auth and Subpackages 970 20. javax.xml and Subpackages 994 21. org.w3c.dom 1032 22. org.xml.sax and Subpackages 1051 Class, Method, and Field Index 1077 Index 1147 Table of Contents 1 xv