Java and J2EE Tutorials, Jsp and Servlet Tutorials, Spring MVC, Solr, XML, JSON Examples, Hibernate & Struts 2 Hello World projects

Tuesday, 24 June 2014

100 Core Java Interview Questions and Answers - Part 8

Here are top selected core java interview questions asked in high level interviews, these questions may be helpful for both freshers or experienced professional going for interview.

71) What are immutable objects in Java?

In java, immutable objects are the objects which can not be changed once created. Any change to the states of these object results in a new object. String objects are the example of immutable objects in java any change to the states of an String object results in a new object and the old object remains unchanged.

72) What is the difference between a StringBuffer and StringBuilder class in Java?

In java both StringBuffer and StringBuilder classes are non immutable in nature, the only difference in between them is that StringBuffer class in thread-safe while StringBuilder is not thread safe in nature. StringBuilder class was introduced in Java5 to reduce the overhead of synchronization.

73) How many types of memory areas are allocated by JVM?

JVM allocated memory areas in many forms like:
1. Class(Method) Area
2. Heap
3. Stack
4. Program Counter Register
5. Native Method Stack

74) What if I changed the order of public static and void in ‘public static void main(String args[])’?

The program will compile fine and run properly, main() method implementation is regardless of the order of public, static and void keywords.

75) What is the default value for an instance variable in Java?

All instance variables are initialized to “null” by default.

76) What do you mean by composition in Java ?

Holding the reference of one class in another class in known as composition in Java.

77) Can be define an abstract method in an non abstract class ?

No, if a single method is declared as abstract in a class then the class must be declared as abstract itself.

78) Can we declare a class as abstract and final in Java?

No, we cannot declare an abstract method as final, abstract methods does not have body and they are meant to be overridden in another class, if we declare them final than its impossible to override them and hence no use of them.

Thanks for reading !
Being Java Guys Team

1 comment:

  1. In java both StringBuffer and StringBuilder classes are not immutable in nature.

    Qus no 72)


Like Us on Facebook

Like Us On Google+


Skype: neel4soft