11 Things About Java You May Not Have Known

  1. The New operator in Java creates objects. The new operator is followed by a call to a constructor, which initializes the new object. The Constructor's job is to initialize the members after the object has reserved memory for itself.

  2. The Default constructor is provided by the compiler, if we don't declare any constructor. If we declare a parameterized constructor, the compiler will not create any default non-parameterized constructor for the class.

  3. The "instanceOf" method returns true if the object is either an instance of the mentioned Class or a subclass of the mentioned Class. The instanceOf method can be used with Interfaces as well, so as to check if the respective class implements the interface.

  4. Though Static methods cannot access the instance variables directly, they can access them using instance handler.

  5. Only Classes can be made Singleton, to have one object only.

  6. As of Java 8, interface implementation facilitates partial inheritance. Java doesn't support multiple class inheritance. Though an Interface can extend multiple Interfaces.

  7. "equals" is the member of object class which returns true if the content of objects are same whereas "==" evaluates to see if the object handlers on the left and right are pointing to the same object in memory.

  8. Only declaring primitive types as final makes them immutable. Making objects final means that the object handler cannot be used to target some other object, but the object is still mutable.

  9. Final variables should be defined before or during object creation. Final variables can also be defined within constructor.

  10. Multi-threading becomes very simple when you use only as many threads as you need, control how threads interact, use some simple patterns everyone in your team understands.

  11. Java Coders don't code Pointers as Java intrinsically manages their use.