Methods

Memory map

Objective

Following rules are described
  1. Item 49: Check parameters for validity
  2. Item 50: Make defensive copies when needed
  3. Item 51: Design method signatures carefully
  4. Item 52: Use overloading judiciously
  5. Item 53: Use varargs judiciously
  6. Item 54: Return empty collections or arrays, not nulls
  7. Item 55: Return optionals judiciously
  8. Item 56: Write doc comments for all exposed API elements

Serialization

Following rules are described-

  1. Introduction
  2. Item 85: Prefer alternatives to Java serialization
  3. Item 86: Implement Serializable with great caution
  4. Item 87: Consider using a custom serialized form
  5. Item 88: Write readObject methods defensively
  6. Item 89: For instance control, prefer enum types to readResolve
  7. Item 90: Consider serialization proxies instead of serialized instances

Introduction

JAVA – Object SERIALIZATION,
It is Java’s framework for encoding objects as byte streams (serialising) and reconstructing objects from their encoding (serialising). This mechanism is used to persist the object. This chapter focuses on the dangers of serialization and how to minimize them.

Concurrency

Objective

Concurrency canot be avoided it is inherent in platform(multicore) and requirement if you want to achieve better performance from multicore processors.
Motivation:
Concurrent programming is harder than single-threaded programming, because more things can go
wrong, and failures can be hard to reproduce.

Memory Map

Following rules are described

  1. Item 78: Synchronize access to shared mutable data . . . . . . . . . . 311
  2. Item 79: Avoid excessive synchronization . . . . . . . . . . . . . . . . . . 317
  3. Item 80: Prefer executors, tasks, and streams to threads . . . . . . . 323
  4. Item 81: Prefer concurrency utilities to wait and notify . . . . . . 325
  5. Item 82: Document thread safety . . . . . . . . . . . . . . . . . . . . . . . . . 330
  6. Item 83: Use lazy initialization judiciously . . . . . . . . . . . . . . . . . 333
  7. Item 84: Don’t depend on the thread scheduler . . . . . . . . . . . . . . 336

General Programming

Following rules are desscribed

  1. Item 57: Minimize the scope of local variables
  2. Item 58: Prefer for-each loops to traditional for loops
  3. Item 59: Know and use the libraries
  4. Item 60: Avoid float and double if exact answers are required
  5. Item 61: Prefer primitive types to boxed primitives
  6. Item 62: Avoid strings where other types are more appropriate
  7. Item 63: Beware the performance of string concatenation
  8. Item 64: Refer to objects by their interfaces
  9. Item 65: Prefer interfaces to reflection
  10. Item 66: Use native methods judiciously. .
  11. Item 67: Optimize judiciously
  12. Item 68: Adhere to generally accepted naming conventions .

Lambdas and Streams

Memory Map

Objective

Following rules are described

  1. Item 42: Prefer lambdas to anonymous classes
  2. Item 43: Prefer method references to lambdas
  3. Item 44: Favor the use of standard functional interfaces
  4. Item 45: Use streams judiciously
  5. Item 46: Prefer side-effect-free functions in streams
  6. Item 47: Prefer Collection to Stream as a return type
  7. Item 48: Use caution when making streams parallel

Generics

What is Generics:


Generic are introduced to programming language from v5, also it maintains support to Raw type.
Generic type is a class or interface followed by Parameter. the parameter is given in angular Bracket.
Generiic allow us to pass the type(Integer ,String ..user defined type) to method ,class or interface.

Parameter can be Formal or actual .
Formal Paramter is used when we declare the Generic type the actual parameter is used when we pass the values.

Why ?


It is better to detect the bug at earlist . the GENERICS provides the type safety so compiler complains when you to enter values other than one specified in generic parameter.
thus ensuring destructibility at compile time (rather than leaving it for run time error .)

Following rules are described –
  1. Item 26: Don’t use raw types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
  2. Item 27: Eliminate unchecked warnings. . . . . . . . . . . . . . . . . . . . 123
  3. Item 28: Prefer lists to arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
  4. Item 29: Favor generic types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
  5. Item 30: Favor generic methods . . . . . . . . . . . . . . . . . . . . . . . . . . 135
  6. Item 31: Use bounded wildcards to increase API flexibility . . . . 139
  7. Item 32: Combine generics and varargs judiciously. . . . . . . . . . . 146
  8. Item 33: Consider typesafe heterogeneous containers . . . . . . . . . 151

MemoryMap

Creating & Destroying Objects

THIS Section concerns creating and destroying objects:

  • When and how to create them,
  • When and how to avoid creating them,
  • How to ensure they are destroyed in a timely manner, and
  • How to manage any cleanup actions that must precede their destruction.
Objects Management memory-map
Following Rules are described
  1. Consider static factory methods instead of constructors
  2. Consider a builder when faced with many constructor parameters
  3. Enforce the singleton property with a private constructor an enum type
  4. Enforce non-instantiability with a private constructor
  5. Prefer dependency injection to hard-wiring resources
  6. Avoid creating unnecessary objects
  7. Eliminate obsolete object references
  8. Avoid finalizers and cleaners
  9. Prefer try-with-resources to try-finally

Introduction to Effective Java:

Following Topics are described with best practices and rules around it in next sections:

  1. Creating and Destroying Objects
  2. Methods Common to all Objects
  3. Classes and Interface
  4. Generics
  5. Enum and Annotations
  6. Lambdas and Streams
  7. Methods
  8. General Programming
  9. Exceptions
  10. Concurrency
  11. Serialization
Progress
  1. Revisit Each Topic and complete a rule (in-progress)
    1. Creating and destroying objects (in-progress)

Objectives:

  1. Your thoughts on Why this topics? What is it about ?
    • As you go thought content verify if it matches what you thought if different what is it?
  2. Things that create Triggered point of realization for a concept
    • Words sentences worth remembering for reiteration in public or interview.
    • In general – 2 things in a text : message and presentation(points that gets your attention)
  3. Getting outcome applying things wither in code or in interview -knowledge sharing
  4. Application -where to apply in implementation
  5. Learning process — make it fast!!!

Exceptions

Memory Map

Objective

Following rules are described

  1. Item 69: Use exceptions only for exceptional conditions . . . . . . . 293
  2. Item 70: Use checked exceptions for recoverable conditions and
  3. runtime exceptions for programming errors . . . . . . . . . . 296
  4. Item 71: Avoid unnecessary use of checked exceptions . . . . . . . . 298
  5. Item 72: Favor the use of standard exceptions. . . . . . . . . . . . . . . . 300
  6. Item 73: Throw exceptions appropriate to the abstraction. . . . . . . 302
  7. Item 74: Document all exceptions thrown by each method. . . . . . 304
  8. Item 75: Include failure-capture information in detail messages. . 306
  9. Item 76: Strive for failure atomicity . . . . . . . . . . . . . . . . . . . . . . . 308
  10. Item 77: Don’t ignore exceptions . . . . . . . . . . . . . . . . . . . . . . . . . 310