How to create a immutable object in Java? Does all property of immutable object needs to be final?

  To create a object immutable You need to make the class final and all its member final so that once objects gets crated no one can modify its state. You can achieve same functionality by making member as non final but private and not modifying them except in constructor. Also its NOT necessary to … Read more

What is immutable object in Java? Can you change values of a immutable object?

A Java object is considered immutable when its state cannot change after it is created. Use of immutable objects is widely accepted as a sound strategy for creating simple, reliable code. Immutable objects are particularly useful in concurrent applications. Since they cannot change state, they cannot be corrupted by thread interference or observed in an … Read more

How much subclasses you can maximum in Inheritance?

In one of our old JAVA projects we had an inheritance depth of five. Believe us we never liked that code. It’s bad to have a huge inheritance depth. A maintainable inheritance depth should be maximum 5. Anything above that is horrible. There is no limit as such specified anywhere that there is some limit … Read more

What is JAVAdoc utility?

Javadoc parses comments in JAVA source files and produced HTML pages for the same. Below is the syntax for the same javadoc [ options ] [ packagenames ] [ sourcefiles ] [ @files ] Arguments can be in any order. Options Command-line options that is doctitle, windowtitle, header, bottom etc Packagenames: – A series of … Read more

What is a StringBuffer class and how does it differs from String class?

StringBuffer is a peer class of String that provides almost all functionality of strings. String represents fixed-length, immutable character sequences. Comparatively StringBuffer represents mutable, growable and writeable character sequences. But StringBuffer does not create new instances as string so it’s more efficient when it comes to intensive concatenation operation. In Core Java, the StringBuffer class … Read more