Questions tagged [effective-java]

Effective Java is a book by Joshua Bloch "designed to help Java programmers make the most effective use of the Java programming language and its fundamental libraries"

Effective Java is a book by Joshua Bloch of patterns "designed to help Java programmers make the most effective use of the Java programming language and its fundamental libraries".

178 questions
0
votes
2 answers

Should exceptions be checked at lower level if higher level takes care of them

This is a quote from Effective java. "Where possible, the best way to deal with exceptions from lower layers is to avoid them, by ensuring that lower-level methods succeed. Sometimes you can do this by checking the validity of the higher-level…
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
0
votes
2 answers

Excessive checks vs Future extensibility tradeoff

I can be sure that 'my code' called returnlist() is never going to return null. Thus I do not do any null pointer check when I loop in the enhanced for loop. But, looking from maintenance this does not appear to be a good practice, since someone in…
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132
0
votes
2 answers

How to create singleton from double check idiom for lazy initialization of instance field?

private volatile FieldType field; FieldType getField() { FieldType result = field; if (result == null) { synchronized(this) { result = field; if (result == null) field = result =…
Trying
  • 14,004
  • 9
  • 70
  • 110
0
votes
1 answer

How to violate Comparable interface first provision with integers overflow?

java.lang.Comparable#compareTo method states as first provision The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compare- To(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x)…
Jaime Hablutzel
  • 6,117
  • 5
  • 40
  • 57
0
votes
3 answers

Understanding Effective Java's tips for documenting Unchecked Exceptions

From Effective Java "DOCUMENT ALL EXCEPTIONS THROWN BY EACH METHOD" It should be noted that documenting all of the unchecked exceptions that each method can throw is an ideal, not always achievable in the real world. When a class undergoes…
Geek
  • 26,489
  • 43
  • 149
  • 227
-1
votes
2 answers

Effective Java: clone() private access

In Bloch's Effective Java, 2nd edition, Item 11: Override clone judiciously has the following example: class Stack { private Object[] elements; private int size = 0; private static final int DEFAULT_INITIAL_CAPACITY = 16; public…
Abhishek Divekar
  • 1,131
  • 2
  • 15
  • 31
-1
votes
1 answer

Are Sets and Maps not parameterized?

In the first paragraph of Josh Bloch's book Effective Java's 29th Item it is said that it is the container that is parameterized Doesn't the author discard Sets and Maps as parameterized types by above declaration?
user961690
  • 698
  • 1
  • 11
  • 22
-1
votes
3 answers

Why declare all instance fields transient in singletons?

To make a singleton class that is implemented using either of the previous approaches serializable (Chapter 11), it is not sufficient merely to add imple- ments Serializable to its declaration. To maintain the singleton guarantee, you have…
-1
votes
4 answers

Effective java item 9: overriding hashcode example

I was reading Effective Java Item 9 and decided to run the example code by myself. But it works slightly different depending on how I insert a new object that I don't understand what exactly is going on inside. The PhoneNumber class looks: public…
pandagrammer
  • 841
  • 2
  • 12
  • 24
-2
votes
2 answers

What do you thínk about Java designers decided java.lang.String.valueOf((Object)null) returns "null" but not ""

[edited this question at 2020/07/27 01:30 UTC] What do you thínk about Java designers decided java.lang.String.valueOf((Object)null) returns "null" but not "" which is the length 0 text ? I think that "" text is better than "null" text instead of…
Alumuko
  • 171
  • 2
  • 11
-2
votes
1 answer

about inline the call from effective_java book

i have a question in effective_java this book, what's mean of the 'modern Java virtual machine (JVM) implementations are almost certain to inline the call to the static factory method.' i don't understand 'inline the call to the static factory…
sunh
  • 74
  • 10
-2
votes
3 answers

collection of date using generics

I am reading about Generics in Effective Java item 23. It is mentioned as below: While the prospect of accidentally inserting a coin into a stamp collection may appear far-fetched, the problem is real. For example, it is easy to imagine someone…
venkysmarty
  • 11,099
  • 25
  • 101
  • 184
-3
votes
1 answer

Effective java Item no 5 example code second edition

public class Person private final Date birthDate; // others fields omitted public boolean isBabyBoomer() { Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); gmtCal.set(1946,Calendar.JANUARY,1,0,0,0); Date boomStart…
karthick
  • 68
  • 1
  • 6
1 2 3
11
12