Effective Java
Rate it:
Open Preview
Started reading December 26, 2020
1%
Flag icon
“Spouse of me this night today manufactures the unusual meal in a home. You will join?”
1%
Flag icon
This book addresses your third need: customary and effective usage.
2%
Flag icon
Small is beautiful, but simple ain’t easy.
2%
Flag icon
The most significant set of changes was the addition of generics, enum types, annotations, autoboxing, and the for-each loop in Java 5. A close second was the addition of the new concurrency library, java.util.concurrent, also released in Java 5.
2%
Flag icon
The other big change in the platform is the widespread adoption of modern Integrated Development Environments (IDEs), such as Eclipse, IntelliJ IDEA, and NetBeans, and of static analysis tools, such as FindBugs.
2%
Flag icon
I borrowed the format from Scott Meyers’s Effective C++, which consists of fifty items, each conveying one specific rule for improving your programs and designs.
2%
Flag icon
I naturally think in terms of exported APIs (Application Programming Interfaces), and I encourage you to do likewise. Even if you aren’t developing reusable components, thinking in these terms tends to improve the quality of the software you write.
2%
Flag icon
Extreme Programming. These methodologies emphasize writing the simplest program that could possibly work.
2%
Flag icon
a focus on API design serves you well in the refactoring process. The fundamental goals of refactoring are the improvement of system structure and the avoidance of code duplication.
2%
Flag icon
THIS book is designed to help you make effective use of the Java programming language and its fundamental libraries: java.lang, java.util, and java.io, and subpackages such as java.util.concurrent and java.util.function.
3%
Flag icon
Clarity and simplicity are of paramount importance. The user of a component should never be surprised by its behavior. Components should be as small as possible but no smaller.
3%
Flag icon
the term component refers to any reusable software element, from an individual method to a complex framework consisting of multiple packages.)
3%
Flag icon
Code should be reused rather than copied. The dependencies between components should be kept to a minimum. Errors should be detected as soon as possible af...
This highlight has been truncated due to consecutive passage length restrictions.
3%
Flag icon
The language supports four kinds of types: interfaces (including annotations), classes (including enums), arrays, and primitives. The first three are known as reference types.
3%
Flag icon
The term exported API, or simply API, refers to the classes, interfaces, constructors, members, and serialized forms by which a programmer accesses a class, interface, or package.
3%
Flag icon
In Java 9, a module system was added to the platform.
3%
Flag icon
Item 1: Consider static factory methods instead of constructors
3%
Flag icon
A class can provide a public static factory method, which is simply a static method that returns an instance of the class.
3%
Flag icon
Flyweight pattern
4%
Flag icon
Bridge pattern
5%
Flag icon
builder object
6%
Flag icon
A minor advantage of builders over constructors is that builders can have multiple varargs parameters because each parameter is specified in its own method.
6%
Flag icon
The Builder pattern has disadvantages as well. In order to create an object, you must first create its builder. While the cost of creating this builder is unlikely to be noticeable in practice, it could be a problem in performance-critical situations.
6%
Flag icon
the Builder pattern is more verbose than the telescoping constructor pattern, so it should be used only if there are enough parameters to make it worthwhile, say four or more.
6%
Flag icon
the Builder pattern is a good choice when designing classes whose constructors or static factories would have more than a handful of parameters,
6%
Flag icon
Item 3: Enforce the singleton property with a private constructor or an enum type
6%
Flag icon
Making a class a singleton can make it difficult to test its clients
6%
Flag icon
a single-element enum type is often the best way to implement a singleton.
6%
Flag icon
Item 4: Enforce noninstantiability with a private constructor
6%
Flag icon
Attempting to enforce noninstantiability by making a class abstract does not work.
7%
Flag icon
a class can be made noninstantiable by including a private constructor
7%
Flag icon
The AssertionError isn’t strictly required, but it provides insurance in case the constructor is accidentally invoked from within the class.
7%
Flag icon
Item 5: Prefer dependency injection to hardwiring resources
7%
Flag icon
Static utility classes and singletons are inappropriate for classes whose behavior is parameterized by an underlying resource.
7%
Flag icon
pass the resource into the constructor when creating a new instance. This is one form of dependency injection: the dictionary is a dependency of the spell checker and is injected into the spell checker when it is created.
7%
Flag icon
A useful variant of the pattern is to pass a resource factory to the constructor.
7%
Flag icon
Factory Method
7%
Flag icon
Although dependency injection greatly improves flexibility and testability, it can clutter up large projects, which typically contain thousands of dependencies. This clutter can be all but eliminated by using a dependency injection framework
7%
Flag icon
Item 6: Avoid creating unnecessary objects
7%
Flag icon
While String.matches is the easiest way to check if a string matches a regular expression, it’s not suitable for repeated use in performance-critical situations.
7%
Flag icon
lazily initializing
7%
Flag icon
As is often the case with lazy initialization, it would complicate the implementation with no measurable performance improvement
7%
Flag icon
When an object is immutable, it is obvious it can be reused safely,
7%
Flag icon
adapters [Gamma95], also known as views. An adapter is an object that delegates to a backing object, providing an alternative interface.
8%
Flag icon
Another way to create unnecessary objects is autoboxing, which allows the programmer to mix primitive and boxed primitive types, boxing and unboxing automatically as needed.
8%
Flag icon
Autoboxing blurs but does not erase the distinction between primitive and boxed primitive types.
8%
Flag icon
prefer primitives to boxed primitives, and watch out for unintentional autoboxing.
8%
Flag icon
avoiding object creation by maintaining your own object pool is a bad idea unless the objects in the pool are extremely heavyweight. The classic example of an object that does justify an object pool is a database connection.
8%
Flag icon
Generally speaking, however, maintaining your own object pools clutters your code, increases memory footprint, and harms performance.
8%
Flag icon
defensive copying.
« Prev 1 3