Wednesday, January 21, 2009

Java Job Interview Questions & Answers

Special Tips
The rule is that not the best qualified candidates get job. Your on-site performance plays a big role. Here are some easily forgettable points.
• 90% interviewing questions raised based on your own resume.
• eye-to-eye contact, smiling all the way. don't miss anyone in the corner.
• asking easier and relevant questions back to the interviewers occasionally.
• be honest to answer technical questions, you are not expert to know everything.
• don't let your boss feel you might be a threat to take his position.
• don't be critical, focus on what you can do.
• try to be humor to show your smartness.
• don't act in a superior way.
• find right time to raise questions AND answer those questions to show your strength.
• aggressively to get candidacy info back after interviewing.
________________________________________
1. For more tips, go to this special tips page
2. Tell me about yourself?
The first is focusing on the needs of the organization. The second is focusing on the needs of the people within that organization. Don't talk so much about strong points about yourself because your resume has already brought you at the interview site.
3. How to deal with a question that is inappropriate?
o Briefly answer the question and move to a new topic.
o Ignore the question and redirect the discussion toward a different topic.
o If the question is blatant and offensive, you have every right to terminate the interview and walk out.
o Don't answer the question, but answer the intent behind the question.
For instance, if the interviewer asks, "Who is going to take care of your children when you have to travel?" You might answer, "I can meet the travel and work schedule that this job requires." Or if he/she asks, "Are you planning a family in the future?" You might say, "Right now I am focused on my career and as a family is always an option, it is not a priority right now."
4. What lessons have you learnt from "Apprentice" show?
At least 8 lessons:
1. Have a Strategy
2. Find Out What the Boss/Client Wants and Give it to Them
3. Deal With the Person in Charge
4. Be Positive
5. Have the Courage to Speak Your Mind
6. Stand Up For Yourself
7. Be Flexible
8. There's Life After Being Fired
Return to top
________________________________________
Java Language
Note: only the most important questions are listed below and they are not categorized, since your interviewing questions will not be categorized either.
1. More Java related interview questions.
2. What is the difference between Process and Thread?(donated in April 2005)
A process can contain multiple threads. In most multithreading operating systems, a process gets its own memory address space; a thread doesn't. Threads typically share the heap belonging to their parent process.
For instance, a JVM runs in a single process in the host O/S. Threads in the JVM share the heap belonging to that process; that's why several threads may access the same object.
Typically, even though they share a common heap, threads have their own stack space. This is how one thread's invocation of a method is kept separate from another's.
This is all a gross oversimplification, but it's accurate enough at a high level. Lots of details differ between operating systems.
Process Thread
A program Similar to a sequential program
Can run on its own Cannot run on its own
Unit of allocation Unit of execution
Have its own memory space Share with others
Each process has one or more threads Each thread belongs to one process
Expensive, need to context switch Cheap, can use process memory and may not need to context switch
More secure. One process cannot corrupt another process Less secure. A thread can write the memory used by another thread
3. Can one create a method which gets a String and modifies it?(donated in April, 2005)
No. In Java, Strings are constant or immutable; their values cannot be changed after they are created, but they can be shared. Once you change a string, you actually create a new object. For example:
String s = "abc"; //create a new String object representing "abc"
s = s.toUpperCase(); //create another object representing "ABC"
4. What is difference between abstract class and interface in Java?
Such question has been answered in More Java interview questions.
5. Why is multiple inheritance not possible in Java?
It depends on how you understand "inheritance". Java can only "extends" one super class, but can "implements" many interfaces; that doesn't mean the multiple inheritance is not possible. You may use interfaces to make inheritance work for you. Or you may need to work around. For example, if you cannot get a feature from a class because your class has a super class already, you may get that class's feature by declaring it as a member field or getting an instance of that class. So the answer is that multiple inheritance in Java is possible.
6. Can Java code be compiled to machine dependent executable file?
Yes. There are many tools out there. If you did so, the generated exe file would be run in the specific platform, not cross-platform.
7. What is the relationship between synchronized and volatile keyword?
The JVM is guaranteed to treat reads and writes of data of 32 bits or less as atomic.(Some JVM might treat reads and writes of data of 64 bits or less as atomic in future) For long or double variable, programmers should take care in multi-threading environment. Either put these variables in a synchronized method or block, or declare them volatile.
8. What factors are used to decide using synchronized or volatile?
Whether you use volatile or synchronized depends on several factors.
o If you are not updating many variables often in a multithread environment, consider using volatile.
o If you are updating many variables, consider using synchronized, because using volatile might be slower.
9. In your opinion, what is the most significant new feature in JDK 1.5 as compared to previous versions? (listed in a Java job recruiter keane.com)
Please visit What is new in jdk 1.5 for more info.
10. This class (IncrementImpl) will be used by various threads concurrently; can you see the inherent flaw(s)? How would you improve it?(listed in a Java job recruiter keane.com)
11. public class IncrementImpl {
12. private static int counter = 0;
13. public synchronized void increment() {
14. counter++;
15. }
16. public int getCounter() {
17. return counter;
18. }
19. }
The counter is static variable which is shared by multiple instances of this class. The increment() method is synchronized, but the getCounter() should be synchronized too. Otherwise the Java run-time system will not guarantee the data integrity and the race conditions will occur. The famous producer/consumer example listed at Sun's thread tutorial site will tell more.
one of solutions

public class IncrementImpl {
private static int counter = 0;
public synchronized void increment() {
counter++;
}
public synchronized int getCounter() {
return counter;
}
}
20. What are the drawbacks of inheritance? (donated by RS in Mar. 2005)
Since inheritance inherits everything from the super class and interface, it may make the subclass too clustering and sometimes error-prone when dynamic overriding or dynamic overloading in some situation. In addition, the inheritance may make peers hardly understand your code if they don't know how your super-class acts.
Usually, when you want to use a functionality of a class, you may use subclass to inherit such function or use an instance of this class in your class. Which is better, depends on your specification.
21. Is there any other way that you can achieve inheritance in Java?(donated by RS in Mar. 2005)
There are a couple of ways. As you know, the straight way is to "extends" and/or "implements". The other way is to get an instance of the class to achieve the inheritance. That means to make the supposed-super-class be a field member. When you use an instance of the class, actually you get every function available from this class, but you may lose the dynamic features of OOP.
22. Two methods have key words static synchronized and synchronized separately. What is the difference between them? (donated by RS in Mar. 2005)
Both are synchronized methods. One is instance method, the other is class method. Method with static modifier is a class method. That means the method belongs to class itself and can be accessed directly with class name and is also called Singleton design. The method without static modifier is an instance method. That means the instance method belongs to its object. Every instance of the class gets its own copy of its instance method.
Since both methods are synchronized methods, you are not asked to explain what is a synchronized method. You are asked to tell the difference between instance and class method. Of course, your explanation to how synchronized keyword works doesn't hurt. And you may use this opportunity to show your knowledge scope.
When synchronized is used with a static method, a lock for the entire class is obtained. When synchronized is used with a non-static method, a lock for the particular object (that means instance) of the class is obtained.
23. How do you create a read-only collection? (donated in Mar. 2005)
The Collections class has six methods to help out here:
1. unmodifiableCollection(Collection c)
2. unmodifiableList(List list)
3. unmodifiableMap(Map m)
4. unmodifiableSet(Set s)
5. unmodifiableSortedMap(SortedMap m)
6. unmodifiableSortedSet(SortedSet s)
If you get an Iterator from one of these unmodifiable collections, when you call remove(), it will throw an UnsupportedOperationException.
24. Can a private method of a superclass be declared within a subclass?
Sure. A private field or method or inner class belongs to its declared class and hides from its subclasses. There is no way for private stuff to have a runtime overloading or overriding (polymorphism) features.
25. Why Java does not support multiple inheritence ?
Java DOES support multiple inheritance via interface implementation.
26. What is the difference between final, finally and finalize?
Short answer:
o final - declares constant
o finally - relates with exception handling
o finalize - helps in garbage collection
If asked to give details, explain:
o final field, final method, final class
o try/finally, try/catch/finally
o protected void finalize() in Object class
Return to top
________________________________________
Networking
1. More networking questions
2. What is SSL? (donated in April, 2005)
SSL stands for Secure Sockets Layer, a protocol developed by Netscape for transmitting private documents via internet. It works by encrypting data sent over SSL connection. URLs that require a SSL connection starts as https. Browsers like Netscape navigator and Internet Explorer support SSL.
3. What two protocols are used in Java RMI technology?
Java Object Serialization and HTTP. The Object Serialization protocol is used to marshal call and return data. The HTTP protocol is used to "POST" a remote method invocation and obtain return data when circumstances warrant.
4. What is difference between Swing and JSF?
The key difference is that JSF runs on the server in a standard Java servlet container like Tomcat or WebLogic and display HTML or some other markup to the client.
5. What is JSF?
JSF stands for JavaServer Faces, or simply Faces. It is a framework for building Web-based user interfaces in Java. Like Swing, it provides a set of standard widgets such as buttons, hyperlinks, checkboxes, ans so on.
Return to top
________________________________________
XML
1. More XML questions
Return to top
________________________________________
JDBC
1. More JDBC questions
Return to top
________________________________________
JSP
1. More JSP questions
2. What is a JSP and what is it used for?
Java Server Pages (JSP) is a platform independent presentation layer technology that comes with SUN’s J2EE platform. JSPs are normal HTML pages with Java code pieces embedded in them. JSP pages are saved to *.jsp files. A JSP compiler is used in the background to generate a Servlet from the JSP page.
3. What is difference between custom JSP tags and beans?
Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. To use custom JSP tags, you need to define three separate components:
1. the tag handler class that defines the tag's behavior
2. the tag library descriptor file that maps the XML element names to the tag implementations
3. the JSP file that uses the tag library
When the first two components are done, you can use the tag by using taglib directive:
<%@ taglib uri="xxx.tld" prefix="..." %>
Then you are ready to use the tags you defined. Let's say the tag prefix is test:
MyJSPTag or
JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags

to declare a bean and use

to set value of the bean class and use
<%=identifier.getclassField() %>
to get value of the bean class.
Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences:
o Custom tags can manipulate JSP content; beans cannot.
o Complex operations can be reduced to a significantly simpler form with custom tags than with beans.
o Custom tags require quite a bit more work to set up than do beans.
o Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page.
o Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
4. what are the two kinds of comments in JSP and whats the difference between them
<%-- JSP Comment --%>

Return to top
________________________________________
Servlet
1. More Servlet questions
2. What mechanisms are used by a Servlet Container to maintain session information?
Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information
3. Difference between GET and POST
In GET, your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 260 characters, not secure, faster, quick and easy.
In POST, your name/value pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size limitations on the form's output. It is used to send a chunk of data to the server to be processed, more versatile, most secure.
4. What is session?
The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests.
5. What is servlet mapping?
The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to servlets.
6. What is servlet context ?
The servlet context is an object that contains a servlet's view of the Web application within which the servlet is running. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use. (answer supplied by Sun's tutorial).
7. Which interface must be implemented by all servlets?
Servlet interface.
Return to top
________________________________________
Struts
1. More Struts questions
2. What is Struts?
Struts is a web page development framework and an open source software that helps developers build web applications quickly and easily. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.
Return to top
________________________________________
EJB
1. More EJB questions
2. What is session Facade
Session Facade is a design pattern to access the Entity bean through local interface than acessing directly. It increases the performance over the network. In this case we call session bean which on turn call entity bean
3. what is the difference between session and entity bean?
Session beans are business data and have not any persistance. Entity beans are Data Objects and have more persistance.
Return to top
________________________________________
J2EE
1. More J2EE questions
2. What is difference between J2EE 1.3 and J2EE 1.4?
J2EE 1.4 is an enhancement version of J2EE 1.3. It is the most complete Web services platform ever.
J2EE 1.4 includes:
o Java API for XML-Based RPC (JAX-RPC 1.1)
o SOAP with Attachments API for Java (SAAJ),
o Web Services for J2EE(JSR 921)
o J2EE Management Model(1.0)
o J2EE Deployment API(1.1)
o Java Management Extensions (JMX),
o Java Authorization Contract for Containers(JavaACC)
o Java API for XML Registries (JAXR)
o Servlet 2.4
o JSP 2.0
o EJB 2.1
o JMS 1.1
o J2EE Connector 1.5
The J2EE 1.4 features complete Web services support through the new JAX-RPC 1.1 API, which supports service endpoints based on servlets and enterprise beans. JAX-RPC 1.1 provides interoperability with Web services based on the WSDL and SOAP protocols.
The J2EE 1.4 platform also supports the Web Services for J2EE specification (JSR 921), which defines deployment requirements for Web services and utilizes the JAX-RPC programming model.
In addition to numerous Web services APIs, J2EE 1.4 platform also features support for the WS-I Basic Profile 1.0. This means that in addition to platform independence and complete Web services support, J2EE 1.4 offers platform Web services interoperability.
The J2EE 1.4 platform also introduces the J2EE Management 1.0 API, which defines the information model for J2EE management, including the standard Management EJB (MEJB). The J2EE Management 1.0 API uses the Java Management Extensions API (JMX).
The J2EE 1.4 platform also introduces the J2EE Deployment 1.1 API, which provides a standard API for deployment of J2EE applications.
The J2EE 1.4 platform includes security enhancements via the introduction of the Java Authorization Contract for Containers (JavaACC). The JavaACC API improves security by standardizing how authentication mechanisms are integrated into J2EE containers.
The J2EE platform now makes it easier to develop web front ends with enhancements to Java Servlet and JavaServer Pages (JSP) technologies. Servlets now support request listeners and enhanced filters. JSP technology has simplified the page and extension development models with the introduction of a simple expression language, tag files, and a simpler tag extension API, among other features. This makes it easier than ever for developers to build JSP-enabled pages, especially those who are familiar with scripting languages.
Other enhancements to the J2EE platform include the J2EE Connector Architecture, which provides incoming resource adapter and Java Message Service (JMS) pluggability. New features in Enterprise JavaBeans (EJB) technology include Web service endpoints, a timer service, and enhancements to EJB QL and message-driven beans.
The J2EE 1.4 platform also includes enhancements to deployment descriptors. They are now defined using XML Schema which can also be used by developers to validate their XML structures.
Note: The above information comes from SUN released notes.
3. Do you have to use design pattern in J2EE project?
Yes. If I do it, I will use it. Learning design pattern will boost my coding skill.
4. Is J2EE a super set of J2SE?
Yes
Return to top
________________________________________
JMS
1. What is JMS?
Java Message Service is the new standard for interclient communication. It allows J2EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.
2. What type messaging is provided by JMS
Both synchronous and asynchronous
3. How may messaging models do JMS provide for and what are they?
JMS provides for two messaging models, publish-and-subscribe and point-to-point queuing
4. For more information about JMS, please read XML faqs regarding JAXM technology
Return to top
________________________________________
Web Logic Faqs
More Web Logic questions
1. What is Web service?
Web services are technologies built on HTTP, XML, JMS and SOAP. Web service interfaces are described using documents in WSDL standard. web service is stored as a file with a JWS extension.
Misc
1. What is JSF?
JavaServer Faces(JSF) is a framework for building web-based user interface in Java. Unlike Swing, JSF provides widgets like buttons, hyperlinks, checkboxes, etc. in diferrent ways. It has extensible facilities for validating inputs and converting objects to and from strings for display.
JSF is the Java answer to Microsoft ASP.NET's Web Forms. ASP.Net is roughly equivalent to the Servlet and JSP.
2. What is Netegrity SiteMinder?
SiteMinder is developed by www.netegrity.com. It provides a single sign-on (SSO) security model to let companies administer and enforce user access to their Web applications. SiteMinder has the following features:
o Centralized, policy-based control of user authentication and authorization management.
o Extensive support for heterogeneous IT environments.
o Standardized role-based access control (RBAC).
o Comprehensive password management, audit and reporting services.
3. What is Maven?
Maven is a Java project management and project comprehension tool developed by http://maven.apache.org/. Maven is based on the concept of a project object model (POM) in that all the artifacts produced by Maven are a result of consulting a well defined model for your project. Builds, documentation, source metrics, source cross-references and a countless number of reports are all controlled by your POM. Maven has the following features.
o Making the build process easy
o Providing a uniform build system
o Providing quality project information
o Providing clear development process guidelines
o Providing guidelines for thorough testing practices
o Providing coherent visualization of project information
o Allowing transparent migration to new features
4. What is JPay? The JPay is Java payment API. It supports payments in an open, Web-like environment and allow Java applications to use a third-party payment service to charge users for using an application or accessing content. For more information, please visit this page
5. What is Jetson?
Jetson is an automation toolset designed to simplify and speed the development and deployment of J2EE applications. Jetson enables rapid Enterprise JavaBean (EJB)-based application generation; allows business rules to be exposed as Web services; supports most common databases; and features a security model that conforms to Java Authentication and Authorization Service (JAAS). More information can be found at http://www.jetsonj2ee.com/.
6. What is Jamaica?
Jamaica (like Jasmin) is an abstract assembly language for Java Virtual Machine(JVM). It uses Java language syntax to define class structures and uses mnemonics or symbolic names in instructions for variables, parameters, data fields, constants, and labels. JVM bytecode is hard to read and can be viewed via javap utility to decompile a class file. For example, you may view a compiled class file as follows:
javap -c anyCompiledClassName
You will see the decompiled JVM bytecode displayed on the screen. But when you use Jamaica to write code, it is easy to read. For example, the HelloWorld class may be written as follows.
public class HelloWorld {
public static void main(String[] args) {
%println "Hello, World!"
%println "Hello, World!"
%println "This is NOT an error!"
}
}
The %println is JVM macro. It needs Jamaica to compile and run
7. What is WML?
Wireless Markup Language (WML) page is delivered over Wireless Application Protocol (WAP) and the network configuration requires a gateway to translate WAP to HTTP and back again. It can be generated by a JSP page or servlet running on the J2EE server.
8. What software development methodologies are prevailing?
o Rational Unified Process(RUP) -- Model-driven architecture, design and development; customizable framework for scalable processes; developed and marketed by Rational company.
o Enterprise Unified Process(EUP) -- extension of RUP(add: production, retirement, operations,support and enterprise disciplines.)
o Personal Software Process(PSP) -- Self-calibration.
o Team Software Process(TSP) -- Extends PSP with specific roles.
o Agile Modeling (AM)-- Feature-driven, test often.
o Extreme Programming(XP) -- Effective pair-programming.
o Reuse -- Across multiple providers.
 Architecture-driven reuse -- domain component
 Artifact reuse -- use cases, standards docu, models, procesures, guidelines,etc.
 Code reuse -- source code, across multiple applications, etc.
 Component reuse -- fully-encapsulated, well tested components.
 Framework reuse -- collections of classes with basic funtionality of a common tech or business domain.
 Inheritance reuse -- taking advantagle of behavior implemented in existing classes.
 Pattern reuse -- publicly documented approaches to solve common problems.
 Template reuse -- common set of layouts for key development artifacts.
o Note: They are all iterative development methodologies.
9. What are orthogonal dimensions in software development?
There are several popular orthogonal dimensions listed as follows
o Top-down vs. bottom-up.
o Waterfall vs. incremental.
o Iterative vs. concurrent.
o Planned vs. mining.
o Same team vs. different team.
10. What is domain engineering(DE)?
Domain engineering(DE) is a process that produces reusable assets including components, web services, generators, frameworks, models and documents, for subsequent use in the development of applications or product line.
11. What is domain analysis(DA)?
Domain analysis(DA) is the front part of domain engineering(DE), which analyzes the anticipated applications, technology trends, standards,and existing assets to develop a model of commonality, variability and initial features into reusable assets.
12. What are alpha, beta or gamma version of a software?
o alpha -- the release contains some large section of new code that hasn't been 100% tested.
o beta -- all new code has been tested, no fatal bugs.
o gamma -- a beta that has been around a while and seems to work fine. Only minor fixes are added. The so-called a release.
13. What is the difference between component and class?
A component is a finished class, whereas a class is a design schema. A component is ready to be used as a member of a class and a class may consist of many components(classes). Component and class names may be exchangeble in context. For example, a Button is a component and also a class. MyWindow class may contain several buttons.
14. What is JUnit?
JUnit is a unit-testing framework (originally written by Erich Gamma and Kent Beck). Unit-testing is a means of verifying the results you expect from your classes. If you write your test beforehand and focus your code on passing the test you are more likely to end up with simple code that does what it should and nothing more. Unit-testing also assists in the refactoring process. If your code passes the unit-test after refactoring you will know that you haven't introduced any bugs to it.
JUnit test may take the following steps to write:
o import junit.framework;
o subclass of TestCase
o Override setUp()
o Write testXXX() methods
o Write suite()--public static Test suite()
o Override tearDown()
o Write a main()
o Use GUI or command line test package
o Consult http://junit.apache.org for more info.
15. What is Cactus?
Cactus is an extension of JUnit. It is used to test J2EE applications. For more info, consult http://jakarta.apache.org/cactus/getting_started.html.
16. What is the difference between Java and PL/SQL?
Java is a general programming language. PL/SQL is a database query languague, especially for Oracle database.
Return to top
________________________________________
Donate a Job Interview Question
Anyone is allowed to donate a job interview question here. The contents you put in will be censored every three days by webmaster to ensure the quality. If you think your question is cool and don't want others to see it before censoring, please send email to javacamp. If your machine doesn't have an email client to use, please contact us via this link.
If you want to add a job interview question, please follow steps below:
1. Select a subject from the left drop down menu.
2. Enter the question.
3. Enter your answer. If you don't know how to answer, leave it blank or just type some words in.
4. Click "Add a Job Interview Question" button.
5. If you want to clear it before clicking "Add a Job Interview Question" button, click "Clear" button.
6. Your added question will be reviewed by javacamp webmaster.
If you add a job interview question to this page, your question will not be shown immediately as you did before. We alter the rules because we find that some guys abuse such function and list garbage or repeated questions. If you concern about this or really want to publish your question quickly, please feel free to contact javacamp.org

0 Comments: