Preface

Onjava8 的双语对照版本,由于本人水平有限,必然会存在很多不恰当的地方,欢迎大家指出。会持续更新…

于2020/12/9 开始

Preface 前言

This book teaches the most modern form of Java programming using the features in the 8th version of that language.
这本书讲授使用java8编程新特性的最新方式。

My previous Java book, Thinking in Java, 4th Edition(prentice Hall 2006), is still useful for programming in Java 5, the version of the language used for Android programming.
我的上一本关于Java的书,《Java编程思想》第四版 Prentice Hal出版社于2006年出版,仍然对基于Java5的Android编程非常有帮助。

But especially with the advent of java 8, the language has changed significantly enough that new Java code feels and reads differently. This justified the two-year effort of creating a new book.
java8的到来,带来了显著的变化和新特性,让java变得非常不一样。 所以我花两年的精力来完成这本书

On Java 8 is degined for someone with a basic foundation in programming. For beginners, web sites like Code.org and Khan Academy can provide at least some of that background, along with the Thinking in C seminar freely available at the OnJava8 Site. Services like YouTube, blogs and StackOverflow have made finding answers ridiculously easy compared to just a few years ago when we relie on print media.
《OnJava8》面向有一定基础的人群。对于初学者,像Code.org, Khan Academy这些网上能够提供一些必要的背景知识。随着《Thinking in C seminar》的在Onjava8网站的免费发布。相对于以前纸质书的时候,如果你在阅读中遇到一些问题,可以在YouTubem,blogs 和 StackOverflow等一些网站找到一些非常好的问题解答。

Combine these with perseverance, and you can use this book as your first programming text. It’s also intended for professional programmers who want to expand their knowledge.
综上所述,这本书可以作为初学者的第一本编程书;同时也适用于专业编程人员的阅读。

I am grateful for all the benefits from Thinking in Java, mostly in the form of speaking engagements all over the world, It has prove invaluable in creating connections with people and companies for my Reinventing Business project.
《Java编程思想》出版后给我带来了很大的收益,让我收到了来自世界各地的演讲邀请,提供了我与各地开发者一个密切交流的机会和各大公司对我的 Reinventing Business 项目的支持。

One of the reasons I finally wrote this book is to support my Reinventing Business research, and it seems the next logical step is to actually create a so-called Teal Organization. I hope this book can become a kind of crowdfunding for that project.
让我决定写这本书的一个原因是,支持Reinventing Business 项目的研究,项目的下一个构想是创建一个叫 “蒂尔”的组织。我希望这本书能够成为一种众筹方式,为项目筹募资金。

Goals

Each chapter teaches a concept, or a group of associated concepts, without relying on features that haven’t yet been introduced. That way you can digest each piece in the context of your current knowledge before moving on.

My goals in this book are to:

  1. Present the material one step at a time so you can easily incorporate each idea before moving on, and to carefully sequence the presentation of features so you’re exposed to a topic before you see it in use. This isn’t always possible; in those situations, a brief introductory description is given.

  2. Use examples that are as simple and short as possible. This sometimes prevents me from tackling “real world” problems, but I’ve found that beginners are usually happier when they can understand every detail of an example rather than being impressed by the scope of the problem it solves. For this I might receive criticism for using “toy examples,” but I’m willing to accept that in favor of producing something pedagogically useful.

  3. Give you what I think is important for you to understand about the language, rather than everything I know. I believe there is an information importance hierarchy, and there are some facts that 95 percent of programmers will never need to know–details that just confuse people and increase their perception of the cimplexity of the language. If you must think about it, it will also confuse the reader/maintainer of that code, so I advocate choosing a simpler approach.

  4. Provide you with a solid foundation so you understand the issues well enough to move on to more difficult coursework and books.

Language Design

Errors

Every language has design errors. New programmers experience deep uncertainty and frustration when they must wade through features and guess at what they should use and what they shouldn’t. It’s embarrassing to admit mistakes. but this bad beginner experience is a lot worse than the discomfort of acknowleding you were wrong about something. Alas, every failed language/library design experiment is forever embedded in the Java distribution.
The Nobel laureate economist Joseph Stiglitz has a philosophy of life that applies here, called The Theory of Escalating Commitment; “The cost of continuing mistakes is borne by others, wile the cost of admitting mistakes is borne by yourself.”

If you’ve read my past writings, you’ll know that when I find design errors in a language, I tend to point them out. Java has developed a partcularly avid following, folks who treat the language more like country of origin and less like a programming tool. Because I’ve written about Java, they assume I am a fellow patriot. When I criticize the errors I find, it tends to have two effects;

  1. Initially, a log of "my-country-right-or-wrong"furor, which years–the error is acknowledged and seen as just part of the history of Java.
  2. More importantly, new programmers don’t go through the struggle of wondering why “they” did it this way, especially the self-doubt that comes from finding something that just doesn’t seem right and naturally assuming I must be doing it wrong or I just don’t get it. Worse, those who teach the language often go right along with the misconceptions rather than delving in and analyzing the issue. By understanding the language design errors, new programmers can understand that something was a mistake, and move ahead.
    Understanding language and library design errors is essential because of the impact they have on programmer productivity. Some companies and teams choose to avoid certain features because, while seductive on the surface, those features can block your progress when you least expect it. Design errors also inform the creation and adoption of new languages. It’s fun to explore what can be done with a language, but design errors tell you what can’t be done with that language. For many years, I honestly felt a lack of care from the Java designers regarding their users. Some of these errors seemd so blatant, so poorly thought-out, that it appeared the designers and some other motivation in mind instead of serving their users. There was a lot of notoriety around the Java language for a long time, and perhaps that’s where the seduction was. This seeming lack of respect for programmers is the major reason I moved away from Java and didn’t want anything to do with it for such a lone time.
    When I did start looking into Java again, something about Java 8 felt very different, as if a fundamental shift and occurred in the designers’ attitude about the language and its users. Many features and libraries that had been wart on the language were fixed after years of ignoring user complains. New features felt very different, as if there were new folks on board who were extremly interested in programmer experimence. These features were–finally–working to make the language better rather than just quickly adding ideas without delving into their implications. And some of the new features are downright elegant(or at least, as elegant as possible given Java constrains). I can only guess that some person or people have departed the language group and this has changed the perspective.
    Because of this new focus by the language developers – and I don’t think I am imagining it — writing this book has been dramatically better than past experiences. Java 8 contains fundamental and important improvements. Alas, Because of Java’s rigid backwards-compatibility promise, these improvements required great offort so it’s unlikely we’ll see anything this dramatic again(I hope I’m wrong about this).
    Noonetheless, I applaud those who have turned the ship as much as they have and set the language on a better course. For the first time I can ever recall, I found myself saying “I love that!” about some of the Java code I’ve been able to write in Java 8.
    Ultimately, the timing for this book seems good, because Java 8 inroduces important features that strongly affect the way code is written, while – so far – Java 9 seems to focus on the understory of the language, bringing important infrastructure-features(equal to basic features) but not those that affect the kind of coding focused on in this book. However, because it’s an eBook, If I discover something I think requires an update or an addition, I can push the new version to existing customers.

Tested Examples

The code examples in this book compile with Java 8 and the Gradle build tool. All the examples are in a freely-accessible Github repository.
Without a built-in test framework with tests that run every thim you do a build of your system, you have no way of knowing whether your code is reliable. To accomplish this in the book, I created a test system to display and validate the output of most examples. The ouput from running an example is attached, as a block comment, at the end of examples that produce output. In some cases only the first few lines are shown, or first and last lines. Embedded output improves reading and learning experience, and provides yet another way to verify the correctness of the exmaple.

Popularity

Java’s popularity has significant implications. If you learn it, getting a job will probably be easier. There are a lot more training materials, courses, and other learning resources available. If you’re starting a company and you choose to work in Java, it’s much easier to find programmers, and that’s a compelling argument.
Short-term thinking is alomost always a bad idea. Don’t use Java if you really don’t like it – using it just to get a job is an unhapply life choice. As a company, think hard before choosing Java just because you can hire people. There might be another language that makes fewer employees far more productive for your particular need.
But if you do enjoy it, if Java does call to you, then welcome. I hope this book will enrich your programming experience.

Android Programmers

I’ve made this book as “Java 8 as possible,” so if you wnat to program for Android devices, you must study Java 5, which I cover in Thinking in Java, 4th edtion. At the time of publishing of On Java 8, Thinking in Java, 4th Edition has become a free download, available through www.OnJava8.com Thinking in Java, 4th Edtion is available in print from Prentice-Hall. In addition, there are many other resources that specialize in Android programming.

This is Only an eBook

On Java 8 is only available as an eBook, and only via ww.OnJava8.com. Any other source or delivery mechanism is illegitimate. There is no print version. This is copyrighted work. Do not post or share it in any way without permission via mindviewinc@gamail.com. You may use the examples for teaching, as long as they are not republished without permission and attribution. See the Copyright.txt file in the example distribution for full details.
This book is far too large to publish as a single print volume, and my intent has always been to only publish it as an eBook. Color syntax highlighting for code listings is, alone, worth the cost of admission.
Searchability, font resizing or text-to-voice for the vision-impaired, the fact you can always keep it with you – there are so many benefits to eBooks it’s hard to name them all.
Anyone buying this book needs a computer to run the programs and write code, and the eBook reads nicely on a computer(I was also surprised to discover that it even reads tolerably well on a phone). However, the best reading experience is on a tablet computer. Tablets are inexpensive ehough that you can now buy one for less than you’d pay for an equivalent print version of this book. It’s much easier to read a tablet in bed(for example) than trying to manage the pages of a physical book, especially one this big. When working at your computer, you don’t have to hold the pages open when using a tablet at your side. It might feel different at first, but I think you’ll find the benefits far outweigh the discomfort of adapting.
I’ve done the research, and Google Play Books works on, and provides a very nice reading experience, every platform, including Linux and iOS. As an experiment, I’ve decided to try publishing exclusively through Google Books.

Colophon 版权声明

This book was written with Pandoc-flavored Markdown, and produced into ePub version 3 format using Pandoc.
The body font is Georgia and the headline font is Verdana. The code font is Ubuntu Mono, because it is especially compact and allows more characters on a line whitout wrapping. I chose to place the code inline (rather than make listing into images, as I’ve seen some books do) because it was important to me that the reader be able to resize the font of the code listings when they resize the body font(otherwise, really, what’s the point?).
The build process for the book was automated, as well as the process to extract, complie and test the code examples. All automation was chieved through fairly extensive programs I wrote in Python 3.

Cover Design 界面设计

The cover of On Java 8 is from a mosaic created through the Works Progress Administration (WPA, a huge project during the US Great Depression from 1935-1943 which put millions of out-of-work-people back to work). It also reminds me of the illustrations from The Wizard of Oz series of books. My friend and designer, Daniel WIll-Harris (www.will-harris.com) and I just liked the image.

Thanks 感谢

Thanks to Eric Evans (author of Domain-Driven Design) for suggesting the book title, and to everyone else in the conference newsgroups for their help in finding the title.
Thanks to James Ward for starting me with the Gradle build tool for this book, and for his help and friendship over the years. Thanks to Ben Muschko for this work polishing the build firle, and Hans Dockter for giving Ben the time.
Jeremy Cerise and Bill Frasure came to the developer retreat for the book and followed up with valuable help.
Thanks to all who have taken the time and effort to ocme to my conferences, workshops, developer retreats, and other events in my tow of Crested Butte, Colorado. Your conributions might not be easily seen, but they are deeply important.

Dedication

For my beloved father, E. Wayne Eckel.
April 1, 1924 – November 23, 2016.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值