Some Important Facts About Core Java

  1. There are 4 important OOPS concepts in Java : Inheritance, Abstraction, Encapsulation and Polymorphism.
  2. There are two types of variables in Java : Primitive types and Object Types
  3. The default value of Boolean is false (the same applies for the Wrapper class too).
  4. Marker interface is the one which doesn't contains any methods, it is like empty interface.
  5. You cannot override the 'main' method of the Java, even-though if you try to do so it will not give any exception, program compiles and executes fine. The reason is : 'main' method is of type static. Static methods are class level methods. Even-though it looks like method overriding, it is not overriding. These are two different method with respect to the corresponding class.
  6. You can Overload the 'main' method of Java, it is valid in Java.
  7. You can have only one 'Public' class and any number of non-public classes in any java source file.
  8. Inheritance is an example for IS-A relationship.
  9. Composition is an example for HAS-A relationship.
  10. You can have abstract class without any abstract methods.
  11. The use of abstract class without any abstract method : a) Whenever you  don't want to direct instantiation of the class, b) Whenever you want to add abstract future at later point of time which you are not aware currently, Otherwise I don't see any usage of such class.
  12. String class is immutable and thread-safe. The reason is , whenever we create String object mentioning some string literal either inside the constructor or direct literal, first it checks in the String constant pool whether that string literal is available or not. If available then it will not create the new instance inside the constant pool instead it points reference to the same string constant. In this case this string might be referenced by many different reference variables. Suppose you make changes to this string value it will alter all the referenced string variables by breaking the actual behavior. Because of this reason String class implemented as Final & Immutable one.
  13. If you want to update your string frequently and dynamically, in case you need to modify your string based on some scenario then you can either go With StringBuffer or StringBuilder based on either for Multithreaded application or Single threaded application. StringBuffer and StringBuilder both classes are same in behavior and functionality except the fact that, StringBuffer class is Synchronized and StringBuilder class non-synchronized.
  14. The efficient way of creating String object is : String str="abcd";, the reason is it creates instance only String Constant Pool and refer it through the reference variable 'str'. On other case, whenever you create String object using 'new' operator as : String str=new String("abcd");, in this case instance will be created in the heap and as well as in the String constant pool if the same string doesn't exist already, else it refers the existing string instance from the pool.

Still There are many to add, I will be updating this post in coming days....

Popular posts from this blog

Resolve OutOfMemoryError With ExcelExport : Export Excel Utility with Apache POI Stream API (SXSSF)

Reading a file while file being written at the same time

Be-Aware of the Performance of the String Concatenation...