Core Java interview questions

Core Java interview questions Download Core Java interview questions PDF

Core Java interview questions

In order to load the Java Classes into a virtual environment, Classloader are used. A class loader will load key classes such as java.lang.object and several other codes into the memory. Usually, these classes are loaded only if a demand occurs. Since Java Runtime Environment includes loaders, they need not know about file and file systems. Also, the loaders are responsible for converting the named class into an equivalent binary form.

Following are the differences between StringBuffer and StringBuilder in java: –
  • StringBuffer methods are synchronized, whereas StringBuilder methods are non-synchronized.
  • In StringBuffer, a storage area is heap which can be modified easily, whereas in StringBuilder, storage is heap which can be modified easily.
  • StringBuffer is threading safe, whereas StringBuilder is not.
  • Performance of StringBuffer is very slow, whereas the performance of StringBuilder is fast.
In Java, a class is a user-defined data type from which objects are created. It can also be called as a blueprint or prototype. A class is a collection of various methods and variables which represent a set of properties that are common to all the objects of one type. A class includes components such as: –
  • Modifiers: it states that a class can be public or can have a default access.
  • Class name: the name of a class should begin with a letter and should be same as the file name.
  • Body: the class body is surrounded by braces- {}.

When we have to store a collection of objects which is unordered we prefer the Set interface. The other main reason for using Set is we can ignore duplicate entities and keep our data unique. For example, if we have a Set containing different entities "John", "Smith", "Smith", "John", "Alisha". It will display "John" and "Smith" only one time in output by ignoring the duplicated entities. On the other hand, List is and ordered the collection of objects. So, when we have to keep our entities in ordered form while not caring about the duplication we will prefer List.

The purpose of the final keyword is to make things unchanged in application lifeline. We can make a class, method or variable unchanged by writing "final" keyword before the method, class, and variable. When the final is written before the variable, it remains unchanged (you can’t change it). A function which use final keyword cannot be overridden. On the other hand, if we make a class final we cannot extend it. When we have to make these unchanged conditions, we prefer to use the final keyword.