您的位置:首页 > 产品设计 > UI/UE

Java Interview Questions

2006-11-02 19:25 295 查看
This site contains the common interview questions, answers and tutorials about Java, J2EE, Struts, RUP, XML, JSP, Servlets and Oracle.

1. What is the difference between an Abstract class and Interface ?

Answer:Abstract classes may have some executable methods and methods left unimplemented. Interfaces contain no implementation code. A class can implement any number of interfaces, but subclass at most one abstract class.
An abstract class can have nonabstract methods. All methods of an interface are abstract.
An abstract class can have instance variables. An interface cannot.
An abstract class can define constructor. An interface cannot.
An abstract class can have any visibility: public, protected, private or none (package). An interface's visibility must be public or none (package).
An abstract class inherits from Object and includes methods such as clone() and equals().

2. What is user defined exception ?

Answer:Java supports exception handling by its try catch constructs. Exceptions are conditions which JVM or applications developed in java are unable to handle. Java API define exception classes for such conditions. These classes are derived from java.lang.Throwable class. User defined exceptions are those exceptions which an application provider or an API provider defines by subclassing java.lang.Throwable class.

3. What do you know about the garbage collector ?

Answer: Garbage collector is a runtime component of Java which sits on top of the heap: memory area from which Java objects are created and periodically scans it for objects which are eligible to be reclaimed when there are no references to these objects in the program. There is simply no way to force garbage collection, but you can suggest your intention of getting the object garbage collecetd to Java Virtual Machine by calling

4. What is the difference between C++ & Java ?

Answer:

5. Explain RMI Architecture?

Answer: RMI uses a layered architecture, each of the layers could be enhanced or replaced without affecting the rest of the system. The details of layers can be summarised as follows:
Application Layer: The client and server program Stub & Skeleton Layer: Intercepts method calls made by the client/redirects these calls to a remote RMI service. Remote Reference Layer: Understands how to interpret and manage references made from clients to the remote service objects. Transport layer: Based on TCP/IP connections between machines in a network. It provides basic connectivity, as well as some firewall penetration strategies.

6. How do you communicate in between Applets & Servlets ?

Answer: We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to the web server. The server then passes this information to the servlet in the normal way. Basically, the applet pretends to be a web browser, and the servlet doesn't know the difference. As far as the servlet is concerned, the applet is just another HTTP client.

7. What is the use of Servlets ?

Answer: Servlets may be used at different levels on a distributed framework. The following are some examples of servlet usage: To accept form input and generate HTML Web pages dynamically. As part of middle tiers in enterprise networks by connecting to SQL databases via JDBC. In conjunction with applets to provide a high degree of interactivity and dynamic Web content generation. For collaborative applications such as online conferencing. A community of servlets could act as active agents which share data with each other. Servlets could be used for balancing load among servers which mirror the same content. Protocol support is one of the most viable uses for servlets. For example, a file service can start with NFS and move on to as many protocols as desired; the transfer between the protocols would be made transparent by servlets. Servlets could be used for tunneling over HTTP to provide chat, newsgroup or other file server functions.

8. What is JDBC? How do you connect to the Database ?
9. In an HTML form I have a Button which makes us to open another page in 15 seconds. How will do you that ?
10. What is the difference between Process and Threads ?

Answer:

10(2). What is the difference between a process and a program?

Answer:

Here is what a process is...

A process is a single executable module that runs concurrently with other executable modules. For example, in a multi-tasking environment that supports processes, like OS/2, a word processor, an internet browser, and a data base, are separate processes and can run concurrently. Processes are separate executable, loadable modules as opposed to threads which are not loadable. Multiple threads of execution may occur within a process. For example, from within a data base application, a user may start both a spell check and a time consuming sort. In order to continue to accept further input from the user, the active thread could start two other concurrent threads of execution, one for the spell check and one for the sort. Contrast this with multiple .EXE files (processes) like a word processor, a data base, and internet browser, multi-tasking under OS/2 for example.

Here is what a program is..

A set of instructions for a computer that lets the computer perform a specific task. Programs that perform tasks directly relating to what a person would want to do (such as word processors, spreadsheets, etc.) are called application software, to distinguish them from system software.

11. What is the difference between RMI & Corba ?

Answer:RMI is completely Java based, where CORBA is language independant. There are many adapters for CORBA, and programs can call processes written in any language that has a CORBA interface. CORBA has many more features documented in the specification than just process communication. RMI is easier to implement if you already know Java - it looks just the same as calling a process locally - but it's limited to only calling other Java applications.

12. What are the services in RMI ?
13. How will you initialize an Applet ?
14. What is the order of method invocation in an Applet ?
15. When is update method called ?
16. How will you pass values from HTML page to the Servlet ?
17. Have you ever used HashTable and Dictionary ?
18. How will you communicate between two Applets ?
19. What are statements in JAVA ?
20. What is JAR file ?
21. What is JNI ?
22. What is the base class for all swing components ?
23. What is JFC ?
24. What is Difference between AWT and Swing ?
25. Considering notepad/IE or any other thing as process, What will happen if you start notepad or IE 3 times? Where 3 processes are started or 3 threads are started ?
26. How does thread synchronization occurs inside a monitor ?
27. How will you call an Applet using a Java Script function ?
28. Is there any tag in HTML to upload and download files ?
29. Why do you Canvas ?
30. How can you push data from an Applet to Servlet ?
31. What are 4 drivers available in JDBC ?
32. How you can know about drivers and database information ?
33. If you are truncated using JDBC, How can you know ..that how much data is truncated ?
34. And What situation , each of the 4 drivers used ?
35. How will you perform transaction using JDBC ?
36. In RMI, server object first loaded into the memory and then the stub reference is sent to the client ? or whether a stub reference is directly sent to the client ?
37. Suppose server object is not loaded into the memory, and the client request for it , what will happen?

38. What is serialization ?

Answer:In the Java world, serialization is the storing of an object's current state on any permanent storage media for later reuse. This is done using when you use the seriazlizable interface or when using the ObjectOutputStream and ObjectInputStream classes.

39. Can you load the server object dynamically? If so, what are the major 3 steps involved in it ?
40. What is difference RMI registry and OSAgent ?
41. To a server method, the client wants to send a value 20, with this value exceeds to 20,. a message should be sent to the client ? What will you do for achieving for this ?
42. What are the benefits of Swing over AWT ?
43. Where the CardLayout is used ?
44. What is the Layout for ToolBar ?
45. What is the difference between Grid and GridbagLayout ?
46. How will you add panel to a Frame ?
47. What is the corresponding Layout for Card in Swing ?
48. What is light weight component ?
49. Can you run the product development on all operating systems ?
50. What is the webserver used for running the Servlets ?
51. What is Servlet API used for connecting database ?
52. What is bean ? Where it can be used ?
53. What is difference in between Java Class and Bean ?
54. Can we send object using Sockets ?
55. What is the RMI and Socket ?
56. How to communicate 2 threads each other ?
57. What are the files generated after using IDL to Java Compilet ?
58. What is the protocol used by server and client ?
59. Can I modify an object in CORBA ?
60. What is the functionality stubs and skeletons ?
61. What is the mapping mechanism used by Java to identify IDL language ?
62. Diff between Application and Applet ?
63. What is serializable Interface ?
64. What is the difference between CGI and Servlet ?

Answer:The main difference between the two is first process the client requests (to the server) one at a time where as in second requests are lined up and send to the server as a collection. The main advantage of using servlets is its security features. [Servlets are small programs that are executed on the server side of the connection]

65. What is the use of Interface ?

Answer:Interface are used when we know the functionality of a program but its implementation is not known to us. This way we can declare the constants and functions in the interface and later on they can be implemented by any program. [We can fully abstract a class from its implementation using this way. Thats why they are called interface]

66. Why Java is not fully objective oriented ?

Answer:Because it doesn’t support many features of OO paradigm like operater overloading. But it to some extent is better than C++ as it has the main function in the class itself thus providing a extra security to a program.

67. Why does not support multiple Inheritance ?

Answer:Java do support a multiple inheritance but not in a way as C++ support. Instead it support by the means of interfaces. [The main reason why java doesn’t support Multiple Inheritance is it allows same features to be inherited again and again and java being a secure language didn’t allow anything that will lead to insecurity.

68. What it the root class for all Java classes ?
69. What is polymorphism ?
70. Suppose If we have variable ' I ' in run method, If I can create one or more thread each thread will occupy a separate copy or same variable will be shared ?
71. In servlets, we are having a web page that is invoking servlets username and password ? which is checked in the database ? Suppose the second page also If we want to verify the same information whether it will connect to the database or it will be used previous information?

72. What are virtual functions ?

Answer:Virtual function is a way to achieve run time polymorphism in C++. It is defined in the base class with a keyword virtual and we need to override the same function in the derived class also. When called the function is called based on the object reference rather than object itself.

73. Write down how will you create a binary Tree ?
74. What are the traverses in Binary Tree ?
75. Write a program for recursive Traverse ?
76. What are session variable in Servlets ?
77. What is client server computing ?
78. What is Constructor and Virtual function? Can we call Virtual function in a constructor ?
79. Why we use OOPS concepts? What is its advantage ?

80. What is the middleware ? What is the functionality of Webserver ?

Answer:

Middleware is a component that sits between client and server and allows every request from client to server through it. This not only increases performance but also reduces trafic between client and server as many request may be handled by the middleware itself.

Java implements middleware using Servlets at the lower level and using J2ee at the higher level.

81. Why Java is not 100 % pure OOPS ? ( EcomServer )
82. When we will use an Interface and Abstract class ?

83. What is an RMI?

Answer:Remote Method Invocation (RMI) is a java Mechanism that allows a program to invoke a method that is being executed on a remote machine. [The important thing to rememeber here remote object whose method is being invoked must be executing on the remote machine)

84. How will you pass parameters in RMI ? Why u serialize?
85. What is the exact difference in between Unicast and Multicast object ? Where we will use ?
86. What is the main functionality of the Remote Reference Layer ?
87. How do you download stubs from a Remote place ?
88. What is the difference in between C++ and Java ? can u explain in detail ?
89. I want to store more than 10 objects in a remote server ? Which methodology will follow ?
90. What is the main functionality of the Prepared Statement ?

Answer:If you want to execute a Statement object many times, it will normally reduce execution time to use a PreparedStatement object instead. The following code snippet will give a better idea

PreparedStatement updateSales = con.prepareStatement(
“UPDATE EMP SET SAL = ? WHERE EMP_NO LIKE ? “);
updateSales.setInt(1, 10000);
updateSales.setString(2, “E%”);
updateSales.executeUpdate():

91. What is meant by static query and dynamic query ?
92. What are the Normalization Rules ? Define the Normalization ?
93. What is meant by Servlet? What are the parameters of the service method ?
94. What is meant by Session ? Tell me something about HTTPSession Class ?
95. How do you invoke a Servlet? What is the difference in between doPost and doGet methods ?

Answer:Servlet is always invoked through the browser either through url string or by pressing a button through action tag in html.
doGet method: is used when we use get attribute in the form tag in the html page calling the servlet. When used doGet, the parameters from the client to the server are passed as a part of url string. The main limitations here the size and number of parameters may create some problem.

doPost method: is used when we use post attribute in the form tag in the html page calling the servlet. When used doPost, the parameters from the client to the server are passed as encoded string not as a part of url string.

96. What is the difference in between the HTTPServlet and Generic Servlet ? Explain their methods ? Tell me their parameter names also ?

Answer:The main difference between the HTTPServlet and Generic Servlet is first is used whenever there is an client and server communicate using HTTP protocol where as second is used for normal communication.

97. Have you used threads in Servlet ?
98. Write a program on RMI and JDBC using StoredProcedure ?
99. How do you sing an Applet ?
100. In a Container there are 5 components. I want to display the all the components names, how will you do that one ?
101. Why there are some null interface in java ? What does it mean ? Give me some null interfaces in JAVA ?
102. Tell me the latest versions in JAVA related areas ?
103. What is meant by class loader ? How many types are there? When will we use them ?
104. How do you load an Image in a Servlet ?
105. What is meant by flickering ?
106. What is meant by distributed Application ? Why we are using that in our applications ?
107. What is the functionality of the stub ?
108. Have you used any version control ?

Answer:Version contorl is a process of keeping many versions of a project so that whenever any error occurs due to some addtion/deletion/modification of the code the problem can be sorted out easily.

109. What is the latest version of JDBC ? What are the new features are added in that ?
110. Explain 2 tier and 3 -tier Architecture ?

Answer:2 tier means communication between 2 components client and server. 3 tier means all the requests/responses from/to client to/from the server are done through middleware that contains the business logic.

111. What is the role of the webserver ?
112. How have you done validation of the fields in your project ?
113. What is the main difficulties that you are faced in your project ?
114. What is meant by cookies ? Explain ?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: