1) What is the difference between String and StringBuffer?
A) Strings are constants. Their values cannot be changed after they are created. StringBuffer is like String with a difference.StringBuffer can be modified. Another string can be appended to StringBuffer.
2) What is the difference between StringBuffer and StringBuilder?
A) Both are same except Methods in StringBuffer are synchronized. Methods in StringBuilder are not synchronized.
3) In a multi-threaded scenario which one do you use? ArrayList or vector
A) Methods in Vector are synchronized, so it is safe to use Vector in Multi-threaded scenario.
Methods in ArrayList are not synchronzied. So, it’s not safe in the multi-threaded scenario.
4 ) What is multi-threaded scenario?
A) When there are multiple threads invoking methods on a SINGLE object.
5) What is the default access modifier for a method in interface
A) Public
6) What is the default priority of a thread?
A) 5
7) What is native method?
A) Native methods are methods written in c and c++. JNI (Java Native interface) allows java to call methods written in c and c++.
Note: In interview always say that you have written class level and method level documentation
8) What is a daemon thread?
A) Daemon thread is a thread used by JVM. For example, a thread that does garbage collection
9) What is the lifetime of JVM?
A) JVM execute as long as non-daemon threads are running. When all the non-daemon threads of java application terminate, JVM will exit.
10) What is a weak reference?
A) Weak references do not prevent their referents from being garbage collected.
A) Strings are constants. Their values cannot be changed after they are created. StringBuffer is like String with a difference.StringBuffer can be modified. Another string can be appended to StringBuffer.
2) What is the difference between StringBuffer and StringBuilder?
A) Both are same except Methods in StringBuffer are synchronized. Methods in StringBuilder are not synchronized.
3) In a multi-threaded scenario which one do you use? ArrayList or vector
A) Methods in Vector are synchronized, so it is safe to use Vector in Multi-threaded scenario.
Methods in ArrayList are not synchronzied. So, it’s not safe in the multi-threaded scenario.
4 ) What is multi-threaded scenario?
A) When there are multiple threads invoking methods on a SINGLE object.
5) What is the default access modifier for a method in interface
A) Public
6) What is the default priority of a thread?
A) 5
7) What is native method?
A) Native methods are methods written in c and c++. JNI (Java Native interface) allows java to call methods written in c and c++.
Note: In interview always say that you have written class level and method level documentation
8) What is a daemon thread?
A) Daemon thread is a thread used by JVM. For example, a thread that does garbage collection
9) What is the lifetime of JVM?
A) JVM execute as long as non-daemon threads are running. When all the non-daemon threads of java application terminate, JVM will exit.
10) What is a weak reference?
A) Weak references do not prevent their referents from being garbage collected.
No comments:
Post a Comment