Java is my all time favorite programming language because of its strong networking support and other strong features. Facing interview in java is always a challenge because of it broad view of concept. Some question are repeatedly ask in interview while you goes for java as experience person or as fresher. Some of question i have faced two or three times . I am listing them below so that you guys does not struggle to give answer to them.
Q1. What is the difference between String and String Builder/String Buffer?
Ans. String object is immutable , immutable means we can not change the values store inside a string object. Let a example
String temp="Hello";
If you append anything to temp then it will create a new object if append a different string to temp.
temp="Hello"+ "Check";
Printing temp will show "Hello check" but internally we have created two object while append "Check" to temp. Same process goes when you use trim method of String. So to improve performance we recommend to use String Buffer/String Builder. Both are mutable and we can changes the value of them without generating a new object.
Now important point is that String Buffer is synchronized and String Builder is not. So if you are not using threading , use String Builder else String Buffer. String Builder was introduce in java 1.4 but String String Buffer was launched in Java 1.5 version
Q2. What is the difference between Design Pattern and Framework?
Ans. Design Pattern is the Pattern designed by Java to make Java Application. It describe how to divide our complete java application into three part i.e MVC
Q1. What is the difference between String and String Builder/String Buffer?
Ans. String object is immutable , immutable means we can not change the values store inside a string object. Let a example
String temp="Hello";
If you append anything to temp then it will create a new object if append a different string to temp.
temp="Hello"+ "Check";
Printing temp will show "Hello check" but internally we have created two object while append "Check" to temp. Same process goes when you use trim method of String. So to improve performance we recommend to use String Buffer/String Builder. Both are mutable and we can changes the value of them without generating a new object.
Now important point is that String Buffer is synchronized and String Builder is not. So if you are not using threading , use String Builder else String Buffer. String Builder was introduce in java 1.4 but String String Buffer was launched in Java 1.5 version
Q2. What is the difference between Design Pattern and Framework?
Ans. Design Pattern is the Pattern designed by Java to make Java Application. It describe how to divide our complete java application into three part i.e MVC
- Model : This part will handle only Business logic (Communication with Data Base).
- View : This part only have presentation logic.
- Controller : This part of logic contain the overall control flow (What should application has to do when a request comes from a Client).
Framework is a small s/w which has been designed by using Design Pattern. And it contain Web Application deployment architecture
i.e Spring, EJB
Q3. What is the difference between passivation and activation?
Ans. While we client is not using any data then its store on secondary storage, this is called passivation but when client send a request to use that piece of data then it loaded into main memory and this refers as activation process.
Q4. Explain Difference HashTable and HashMap?
Ans. Here is some key difference between them ---
- Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as un synchronized Objects typically perform better than synchronized ones.
- Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.
- One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.
Q5. Differnce between Vector and Array List?
Ans. Vector is synchronized whereas Array List is not synchronized . Using Vector inside threading application is recommended as it avoid insertion and deletion at once by throwing UnSupportedException
Q6. What is difference between Abstract class and Interface ?
Ans. Java does not support multiple inheritance so this restriction is some what avoided using interface . You can implement multiple interface in a single class but can not extends more than one class at time.
- When you implement an interface to a class then its compulsory to override all method of interface (if class is abstract then its not necessary). But if you extends a abstract , there is no such necessity
- Abstract class implementation is fast
- Interface provide only signature of method not code. but abstract class can have code for method
- Interface'method is implicitly abstract
No comments:
Post a Comment
Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging