Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorCay S. Horstmann

The Classic Guide to the Java Programming Language--Fully Updated through Java 21 Whatever version of Java you are using, Core Java, Volume I: Fundamentals, Thirteenth Edition, will help you achieve a deep and practical understanding of the language and APIs. With hundreds of realistic examples, Java Champion Cay S. Horstmann demonstrates the most powerful and effective ways to get the job done. Written for experienced programmers looking for in-depth coverage of the Java language and platform, this revised and updated edition continues to be the first choice for serious programmers. The carefully crafted sample programs demonstrate almost every language and library feature, as well as the newest capabilities introduced in Java 21. The examples are purposefully simple to focus on the major points, but, for the most part, they aren't fake and they don't cut corners. They should make good starting points for your own code. This first of two volumes offers a detailed treatment of fundamental Java programming topics, including object-oriented programming, reflection and proxies, interfaces and inner classes, exception handling, generics, collections, lambda expressions, concurrency, annotations, and the Java Platform Module System. Master foundational techniques, idioms, and best practices for writing superior Java code Leverage the power of interfaces, lambda expressions, and inner classes Take advantage of sealed class hierarchies and pattern matching for processing structured data Harden programs through effective exception handling and debugging Write safer, more reusable code with generic programming Improve performance and efficiency with Java's standard collections Explore simple programs with JShell and assemble complex programs with archives and modules Fully utilize multicore processors with Java's powerful concurrency model See Core Java, Volume II: Advanced Features, Thirteenth Edition, for coverage of Java 21 enterprise features, including detai

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A comprehensive, example-driven reference for experienced programmers who want a deep, practical command of Java fundamentals—from syntax and OOP to generics, collections, and concurrency—updated through Java 21. 【Book Arc】 - **Opening (~0%–6%)**: Sets the stage with Java’s evolution (from Java 2 to 21), explains the book’s philosophy of realistic, non-trivial examples, and previews the core topics: OOP, reflection, interfaces, exceptions, generics, collections, lambdas, concurrency, annotations, and modules. - **Early (~6%–19%)**: Dives into the basics—comments, data types, operators, strings, and control flow—with practical warnings (e.g., non-nesting comments, string concatenation pitfalls) and introduces file I/O via `Scanner` and `PrintWriter`. - **Early (~19%–28%)**: Moves into object-oriented programming: classes, objects, static members, factory methods (e.g., `LocalDate`, `NumberFormat`), and the rationale behind design choices like immutability and naming conventions. - **Middle (~28%–44%)**: Covers inheritance, equality (`equals`/`hashCode`), final classes/methods, and the class path/JAR mechanics—essential for structuring real projects and understanding how Java locates and loads classes. - **Middle (~44%–47%)**: Explores collections (e.g., `ArrayList`), autoboxing, and the performance trade-offs of wrappers versus primitives, alongside deeper OOP topics like polymorphism and method overriding rules. - **Late (~47%–end)**: The excerpts taper off before covering advanced topics like generics, lambdas, concurrency, and modules in full; the book’s structure suggests these are treated with the same depth, using simple but non-trivial examples. 【Key Takeaways】 - **Java’s evolution matters for modern code** (Opening): Understanding version history (e.g., generics in 5.0, lambdas in 8, pattern matching in 21) helps you write idiomatic code and leverage new features without breaking compatibility. (Early) - **Comments and strings have hidden traps** (Early): `/* */` comments don’t nest, and string concatenation with `+` can produce surprising results (e.g., `"age" + 1 + "."` yields `"age1."`)—use parentheses or `StringBuilder` for clarity and efficiency. (Early) - **`StringBuilder` beats `StringBuffer` in single-threaded code** (Early): The former is more efficient; the latter is only needed for multi-threaded string editing. Chaining methods and reversing strings are practical idioms to master. (Early) - **Factory methods offer flexibility constructors can’t** (Early): `NumberFormat.getCurrencyInstance()` and `LocalDate.of()` show how static factories enable naming, subtype returns, and instance sharing—prefer them when constructors are too rigid. (Early) - **Immutability is a concurrency safety net** (Middle): Classes like `LocalDate` avoid mutation, making them safe for multi-threaded use. Prefer immutable designs to prevent unpredictable behavior when threads share objects. (Middle) - **The class path is the backbone of project structure** (Middle): Understanding how Java finds classes (via directories, JARs, and wildcards) is essential for building and sharing code—especially before modules take over encapsulation. (Middle) - **`equals` requires careful implementation** (Middle): Check identity, null, and class match before comparing fields; use `Objects.equals` to handle nulls safely. Getting this wrong breaks collections and debugging. (Middle) - **Autoboxing is convenient but costly** (Middle): `ArrayList<Integer>` wraps each `int` in an object, hurting performance versus `int[]`. Use wrappers only for small collections where convenience outweighs efficiency. (Middle) 【Reading Tips】 - **Skim the history and API notes** (Opening–Early): The version history and API notes are useful context but not essential for coding—skim them and focus on the code listings and warnings. - **Deep-read the “Caution” and “Note” boxes** (Early–Middle): These contain hard-won pitfalls (e.g., comment nesting, concatenation order, autoboxing overhead) that save you from common bugs. - **Run the examples yourself** (Early–Middle): The book’s examples are deliberately simple but non-trivial—type them into JShell or an IDE to internalize patterns like factory methods and `equals` implementation. - **Pay extra attention to the class path section** (Middle): This is a common stumbling block for beginners; work through the directory and JAR setup manually to avoid confusion in real projects. - **Treat the later chapters as a roadmap** (Late): The excerpts don’t cover generics, lambdas, concurrency, or modules in detail—use the book’s structure to plan your reading, and revisit these topics with the same example-driven approach. 【Coverage Limits】 This guide synthesizes the opening through middle sections (roughly 0–47% of the book). The excerpts do not cover the later chapters on generics, lambda expressions, concurrency, annotations, or the Java Platform Module System in depth.
Excerpt 1
ulticore processors with Java's powerful concurrency model See Core Java, Volume II: Advanced Features, Thirteenth Edition, for coverage of Java 21 enterpris...
View in text
Excerpt 2
constructs a Scanner that reads data from the given string. java.io.PrintWriter 1.1 PrintWriter(String fileName) PrintWriter(String fileName, Charset charset...
View in text
Excerpt 3
ys constructs a new object. You may want to share instances. For example, the Integer.valueOf factory method yields the same instance when you call it twice...
View in text
Excerpt 4
tem.out.println("alice1 == alice3: " + (alice1 == alice3)); System.out.println("alice1.equals(alice3): " + alice1.equals(alice3)); System.out.println("alice1...
View in text
Excerpt 5
ents of compareTo, the sign (but not necessarily the actual value) of the result must also flip. throughout the lifetime of the object, with no mutators touc...
View in text
Excerpt 6
.java 1 package stackTrace; 2 3 import java.util.*; 4 5 /** 6 * A program that displays a trace feature of a recursive method call. 7 * @version 1.10 2017-12...
View in text
Excerpt 7
* @author Cay Horstmann 14 */ 15 public class SetTest 16 { 17 public static void time(Set<String> wordSet, List<String> wordList, int repetitions) 18 { 19 lo...
View in text
Excerpt 8
tance which, when started, will execute the given Runnable. You can provide your own class that implements this interface, or, since Java 21, use a convenien...
View in text
Tags
AI categories
Programming LanguageJavaBackend
Publisher: Pearson Education
Publish Year: 2024
Language: English
Pages: 1061
File Format: PDF
File Size: 16.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…