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
2
votes
1 answer

Using Builder Constructor on Extended Class?

I'm implementing a Builder constructor as documented in Joshua Bloch's "Effective Java 2nd Edition. However, I'm running into a few complications when I try to extend the class and its builder. Essentially, the extended Builder in the extended child…
tmn
  • 11,121
  • 15
  • 56
  • 112
2
votes
2 answers

Can anyone explain me example from Joshua Bloch item 41?

I'm reading "Effective Java" by Joshua Bloch now and when I read item 41 "Use overloading judiciously" I was confused because of the example used there. I tried it on computer and it indeed does what it does in the book. But I don't understand…
mykola
  • 1,736
  • 5
  • 25
  • 37
2
votes
2 answers

Heterogeneous Container with two element of same type

I am reading Effective Java - Item 29. It talks about Heterogeneous container, in the example: private Map, Object> favorites = new HashMap, Object>(); public void putFavirite(Class type, T insance) { if(type == null)…
hamid
  • 2,033
  • 4
  • 22
  • 42
2
votes
1 answer

How can utility classes be used to group methods on a final class, instead of extending the class?

Joshua Bloch mentions in his book (Effective Java - 2nd Ed) in Item 4 :- Classes containing just static fields and static methods (utility classes) can be used to group methods on a final class, instead of extending the class. Can anyone…
user1522820
  • 1,584
  • 5
  • 18
  • 31
2
votes
2 answers

Effective Java. Serializable Builder pattern (how to add public no-arg constructor?)

I want to create a class in Joshua Bloch's style using Builder pattern. But I want to use this class as DTO object and transfer it from EJB. So it need to have public no-arg constructor. How I can achieve this java-bean style in builder pattern? In…
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
2
votes
2 answers

java generics with wildcards

Can someone please explain to me difference between extends and super in java generics with wildcards? I have read related posts and didn't get complete understanding. If you could explain me with real time example that would be great help for…
user1318738
1
vote
1 answer

Why is it a good practice to make a final field pointing to an immutable obj non public?

effective java has a statement about the access control: Even if a field is final and refers to an immutable object, by making it public you give up the flexibility to switch to a new internal data representation in which the field does not exist. I…
1
vote
2 answers

Glacier Class Immutable Checker does not works on Checker Framework 3.6.0

I try to use Glacier Class Immutable Checker does not works on Checker Framework 3.6.0. I get Glacier 0.1 with Maven. (http://mcoblenz.github.io/Glacier/) Then, I tried to check the sample source, but an error occurs. Can I use Glacier Class…
Alumuko
  • 171
  • 2
  • 11
1
vote
1 answer

Why is sharing the mutable internals of immutable objects a good idea?

I'm reading Joshua Bloch's "Effective Java" and have two questions. Bloch states the following. Not only can you share immutable objects, but they can share their internals. He then proceeds to give an example with one instance of BigInteger…
Noah Stebbins
  • 385
  • 1
  • 11
1
vote
1 answer

Why is the boolean logical operator ^ being used in this piece of example code from Effective Java?

I found this example code for Joshua Bloch's book, Effective Java. It's meant to demonstrate why you should avoid unnecessarily creating objects: import java.util.regex.Pattern; // Reusing expensive object for improved performance public class…
Monopole Magnet
  • 435
  • 5
  • 19
1
vote
3 answers

Make my logger very effective to my Java-application

I am struggling with the following problem and ask for help. My application has a logger module. This takes the trace level and the message (as string). Often should be messages constructed from different sources and/or different ways (e.G. once…
user2218825
1
vote
2 answers

BigDecimal is extendable and has no copy-constructor. Is that a security risk?

According to Effective Java Item 24 (Make defensive copies when needed) mutable objects pose a security risk, especially when passed as constructor arguments. One is encouraged to make defensive copies as necessary. BigDecimal is meant to be…
Gili
  • 86,244
  • 97
  • 390
  • 689
1
vote
1 answer

What is the better way to implement CountDownLatch in effective java 2nd item 72?

Effective Java Item 72 shows bad example of CountDownLatch implementation. But it doesn't show a right way to implement it. Do I have to use wait() and notify() instead of a while loop ? Can anyone suggest me a good example of this item ? Below is…
myoldgrandpa
  • 871
  • 7
  • 21
1
vote
2 answers

Singleton classes serializable

Can anyone explain this paragraph: [copied from Effective Java Joshua Bloch 3rd edition Chapter 2 Item 3 ] To make a singleton class that uses either of these approaches (i.e. keeping the constructor private and exporting a …
user6021893
1
vote
2 answers

Immutable class using static factories

I'm studying Effective Java by Joshua Bloch, where he explains about different ways of achieving immutable class. To prevent subclassing, one way is to use final. The more sophisticated way for it is to make constructor private, thus preventing…
gaurav jain
  • 3,119
  • 3
  • 31
  • 48