没有合适的资源?快使用搜索试试~ 我知道了~
首页Java语言特性:模块、流、线程、I/O与lambda表达式(2nd Edition)
"Java Language Features, 2nd Edition--2018年"
本书"Java Language Features, 2nd Edition--2018年"由Kishori Sharan撰写,主要涵盖了Java编程语言的一些核心特性,特别是针对2018年版本的更新。以下是书中涉及的关键知识点:
1. **模块系统(Modules)**:Java 9引入了模块系统,这是一个对大型应用进行组织和封装的重要改进。模块化使得代码更加私有化和安全,同时提升了程序的性能和可维护性。通过`module`关键字,开发者可以声明和定义模块的依赖关系,从而提高整体系统的可管理性。
2. **流(Streams)**:Java 8引入的流API是处理集合数据的强大工具,它允许开发者以声明式的方式处理数据。流提供了并行处理的能力,可以有效地利用多核处理器,提高代码的执行效率。通过`Stream`类,开发者可以实现过滤、映射、归约等操作,使代码更简洁易读。
3. **线程(Threads)**:Java一直以其强大的多线程支持而闻名。在本书中,读者将深入理解如何创建和管理线程,包括同步机制(如`synchronized`关键字、`wait()`, `notify()`方法和`Lock`接口)、并发工具类(如`ExecutorService`和`Future`),以及Java并发包中的高级特性,如`CountDownLatch`, `CyclicBarrier`和`Semaphore`。
4. **输入/输出(I/O)**:Java的I/O系统提供了丰富的类和接口来处理文件、网络和流数据。书中可能涵盖NIO(非阻塞I/O)和NIO.2,这两个API极大地增强了Java处理I/O操作的能力,包括文件通道、选择器和异步I/O。
5. **Lambda表达式(Lambda Expressions)**:Java 8引入的lambda表达式简化了函数式编程,使得代码更简洁,尤其是处理事件驱动和高阶函数时。Lambda表达式可以表示匿名函数,并可以被用作方法参数或存储在变量中,大大提高了代码的可读性和灵活性。
6. **其他特性**:除了上述重点,书中可能还讨论了Java的其他特性,如类型推断(`var`关键字)、方法引用、日期时间API(`java.time`包)、默认方法(在接口中定义的具有实现的方法)等。
通过阅读这本书,开发者可以深入理解Java的最新特性和最佳实践,提升其在现代Java开发中的技能和效率。书中的实例和讲解将帮助读者更好地理解和应用这些核心概念,无论是在开发大型企业级应用还是在日常编码中。
■ Contents
xv
Creating Different Views of a Collection ����������������������������������������������������������������������� 659
Read-Only Views of Collections ���������������������������������������������������������������������������������������������������������� 659
Synchronized View of a Collection ������������������������������������������������������������������������������������������������������ 660
Checked Collections ��������������������������������������������������������������������������������������������������������������������������661
Creating Empty Collections ������������������������������������������������������������������������������������������ 662
Creating Singleton Collections ������������������������������������������������������������������������������������� 662
Understanding Hash-Based Collections ����������������������������������������������������������������������� 663
Summary ���������������������������������������������������������������������������������������������������������������������� 668
■Chapter 13: Streams ������������������������������������������������������������������������������������������ 675
What Are Streams? ������������������������������������������������������������������������������������������������������� 675
Streams Have No Storage �������������������������������������������������������������������������������������������������������������������676
Infinite Streams ���������������������������������������������������������������������������������������������������������������������������������� 676
Internal Iteration vs� External Iteration ����������������������������������������������������������������������������������������������� 676
Imperative vs� Functional �������������������������������������������������������������������������������������������������������������������678
Stream Operations ������������������������������������������������������������������������������������������������������������������������������678
Ordered Streams ��������������������������������������������������������������������������������������������������������������������������������680
Streams Are Not Reusable ������������������������������������������������������������������������������������������������������������������ 680
Architecture of the Streams API ��������������������������������������������������������������������������������������������������������� 680
A Quick Example ���������������������������������������������������������������������������������������������������������� 682
Creating Streams���������������������������������������������������������������������������������������������������������� 686
Streams from Values ��������������������������������������������������������������������������������������������������������������������������686
Empty Streams ����������������������������������������������������������������������������������������������������������������������������������� 689
Streams from Functions ���������������������������������������������������������������������������������������������������������������������689
Streams from Arrays ���������������������������������������������������������������������������������������������������������������������������694
Streams from Collections �������������������������������������������������������������������������������������������������������������������695
Streams from Files �����������������������������������������������������������������������������������������������������������������������������695
Streams from Other Sources �������������������������������������������������������������������������������������������������������������� 697
Representing an Optional Value ����������������������������������������������������������������������������������� 698
Applying Operations to Streams ����������������������������������������������������������������������������������� 703
Debugging a Stream Pipeline �������������������������������������������������������������������������������������������������������������704
Applying the ForEach Operation ���������������������������������������������������������������������������������������������������������705
■ Contents
xvi
Applying the Map Operation ���������������������������������������������������������������������������������������������������������������706
Flattening Streams �����������������������������������������������������������������������������������������������������������������������������708
Applying the Filter Operation �������������������������������������������������������������������������������������������������������������� 710
Applying the Reduce Operation ����������������������������������������������������������������������������������������������������������713
Collecting Data Using Collectors ���������������������������������������������������������������������������������� 721
Collecting Summary Statistics ������������������������������������������������������������������������������������� 725
Collecting Data in Maps ����������������������������������������������������������������������������������������������� 727
Joining Strings Using Collectors ���������������������������������������������������������������������������������� 729
Grouping Data �������������������������������������������������������������������������������������������������������������� 730
Partitioning Data ����������������������������������������������������������������������������������������������������������� 734
Adapting the Collector Results ������������������������������������������������������������������������������������� 735
Finding and Matching in Streams �������������������������������������������������������������������������������� 739
Parallel Streams ����������������������������������������������������������������������������������������������������������� 740
Summary ���������������������������������������������������������������������������������������������������������������������� 742
■Chapter 14: Implementing Services ������������������������������������������������������������������ 747
What Is a Service? �������������������������������������������������������������������������������������������������������� 747
Discovering Services ���������������������������������������������������������������������������������������������������� 749
Providing Service Implementations ������������������������������������������������������������������������������ 750
Defining the Service Interface �������������������������������������������������������������������������������������� 752
Obtaining Service Provider Instances �������������������������������������������������������������������������� 752
Defining the Service ����������������������������������������������������������������������������������������������������� 756
Defining Service Providers ������������������������������������������������������������������������������������������� 758
Defining a Default Prime Service Provider ����������������������������������������������������������������������������������������� 758
Defining a Faster Prime Service Provider ������������������������������������������������������������������������������������������� 760
Defining a Probable Prime Service Provider ��������������������������������������������������������������������������������������� 761
Testing the Prime Service �������������������������������������������������������������������������������������������� 763
Testing Prime Service in Legacy Mode ������������������������������������������������������������������������ 767
Summary ���������������������������������������������������������������������������������������������������������������������� 769
■ Contents
xvii
■Chapter 15: The Module API ������������������������������������������������������������������������������ 771
What Is the Module API?����������������������������������������������������������������������������������������������� 771
Representing Modules ������������������������������������������������������������������������������������������������� 773
Describing Modules ������������������������������������������������������������������������������������������������������ 773
Representing Module Statements ������������������������������������������������������������������������������������������������������774
Representing a Module Version ���������������������������������������������������������������������������������������������������������� 776
Other Properties of Modules ��������������������������������������������������������������������������������������������������������������� 777
Knowing Module Basic Info ����������������������������������������������������������������������������������������������������������������778
Querying Modules �������������������������������������������������������������������������������������������������������� 781
Updating Modules �������������������������������������������������������������������������������������������������������� 783
Accessing Module Resources �������������������������������������������������������������������������������������� 786
Accessing Resources Before JDK9 �����������������������������������������������������������������������������������������������������786
Accessing Resources in JDK9 ������������������������������������������������������������������������������������������������������������ 790
Annotation on Modules������������������������������������������������������������������������������������������������� 803
Working with Module Layers ���������������������������������������������������������������������������������������� 805
Finding Modules ��������������������������������������������������������������������������������������������������������������������������������� 807
Reading Module Contents ������������������������������������������������������������������������������������������������������������������� 809
Creating Configurations ���������������������������������������������������������������������������������������������������������������������� 811
Creating Module Layers ����������������������������������������������������������������������������������������������������������������������813
Summary ���������������������������������������������������������������������������������������������������������������������� 821
■Chapter 16: Breaking Module Encapsulation ���������������������������������������������������� 825
What Is Breaking Module Encapsulation? �������������������������������������������������������������������� 825
Command-Line Options ������������������������������������������������������������������������������������������������ 826
The --add-exports Option �������������������������������������������������������������������������������������������������������������������826
The --add-opens Option ��������������������������������������������������������������������������������������������������������������������� 827
The --add-reads Option ���������������������������������������������������������������������������������������������������������������������� 827
The --illegal-access Option ���������������������������������������������������������������������������������������������������������������� 828
An Example ������������������������������������������������������������������������������������������������������������������ 829
Using Manifest Attributes of a JAR ������������������������������������������������������������������������������� 837
Summary ���������������������������������������������������������������������������������������������������������������������� 841
■ Contents
xviii
■Chapter 17: Reactive Streams ��������������������������������������������������������������������������� 843
What Is a Stream? �������������������������������������������������������������������������������������������������������� 843
What Are Reactive Streams? ���������������������������������������������������������������������������������������� 844
The Reactive Streams API in JDK9 ������������������������������������������������������������������������������� 846
Publisher-Subscriber Interactions ������������������������������������������������������������������������������������������������������ 846
Creating Publishers ���������������������������������������������������������������������������������������������������������������������������� 847
Publishing Items ��������������������������������������������������������������������������������������������������������������������������������� 848
A Quick Example ���������������������������������������������������������������������������������������������������������������������������������849
Creating Subscribers �������������������������������������������������������������������������������������������������������������������������� 851
Using Processors �������������������������������������������������������������������������������������������������������������������������������� 856
Summary ���������������������������������������������������������������������������������������������������������������������� 859
■Chapter 18: Stack Walking �������������������������������������������������������������������������������� 861
What Is a Stack? ���������������������������������������������������������������������������������������������������������� 861
What Is Stack Walking? ������������������������������������������������������������������������������������������������ 862
Stack Walking in JDK8 ������������������������������������������������������������������������������������������������� 862
Drawbacks in Stack Walking ���������������������������������������������������������������������������������������� 865
Stack Walking in JDK9 ������������������������������������������������������������������������������������������������� 866
Specifying Stack-Walking Options �����������������������������������������������������������������������������������������������������866
Representing a Stack Frame ��������������������������������������������������������������������������������������������������������������866
Obtaining a StackWalker Class ����������������������������������������������������������������������������������������������������������� 868
Walking the Stack �������������������������������������������������������������������������������������������������������������������������������869
Knowing the Caller’s Class ����������������������������������������������������������������������������������������������������������������� 874
Stack-Walking Permissions ����������������������������������������������������������������������������������������������������������������877
Summary ���������������������������������������������������������������������������������������������������������������������� 878
Index ��������������������������������������������������������������������������������������������������������������������� 881
xix
About the Author
Kishori Sharan works as a senior software engineer lead at IndraSoft, Inc.
He earned a master’s of science degree in computer information systems
from Troy State University, Alabama. He is a Sun-certified Java 2
programmer and has over 20 years of experience in developing enterprise
applications and providing training to professional developers using the
Java platform.
www.allitebooks.com
剩余914页未读,继续阅读
白鸽-小蛋
- 粉丝: 10
- 资源: 166
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 最优条件下三次B样条小波边缘检测算子研究
- 深入解析:wav文件格式结构
- JIRA系统配置指南:代理与SSL设置
- 入门必备:电阻电容识别全解析
- U盘制作启动盘:详细教程解决无光驱装系统难题
- Eclipse快捷键大全:提升开发效率的必备秘籍
- C++ Primer Plus中文版:深入学习C++编程必备
- Eclipse常用快捷键汇总与操作指南
- JavaScript作用域解析与面向对象基础
- 软通动力Java笔试题解析
- 自定义标签配置与使用指南
- Android Intent深度解析:组件通信与广播机制
- 增强MyEclipse代码提示功能设置教程
- x86下VMware环境中Openwrt编译与LuCI集成指南
- S3C2440A嵌入式终端电源管理系统设计探讨
- Intel DTCP-IP技术在数字家庭中的内容保护
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功