Introduction

Introduction 介绍

“The limits of my language are the limits of my world” — Wittgenstein
This is ture of both spoken/written languages and programming languages. It’s often subtle: A language gently guides you into certain modes of thought and away from others. Java is particularly opinionated.

Java is a dervied language. The original language designers didn’t want to use C++ for a project, so created a new language which unsurprisingly looked a lot like C++, but with improvements ( their original project never came to fruition(完成)). The core changes were the incorporation(编入,并入) of a virtual machine and garbage collection, both of which are described in detail in this book. Java is also responsible for pushing the industry forward in other ways; for example, most languages are now expected to include documentation markup syntax and a tool to produce HTML documentation.
One of the most predominant Java concept came from the SmallTalk language, which insists that the “object” (described in the next chapter) is the fundamenta unit of programming, so everything must be an object. Time has tested this belief and found it overenthusiastic. some folks even declare that objects are a complete failure and should be discarded. Personally, I find that making everything an object is not only an unneccessary burden but also pushs many designs in a poor direction. However, there are still situations where objects shine. Requiring that everything be an object ( especially all the way down to the lowest level) is a design mistake, but banning objects altogether seems equally draconian(严苛的).
Other Java language decisions haven’t panned out(pan out 成功 短语) as promised.
Throughout this book I attempt to explain these so you not only understand those features, but also why they might not feel quite right to you. It’s not about declaring that Java is a good language or a bad one. If you understand the flaws(缺陷) and limitations of the language you will:
1. Not get stymied(阻挠,妨碍) when you encounter a feature that seems “off.”
2. Design and code better by knowing where the boundaries are.

Programming is about managing complexity: the complexity of the problem, laid upon the complexity of the machine. Because of the complexity, most of our programming projects fail.
Many language design decisions are made with complexity in mind, but at some point other issues are considered essential. Inevitably, those other issues are what cause programmers to eventually “hit the wall” with a language. For example, C++ and to be backward-compatible with C(to allow easy migration for C promrammers), as well as efficent. Those are both useful goals and account for much of the success of C++, but they also expose extra complexity that prevent some projects from finishing. Certainly, you can blame programmers and management, but if a language can help by catching your mistakes, why shouldn’t it?
Visual BASIC(VB) was tied to BASIC, which wasn’t really designed as an extensible language. All the extensions piled upon VB have produced some truly un-maintainable syntax. Perl is backward-compatible with awk, sed, grep, and other Unix tools it was meant to replace, and as a result it is often accused of producing “write-only-code”( that is. you can’t read your own code.) On the other hand, C++, VB, Perl, and other languages such as SmallTalk had some of their design efforts focused on the issue of complexity and as a result are remarkably successful in solving certain types of problems.
The communication revolution enables all of us to communicate with each other more easily: one-on-one as well as in groups and as a planet. I’ve heard it suggested that the next revolution is the formation of kind of global mind that results from enough prople and enough interconnectedness. Java might or might not be one of the tools for that revolution, but at least the possibility has made me feel like I’m doing something meaingful by attempting to teach the language.

Prerequisites

This book assumes you have some programming familiarity, so you understand:

  1. A program is a collection of statements
  2. The idea of a subroutine(子程序)/function/macro(宏指令)
  3. Control statements such as “if” and looping constructs such as “while”
  4. Etc.

You might have learned this in many places, typically school, books, or the Internet. As long as you feel comfortable with the basic ideas of programming, you can work through this book. The Thinking in C multimedia seminar freely downloadable from OnJava8.com will bring you up to speed on the fundamentals necessary to learn Java. On Java 8 does inroduce the concepts of object-oriented programming (OOP) and Java’s basic control mechanisms.
Although I make references to C and C++ language features, these are not intended to be insider comments, but instead to help all programmers put Java in perspective with those languages, from which, after all, Java is descended. I attempt to make these references simple and to explain anything that might be unfamiliar to a non-C/C++ programmer.

JDK HTML

Documentation

The Java Development Kit(JDK) from Oracle (a fre download) comes with documentation in electronic form, readable through your web browser. Unless(除非) necessary, this book will not repeat that documentation, because it’s usually much faster to find the class descriptions with your browser than to look them up in a book(also, the online documentation is current). I’ll provide extra descriptions of the classes only when it’s necessary to supplement that documentation so you understand a particular example.

Thinking in C

The Thinking in C multimedia seminar is freely downloadable from www.OnJava8.com. This gives an introduction to the C syntax.
Thinking in C also provides a gentle introduction to coding, assuming even less about the student’s programming background than does this book.
I commissioned Chuck Allison to create Thinking in C as a standalone product, which was later includeed in book CDs, and finally reworked(重做,改写;重新加工) as a free download. By freely providing this seminar online, I can ensure that everyone begins with adequate(充足的;适当的;胜任的) preparation.

Source Code

All the source code for this book is available as copyrighted freeware(免费软件;自由软件), distributed via Github. To ensure you have the most current version, this is the official code distribution(分布;分配;供应) site. You may use this code in classroom and other educational situations.
The primary goal of the copyright is to ensure that the source of the code is properly cited, and to prevent you from republishing the code without permission.(As long as this book is cited, using examples from the book in most media is generally not a problem.)
In each source-code file you find a reference(参考,参照;)to the following copyright notice:

Coding Standards

In the text of this book, identifiers(keywords, methods, variables, and class names) are set in bold, fixed-width code font. Some keywords, such as class, are used so much that the bolding can become tedious(沉闷的;冗长乏味的). Those which are distinctive(独特的)enough are left in normal font.
I use a particular coding style for the examples in this book. As much as possible within the books formating constrains(约束),this follows the style that Oracle itself uses in virtually all code you find at its site, and seems to be supported by most Java development environments. As the subject of formatting style is good for hours of hot debate, I’ll just say I’m not trying to dicate correct style via my examples; I have my own motivation for using the style I do. Because Java is free-form programming language, continue to use whatever style you’re comfortable with. One solution to the coding style issue is to use an IDE( integrated development environment) tool like IntelliJ IDEA, Eclipse or NetBeans to change formatting to that which suits you.
The code files in this book are tested with an automated system,and should work without compiler errors(except those specifically tagged) in the latest version of Java.
This book focuses on and is tested with Java 8. If you must learn about earlier releases of the language not covered here, the 4th edition of Thinking in Java is freely downloadable at www.OnJava8.com

Bad Reports

No matter how many tools a writer uses to detect errors, same always creep(此处可看作是 微不足道的小bug) in and these often leap off the page for a fresh reader. If you discover anything you believe to be an error, please submit the error along with your suggested correction, for either the book’s prose(可看作 文字 word)or example, here. Your help is appreciated.

Mailing List

For news and notifications, you can subscribe to the low-volume email list at www.Onjava8.com. I don’t use ads and strive to make the content as appropriate as possible.

What About User Interfaces?

Graphical user interfaces and desktop programming in Java hace had a tumultuous(吵闹的;骚乱的;狂暴的) – some would say tragic — history.
The original design goal of the graphical user interface(GUI) library in Java 1.0 was to enable the programmer to build a GUI to look good on all platforms. That goal was not achieved. Instead, the Java 1.0 Abstract Windowing Toolkit(AWT) produced a GUI that looked equally mediocre( 普通的;平凡的;中等的) on all systems. In addition, it was restrictive(限制的;限制性的;约束的); you could use only four fonts and you could not access any of the more sophisticated(复杂) GUI elements that exist in your operating system. The Java 1.0 AWT programming model was also awkward and non-object-oriented. A student in one of my seminars(who had been at Sun during the creation of Java) explained why: The original AWT had been conceived(构思;设想), designed, and implemented in a month. Certainly a marvel of productivity, and also an object lession in why design is important.
The situation improved with the Java 1.1 AWT event model, which took a much clearer, object-oriented approach, along with the addtion of JavaBeans, a component programming model(now bead) oriented toward the easy creation of visual(栩栩如生) programming environments. Java 2(Java 1.2) finished the transformation(变革) away from the old Java 1.0 AWT by essentially replacing with the Java Foundation Classed (IFC), the GUI portion of which is called “Swing.” These are a rich set of JavaBeans that create a reasonable GUI. The revision(修正,复习) 3 rule of the software industry (“a product isn’t good until revision 3”) seems to hold true with programming languages as well.

It seemed that Swing was the final GUI library for Java. This assumption truned out to be wrong – SUn made a final attempt, called JavaFX. When Oracle bought Sun they changed the original ambitious project ( which included a sripting language) into a library, and now it appears to be the only UI toolkit getting development effort ( see the Wikipedia article on JavaFX) – but even that effort has diminished(减弱的;减退了的). JavaFX, too, seems eventually doomed.

Ultimately(最后;根本;基本上), desktop Java never took hold, and never even touched the designers’ ambitious. Other pieces, such as JavaBeans, were given much fanfare( and many unfortunate authors spent a log of effort writing books solely(adv. 单独地;仅仅) on Swing and even books just on JavaBeans) but never gained any traction(吸引力). Most usage you’ll see for desktop Java is for integrated development environments(IDEs) and some in-house (内部) corporate application. People do develop user interfaces in Java, but it’s safe to consider(认为) that a niche(小众) usage of the language.

If you must learn Swing, it’s covered in the freely-downloadable Tinking in Java, 4th Edtion( available at www.OnJava8.com), and in books dedicated to the topic.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值