Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Foreword
Preface
Changes in the Sixth Edition
Contents of This Book
Related Books
Examples Online
Conventions Used in This Book
Request for Comments
Safari® Books Online
Acknowledgments
I. Introducing Java
1. Introduction to the Java Environment
The Language, the JVM, and the Ecosystem
What Is the Java Language?
What Is the JVM?
What Is the Java Ecosystem?
A Brief History of Java and the JVM
The Lifecycle of a Java Program
Frequently Asked Questions
What is bytecode?
Is javac a compiler?
Why is it called “bytecode”?
Is bytecode optimized?
Is bytecode really machine independent? What about things like endianness?
Is Java an interpreted language?
Can other languages run on the JVM?
Java Security
Comparing Java to Other Languages
Java Compared to C
Java Compared to C++
Java Compared to PHP
Java Compared to JavaScript
Answering Some Criticisms of Java
Overly Verbose
Slow to Change
Performance Problems
Insecure
Too Corporate
2. Java Syntax from the Ground Up
Java Programs from the Top Down
Lexical Structure
The Unicode Character Set
Case Sensitivity and Whitespace
Comments
Reserved Words
Identifiers
Literals
Punctuation
Primitive Data Types
The boolean Type
The char Type
String literals
Integer Types
Floating-Point Types
Primitive Type Conversions
Expressions and Operators
Operator Summary
Precedence
Associativity
Operator summary table
Operand number and type
Return type
Side effects
Order of evaluation
Arithmetic Operators
String Concatenation Operator
Increment and Decrement Operators
Comparison Operators
Boolean Operators
Bitwise and Shift Operators
Assignment Operators
The Conditional Operator
The instanceof Operator
Special Operators
Statements
Expression Statements
Compound Statements
The Empty Statement
Labeled Statements
Local Variable Declaration Statements
The if/else Statement
The else if clause
The switch Statement
The while Statement
The do Statement
The for Statement
The foreach Statement
What foreach cannot do
The break Statement
The continue Statement
The return Statement
The synchronized Statement
The throw Statement
The try/catch/finally Statement
try
catch
finally
The try-with-resources Statement
The assert Statement
Enabling assertions
Methods
Defining Methods
Method Modifiers
Checked and Unchecked Exceptions
Working with checked exceptions
Variable-Length Argument Lists
Introduction to Classes and Objects
Defining a Class
Creating an Object
Using an Object
Object Literals
String literals
Type literals
The null reference
Lambda Expressions
Arrays
Array Types
Array type widening conversions
C compatibility syntax
Creating and Initializing Arrays
Array initializers
Using Arrays
Accessing array elements
Array bounds
Iterating arrays
Copying arrays
Array utilities
Multidimensional Arrays
Reference Types
Reference Versus Primitive Types
Manipulating Objects and Reference Copies
Comparing Objects
Boxing and Unboxing Conversions
Packages and the Java Namespace
Package Declaration
Globally Unique Package Names
Importing Types
Naming conflicts and shadowing
Importing Static Members
Static member imports and overloaded methods
Java File Structure
Defining and Running Java Programs
Summary
3. Object-Oriented Programming in Java
Overview of Classes
Basic OO Definitions
Other Reference Types
Class Definition Syntax
Fields and Methods
Field Declaration Syntax
Class Fields
Class Methods
Instance Fields
Instance Methods
How the this Reference Works
Creating and Initializing Objects
Defining a Constructor
Defining Multiple Constructors
Invoking One Constructor from Another
Field Defaults and Initializers
Initializer blocks
Subclasses and Inheritance
Extending a Class
Final classes
Superclasses, Object, and the Class Hierarchy
Subclass Constructors
Constructor Chaining and the Default Constructor
The default constructor
Hiding Superclass Fields
Overriding Superclass Methods
Overriding is not hiding
Virtual method lookup
Invoking an overridden method
Data Hiding and Encapsulation
Access Control
Access to packages
Access to classes
Access to members
Access control and inheritance
Member access summary
Data Accessor Methods
Abstract Classes and Methods
Reference Type Conversions
Modifier Summary
4. The Java Type System
Interfaces
Defining an Interface
Extending Interfaces
Implementing an Interface
Implementing Multiple Interfaces
Default Methods
Backward compatibility
Implementation of default methods
Marker Interfaces
Java Generics
Introduction to Generics
Generic Types and Type Parameters
Diamond Syntax
Type Erasure
Wildcards
Bounded wildcards
Array Covariance
Generic Methods
Using and Designing Generic Types
Compile and Runtime Typing
Enums and Annotations
Enums
Annotations
Defining Custom Annotations
Type Annotations
Nested Types
Static Member Types
Features of static member types
Nonstatic Member Classes
Features of member classes
Restrictions on member classes
Syntax for member classes
Scope versus inheritance
Local Classes
Features of local classes
Restrictions on local classes
Scope of a local class
Lexical Scoping and Local Variables
Anonymous Classes
Restrictions on anonymous classes
How Nested Types Work
Nonstatic member class implementation
Local and anonymous class implementation
Lambda Expressions
Lambda Expression Conversion
Method References
Functional Programming
Conclusion
5. Introduction to Object-Oriented Design in Java
Java Values
Important Methods of java.lang.Object
toString()
equals()
hashCode()
Comparable::compareTo()
clone()
Aspects of Object-Oriented Design
Constants
Interfaces Versus Abstract Classes
Instance Methods or Class Methods?
A word about System.out.println()
Composition Versus Inheritance
Field Inheritance and Accessors
Singleton
Exceptions and Exception Handling
Safe Java Programming
6. Java’s Approach to Memory and Concurrency
Basic Concepts of Java Memory Management
Memory Leaks in Java
Introducing Mark and Sweep
The Basic Mark and Sweep Algorithm
How the JVM Optimizes Garbage Collection
Evacuation
The HotSpot Heap
Collecting the Old Generation
Other Collectors
Concurrent Mark and Sweep
G1
Finalization
Finalization Details
Java’s Support for Concurrency
Thread Lifecycle
Visibility and Mutability
Concurrent Safety
Exclusion and Protecting State
volatile
Useful Methods of Thread
getId()
getPriority() and setPriority()
setName() and getName()
getState()
isAlive()
start()
interrupt()
join()
setDaemon()
setUncaughtExceptionHandler()
Deprecated Methods of Thread
stop()
suspend(), resume(), and countStackFrames()
destroy()
Working with Threads
Summary
II. Working with the Java Platform
7. Programming and Documentation Conventions
Naming and Capitalization Conventions
Practical Naming
Java Documentation Comments
Structure of a Doc Comment
Doc-Comment Tags
Inline Doc-Comment Tags
Cross-References in Doc Comments
Doc Comments for Packages
Conventions for Portable Programs
8. Working with Java Collections
Introduction to Collections API
The Collection Interface
The Set Interface
The List Interface
Foreach loops and iteration
Random access to Lists
The Map Interface
The Queue and BlockingQueue Interfaces
Adding elements to queues
Removing elements from queues
Querying
Utility Methods
Special-case collections
Arrays and Helper Methods
Lambda Expressions in the Java Collections
Functional Approaches
Filter
Map
forEach
Reduce
The Streams API
Lazy evaluation
Streams utility default methods
Conclusion
9. Handling Common Data Formats
Text
Special Syntax for Strings
String literals
toString()
String concatenation
String Immutability
Hash codes and effective immutability
Regular Expressions
Numbers and Math
How Java Represents Integer Types
Java and Floating-Point Numbers
BigDecimal
Java’s Standard Library of Mathematical Functions
Java 8 Date and Time
Introducing the Java 8 Date and Time API
The parts of a timestamp
Example
Queries
Adjusters
Legacy Date and Time
Conclusion
10. File Handling and I/O
Classic Java I/O
Files
Streams
Readers and Writers
try-with-resources Revisited
Problems with Classic I/O
Modern Java I/O
Files
Path
NIO Channels and Buffers
ByteBuffer
Mapped Byte Buffers
Async I/O
Future-Based Style
Callback-Based Style
Watch Services and Directory Searching
Networking
HTTP
TCP
IP
11. Classloading, Reflection, and Method Handles
Class Files, Class Objects, and Metadata
Examples of Class Objects
Class Objects and Metadata
Phases of Classloading
Loading
Verification
Preparation and Resolution
Initialization
Secure Programming and Classloading
Applied Classloading
Classloader Hierarchy
Primordial classloader
Extension classloader
Application classloader
Custom classloader
Reflection
When to Use Reflection
How to Use Reflection
Method objects
Problems with Reflection
Dynamic Proxies
Method Handles
MethodType
Method Lookup
Invoking Method Handles
12. Nashorn
Introduction to Nashorn
Non-Java Languages on the JVM
Motivation
Executing JavaScript with Nashorn
Running from the Command Line
Using the Nashorn Shell
Scripting with jjs
Scripting comments
Inline command execution
String interpolation
Special variables
Inline documents
Nashorn helper functions
Shebang syntax
Nashorn and javax.script
Introducing javax.script with Nashorn
The javax.script API
Advanced Nashorn
Calling Java from Nashorn
JavaClass and JavaPackage
JavaScript functions and Java lambda expressions
Nashorn’s JavaScript Language Extensions
Foreach loops
Single expression functions
Multiple catch clauses
Under the Hood
Conclusion
Project Avatar
13. Platform Tools and Profiles
Command-Line Tools
VisualVM
Java 8 Profiles
Motivation
Compact Profiles
Conclusion
Index
← Prev
Back
Next →
← Prev
Back
Next →