售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Title Page
Copyright and Credits
Introduction to Programming
Dedication
Contributors
About the author
About the reviewers
Packt is searching for authors like you
Packt Upsell
Why subscribe?
PacktPub.com
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Java Virtual Machine (JVM) on Your Computer
What is Java?
Basic terms
History and popularity
Principles
Java platforms, editions, versions, and technologies
Platforms and editions
Versions
Technologies
Java SE Development Kit (JDK) installation and configuration
Where to start
The page with Java installers
How to install
Main Java commands
The JVM execution command
The compilation command
Command jcmd and other commands
Exercise – JDK tools and utilities
Answer
Summary
Java Language Basics
The basic terms of Java programming
Byte code
Defects (bugs) and their severity and priority
Java program dependencies
Statements
Methods
Classes
The Main class and the main method
Classes and objects (instances)
Java classes
Java object (class instance)
Class (static) and object (instance) members
Private and public
Static members
Object (instance) members
Method overloading
Interface, implementation, and inheritance
Interface
Implementation
Inheritance
The java.lang.Object class
The equals() method
The hashCode() method
The getClass() method
The toString() method
The clone() method
The wait() and notify() methods
OOP concepts
Object/class
Encapsulation
Inheritance
Interface (abstraction)
Polymorphism
Exercise – Interface versus abstract class
Answer
Summary
Your Development Environment Setup
What is the development environment?
Java editor is your main tool
Source code compilation
Code sharing
Code and test execution
Setting the classpath
Manual setting
Searching on the classpath
IDE sets the classpath automatically
There are many IDEs out there
NetBeans
Eclipse
IntelliJ IDEA
Installing and configuring IntelliJ IDEA
Downloading and installing
Configuring IntelliJ IDEA
Exercise – Installing NetBeans IDE
Answer
Summary
Your First Java Project
What is a project?
Definition and origin of project
Project-related terms
A project's life cycle
Creating a project
Creating a project using a project wizard
Maven project configuration
Changing IDE settings at any time
Writing an application code
Java package declaration
Creating a package
Creating the MyApplication class
Building the application
Hiding some files and directories
Creating the SimpleMath class
Creating methods
Executing and unit testing an application
Executing the application using the IDE
Creating a unit test
Executing the unit test
How many unit tests are enough?
Exercise – JUnit @Before and @After annotations
Answer
Summary
Java Language Elements and Types
What are the Java language elements?
Input elements
Types
Comments
Identifiers and variables
Identifier
Variable
Variable declaration, definition, and initialization
Final variable (constant)
Reserved and restricted keywords
Reserved keywords
Restricted keywords
Separators
Semicolon ";"
Braces "{}"
Parentheses "()"
Brackets "[]"
Comma ","
Period "."
Ellipsis "..."
Colons "::"
At sign "@"
Primitive types and literals
The Boolean type
Integral types
Floating-point types
Default values of primitive types
Primitive type literals
Reference types and String
Class types
Interface types
Arrays
Default value of a reference type
Reference type literals
String immutability
Enum types
Passing reference type values as method parameters
Exercise – Variable declarations and initializations
Answer
Summary
Interfaces, Classes, and Object Construction
What is an API?
Java APIs
Command line APIs
HTTP-based APIs
Software component API
Interface and object factory as API
Interface
Object factory
Reading configuration file
Using the json-simple library
Using the json-api library
Unit test
Calculator API
Adding static methods to API
The API is complete
Overloading, overriding, and hiding
Interface method overloading
Interface method overriding
Interface static member hiding
Class member hiding
Instance method overriding
Instance method overloading
This, super, and constructors
Keyword this and its usage
Keyword super and its usage
Constructors
Final variable, final method, or final class
Final variable
Final method
Final class
Exercise – Restricting a class instantiation to a single shared instance
Answer
Summary
Packages and Accessibility (Visibility)
What is importing?
Structure of the .java file and packages
Single class import
Multiple classes import
Static import
Access modifiers
The accessibility of a top-level class or interface
Access to class or interface members
The constructor's accessibility is the same as any class member
Encapsulation
Data hiding and decoupling
Flexibility, maintainability, and refactoring
Reusability
Testability
Exercise – Shadowing
Answer
Summary
Object-Oriented Design (OOD) Principles
What is the purpose of design?
The project's feasibility
Requirement gathering and prototyping
High-level design
Detailed design
Coding
Testing
A roadmap to a good design
Encapsulating and coding to an interface
Taking advantage of polymorphism
Decoupling as much as you can
Preferring aggregation over inheritance
So many OOD principles and so little time
Exercise – Design patterns
Answer
Summary
Operators, Expressions, and Statements
What are the core elements of Java programming?
Operators
Arithmetic unary (+ -) and binary operators: + - * / %
Incrementing and decrementing unary operators: ++ --
Equality operators: == !=
Relational operators: < > <= >=
Logical operators: ! & |
Conditional operators: && || ? : (ternary)
Assignment operators (most popular): = += -= *= /= %=
Instance creation operator: new
Type comparison operator: instanceof
Preferring polymorphism over the instanceof operator
Field access or method invocation operator: .
Cast operator: (target type)
Expressions
Statements
Operator precedence and evaluation order of operands
Operator precedence
Evaluation order of operands
Widening and narrowing reference types
Widening
Narrowing
Widening and narrowing conversion of primitive types
Widening
Narrowing
Methods of primitive type conversion
Boxing and unboxing between primitive and reference types
Boxing
Unboxing
Method equals() of reference types
Using the implementation of the base class Object
Overriding the equals() method
Using the identification implemented in the parent class
The equals() method of the String class
The equals() method in wrapper classes of primitive types
Exercise – Naming the statements
Answer
Summary
Control Flow Statements
What is a control flow?
Selection statements
Iteration statements
Branching statements
Exception handling statements
Selection statements
if
if...else
if...else if-...-else
switch...case
Iteration statements
while
do...while
for
for enhanced
for with multiple initializers and expressions
Branching statements
Break and labeled break
Continue and labeled continue
return
Exception handling statements
throw
try...catch
Checked and unchecked (runtime) exceptions
throws
Custom exceptions
What is exception handling?
Some best practices of exception handling
finally
Assert requires JVM option -ea
Exercise – Infinite loop
Answer
Summary
JVM Processes and Garbage Collection
What are JVM processes?
Loading
Linking
Initialization
Instantiation
Execution
Garbage collection
Application termination
JVM architecture
Runtime data areas
Classloader
Execution engine
Threads
Extending the Thread class
What is daemon?
Running threads extending Thread
Implementing Runnable
Runing threads implementing Runnable
Extending Thread vs implementing Runnable
How to execute the main(String[]) method
Using IDE
Command line with classes on classpath
Command line with a .jar file on classpath
Command line with an executable .jar file
Garbage collection
Responsiveness, throughput, and stop-the-world
Object age and generations
When stop-the-world is unavoidable
Exercise – Monitoring JVM while running an application
Answer
Summary
Java Standard and External Libraries
What are standard and external libraries?
Java standard libraries
java.lang
java.util
java.time
java.io and java.nio
java.sql and javax.sql
java.net
java.math
java.awt, javax.swing, and javafx
Java external libraries
org.junit
org.mockito
org.apache.log4j and org.slf4j
org.apache.commons
org.apache.commons.io
org.apache.commons.lang and lang3
org.apache.commons.codec.binary
Exercise – Comparing String.indexOf() and StringUtils.indexOf()
Answer
Summary
Java Collections
What are collections?
The java.util package
Apache Commons collections
Collections vs arrays
Here is what we are going to discuss
List - ArrayList preserves order
Prefer variable type List
Why is it called ArrayList?
Adding elements
size(), isEmpty(), clear()
Iterate and stream
Add using generics
Add collection
Implementing equals() and hashCode()
Locating element
Retrieving elements
Removing elements
Replacing elements
Sorting String and numeral types
Sorting custom objects
Comparing with another collection
Converting to array
List implementations
Set - HashSet does not allow duplicates
Preferring variable type Set
Why is it called HashSet?
Adding elements
size(), isEmpty(), and clear()
Iterate and stream
Adding using generics
Adding collection
Implementing equals() and hashCode()
Locating element
Retrieving elements
Removing elements
Replacing elements
Sorting
Comparing with another collection
Converting to array
Set implementations
Map – HashMap stores/retrieves objects by key
Preferring variable type Map
Why is it called HashMap?
Adding and maybe replace
size(), isEmpty(), and clear()
Iterate and stream
Adding using generics
Adding another Map
Implementing equals() and hashCode()
Locating element
Retrieving elements
Removing elements
Replacing elements
Sorting
Comparing with another collection
Map implementations
Exercise – EnumSet methods
Answer
Summary
Managing Collections and Arrays
Managing collections
Initializing collections
Collection constructor
Instance initializer (double brace)
Static initialization block
Factory methods of()
Using other objects and streams
Immutable collections
Immutable versus unmodifiable
Immutable without methods of()
Methods add() and put() confusion
java.util.Collections class
Copy
Sort and equals()
Reverse and rotate
Search and equals()
Comparing two collections
Min and max elements
Add and replace elements
Shuffle and swap elements
Converting to a checked collection
Convert to a thread-safe collection
Convert to another collection type
Create enumeration and iterator
Class collections4.CollectionUtils
Manage arrays
Initialize arrays
Creation expression
Array initializer
Static initialization block
From collection
Other possible methods
Class java.util.Arrays
Class lang3.ArrayUtils
Exercise – Sort list of objects
Answer
Summary
Managing Objects, Strings, Time, and Random Numbers
Managing objects
Class java.util.Objects
equals() and deepEquals()
hash() and hashCode()
isNull() and nonNull()
requireNonNull()
checkIndex()
compare()
toString()
Class lang3.ObjectUtils
Managing strings
StringBuilder and StringBuffer
Class java.lang.String
Constructors
format()
replace()
compareTo()
valueOf(Objectj)
valueOf(primitive or char[])
copyValueOf(char[])
indexOf() and substring()
contains() and matches()
split(), concat(), and join()
startsWith() and endsWith()
equals() and equalsIgnoreCase()
contentEquals() and copyValueOf()
length(), isEmpty(), and hashCode()
trim(), toLowerCase(), and toUpperCase()
getBytes(), getChars(), and toCharArray()
Get code point by index or stream
Class lang3.StringUtils
Managing time
java.time.LocalDate
java.time.LocalTime
java.time.LocalDateTime
Period and Duration
Managing random numbers
Method java.lang.Math.random()
Class java.util.Random
Exercise – Objects.equals() result
Answer
Summary
Database Programming
What is Java Database Connectivity (JDBC)?
Connecting to the database
Closing the database connection
Structured Query Language (SQL)
Creating a database and its structure
CREATE and DROP the database and its user
CREATE, ALTER, and DROP table
Create, read, update, and delete (CRUD) data
INSERT statement
SELECT-statement
UPDATE-statement
DELETE-statement
Using the PreparedStatement class
Exercise – Selecting unique first names
Answer
Summary
Lambda Expressions and Functional Programming
Functional programming
What is a functional interface?
Ready-to-use standard functional interfaces
Function<T, R>
Consumer<T>
Supplier<T>
Predicate<T>
Other standard functional interfaces
Chaining standard functions
Chain two Function<T,R>
Chain two Consumer<T>
Chain two Predicate<T>
identity() and other default methods
Lambda expressions
What is a lambda expression?
Re-implementing functions
Lambda limitations
Effectively final local variable
The this keyword interpretation
Method references
Exercise – Using the method reference to create a new object
Answer
Summary
Streams and Pipelines
What is a stream?
Stream operations
Creating a stream
Stream interface
empty(), of(T t), ofNullable(T t)
iterate(Object, UnaryOperator)
concat(Stream a, Stream b)
generate(Supplier)
of(T... values)
The Stream.Builder interface
Other classes and interfaces
Intermediate operations
Filtering
Mapping
Sorting
Peeking
Terminal operations
Processing each element
Counting all elements
Matching all, any, or none
Finding any or first
Class Optional
Min and max
The toArray() operation
The reduce operation
The collect operation
Class collectors
Numeric stream interfaces
Creating a stream
range(), rangeClosed()
Intermediate operations
boxed() and mapToObj()
mapToInt(), mapToLong(), and mapToDouble()
flatMapToInt(), flatMapToLong(), and flatMapToDouble()
Terminal operations
sum() and average()
Parallel processing
Stateless and stateful operations
Sequential or parallel processing?
Exercise – Multiplying all the stream elements
Answer
Summary
Reactive Systems
How to process a lot of data quickly
Asynchronous
Sequential versus parallel streams
Using the CompletableFuture class
Non-blocking
The java.io versus java.nio package
Event loop, or run loop
Distributed
Scalable
Reactive
Responsive
Resilient
Elastic
Message-driven
Microservices
Vert.x basics
The HTTP server as a microservice
Periodic service as a microservice
The HTTP client as a microservice
Other microservices
Reactive systems
Message-driven system
Message consumer
Message sender
Message publisher
Reality check
Exercise – Creating io.reactivex.Observable
Answer
Summary
Other Books You May Enjoy
Leave a review - let other readers know what you think
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜