자바 관련해서 면접시 테크니컬 인터뷰할 때 자주 물어보는 질문들입니다.
아시는 답들 달아주세요. 면접때 어떻게 얘기해야 모범 답안 일까요?
1. What are checked and unchecked exceptions.
2. Why do you need to have checked exception?
3. How do you throw an exception?
-Using throw
4. What is factory method pattern? explain with example.
5. How can you restrict the class from creating an object?
- yes. make the constructor as private
6. what are synchronized methods?
- Only one thread can access that method at a time.
7. What are the classes that implement List interface?
- ArrayList, vectors, LinkedList
8. what's the difference between the Vector and ArrayList?
- Vector-synchronized
ArrayList-not synchronized, so faster
9. How can you create thread? which method is better and why?
- By extending Thread class, or by implementing the Runnable interface.
10. If you have a vector and you are iterating over it, and can another thread perform the update operation? what will happen when another thread tries to acces it? will it throw exception?
- Another thread can not modify the the iterator. There wont be any exception as such, but the thread goes to the waiting state.
11. Can one Jsp extend another JSP?
yes.
12. What's the difference between include directive and the include action?
-Static: All the contents of the jsp to be included will directly embedded into the main jsp at the translation time.
dynamic: The jsp to be included will be compiled and results will be embedded into the main jsp at teh compilation time.
13. Can one class extend two classes?
-No
14. When a class override the constructor and if you call default constructor what will happen?
- You need to create your own default constructor.
15. how do you implement composite key in the hibernate?
16. How do you manage the parent and child relation in hibernate?
17. What is interceptors pattern? give example?
18. What is the use of struts framework?
- Easy to use, provide many inbuilt functions, modular
19. What is the essence of AJAX?
- Asynchronous calls to teh webserver
20. What is the difference between <div> and <span>?
21. When client sends the Ajax request what happens at the server side? did server know it's an AJAX call?
- server process the request and send back the response. Server has no idea what who raised the request.
22. consider,
class A {
String str1;
String str2;
}
if you have two objects,
A a = new A();
a.str1="hello";
a.str2="hello2";
A b = new A();
b.str1="hello";
b.str2="hello2";
if you add these two instances to Set how many objects will be there in the Set? why?
- there will be 2 elements. there is no equals and hashcode() method implemented.
23. Have you made any suggestions to improve the end user experience when it comes to UI?
24. In a JSP,
page.jsp
<% int i = 10; %>
page2.jsp also
<% int i = 10; %>
if you try to do static include of these two above jsps into page3.jsp what will happen?
- translation error. 'coz of the variable name collision
if you try to do dynamic include of these two above jsps into page3.jsp what will happen?
- compiles fine
25. How can u forward the control one action to another action in struts 1.3?
26. How many instances of the servlet will be created when for multiple requests in a jsp?
- one
27. Can u configure to make new instances of servlets for each of the user request for a jsp?
28. When there is an error in the jsp page, internally will it create the servlet? when will be the error generated at translation time or at the compile time.
- Error is thrown at translation time. There wont be any servlet generated.
29. Why the compiler will not generate the default constructor when you create your own constructor?
30. Do you refer to different frameworks APIs? and study them?
31. what are taglibs? why do u need them?
- taglibgs provide customized features which can be easily plugged in n can be used in the Jsp. If you need any customized features which is not provided by framework's tag library, you can write your own.
32. Can you have only try block with finally without catch? why do you need finally?
- yes. Mainly used to close some of the costly resources like I/O or connections etc even in case of exception.
33. What are filters? how do you use them? why do u need them?
- used to manipulate the incoming requests before or after it reaches the servlets. They can be configured in your web.xml.
34. How can you access the html elements?
- using document object.
1. algorithm, given a string of (a+b)/c*d-e/f...., provide a function algorithm to calculate the actual value assuming the a,b,c,d,e,f ... are integer. what data structure to use.
2. is it ok to have the following code running without problem?
public class A {
public int method1 {
try {
...
} catch ( Exception1 ) {
...
} catch (Exception2 ) {
...
} finally {
catch (Exception3)
}
3. what are the Clonable interface used for? why does Java have this interface for if nothing is defined in this interface?
4. Can you tell me whether the element in HashSet is ordered as it inputted or if not, what about OrderedSet? how to ensure the data entered into the set is ordered based on the key attribute of the object?
예 맞아요.. 한국에서는 그런데...
제 경험으로는 미국이나 인도에서는 물어봐요. 제가 두군데서 다 있어 봤거든요...
지금은 미국에 있는데요. 여기 저기 면접 경험하면서 들었던 질문하고 또 어디서 얻은 질문들이예요.
제가 답을 아는것도 있고 모르는것도 있고 잘 설명하기 어려운것도 많고... 한번 이런 질문에 대한 모범 답변 머릿속에 넣어두면 좋을 것 같아서요.
제가 아는 답 몇개 적어보죠..
1. 꼭 체크해야할 Exception과 그렇지 않은 Exception
unchecked Exception은 컴파일 시간이 아닌 런타임 시간에 발생
Checked Exception은 RuntimeException과 Error 이외의 Exception 例) IOException
Checked Exception은 try-catch문으로 예외처리 하거나 예외를 상위로 전파시켜야 한다.
2. Checked Exception은 Try Catch 구문으로 예외처리를 할 수 있다.
3. public Object pop() {
Object obj;
if (size == 0) {
throw new EmptyStackException();
}
obj = objectAt(size - 1);
setObjectAt(size - 1, null);
size--;
return obj;
}
class TempException extends Exception{}
public class ExTest07{ // java ExTest07 e f e
public static void main( String args[] )
throws TempException
{
try{
System.out.println("1");
try{
System.out.println("2");
if( args[0].equals("e") )
throw new TempException();
}
catch( TempException ex ){
System.out.println("3");
if( args[1].equals("e") )
throw ex;
}
finally{
System.out.println("4");
}
System.out.println("5");
}
catch( TempException ex2 ){
System.out.println("6");
if( args[2].equals("e") )
throw ex2;
}
finally{
System.out.println("7");
}
System.out.println("8");
}
}
4. 팩토리 메서드 패턴에서는 객체를 생성하기 위한 인터페이스를 정의하는데, 어떤 클래스의 인스턴스를 만들지는 서브클래스에서 결정하게 됨



