Question Bank
Question Bank
a. Abstract class:
- Single inheritance with “extends” key word
- Could have both abstract and concrete methods. Attributes are normal as
normal classes.
- Use when we want to have common behaviors for subclasses.
b. Interface:
- Support for multiple inheritance.
- Have only abstract methods
- Provide the contract.
14. What equals() and hashCode() method respond for?
- Equals() method:
o Compare logically two objects.
- hashCode():
o An integer number associcated with the objects using for storing
and retriving in demands.
- Both methods are useful when we want to store objects in hash
collection or set duplicate elements.
15. How and when override them?
- Equals() method:
o Public boolean equals(Object obj){} (must pass Object type)
o Check null -> check instanceof -> compare properties.
- Hashcode():
o Public int hashCode(){}
o Based on attributes we implement an agorithm to generate
distinct numbers.
16. What is the difference between equals() and “==” ?
- equals(): Compare logically.
- “==” : Compare address.
17. What are differences between Comparator and Comparable?
- Comparable:
o Override compareTo(Object obj)
- Comparator:
o Act as the third party
o Override compare(Object obj1, Object obj2)
18. Comparable interface? When to use them?"
- Comparable: implement to compare an object itself with another.
- Use:
38. What meaning of String immutable? Can you explain the concept?"
- When modifying a String, a new String object is created in memory,
stored in the String pool and the instance refers to the new object.
39. Describe the basic steps to reverse a string?
-Non-heap:
o ‘method area’
- Stack memory:
o Allocate automatic variable in function
63. How could you solve the memory leak?
- Use good Java best practices
- Consider static resources, set empty collections...
- Minimize the variable scopes
- Use tools to check before release applications
64. What will you do if your program has 500 Internal Server Error or
OutOfMemoryException?
- 500 error:
o Check log file
o Reprocedure and debug
- OutOfMemory:
o Check log file
o Use tool to check memory leak
65. What’s version of Java do you use? What are the notable characteristics of that
version?
- Java 6
- Some features:
o JAXB
o Common annotations
o …
XML
66. What is XML?
- Extensible Markup Language.
- Describe data.
- Various programming languages support.
- Checkable by XSD
- Human readable in tags
67. How to validate the XML file?
- Use XSD
68. What is XSD?
- XML itself
- Validate structure of XML file
- Not mandatory
-
ApplicationContext Derives from BeanFactory
-
Has all functionality of BeanFactory + support:
o Internationalization messsages
o Many enterprise service(EJB, JNDI…)
o Access to resource (URL + file)
o Application life-cycle events
o Publish events to bean registered as listenter
o Loading mutiple context
101. "How many types of bean scopes supported by Spring? And explain them."
- 5 types:
o Singleton: default scope of Spring, 1 object instance per Spring
container
o Prototype: new object is created + returned whenever you get the
bean
o Request: new object for each HTTP request
o Session: new session is created -> new instance object of bean
o Global session: same as HTTP session scope, applicable in
portlet-based web app
JAVA DESIGN PATTERN
102. "What kind of design pattern that you know?"
- Singleton
- Factory + Abstract Factory
- Service Locator
- Façade
- Observer
- Builder
103. "What is façade pattern, factory pattern, singleton pattern? When you use
them?"
- Façade:
o unified interface to a set of interface in as subsytem
o hide complex system
- Factory:
o Create object without exposing instantiation logic to client
o Refer newly created object through a common interface
- Singleton:
DATABASE
HIBERNATE
137. How do you decide when you should you session, entity or message-driven
bean?
- Entity Bean:
o Are data objects
o Represent persistent data
o Responsible for DB CRUD.
- Session Bean:
o Only implement business logic and work flow.
- Message-driven beans:
o Receiving asynchronous messages from other systems.
138. Can you compare Stateless and stateful session bean?
- Stateful Session Bean:
o Are retained during working session.
o Lifecycle (postConstruct and preDestroy)
- Stateless Session Bean:
o Are not retained for each client request
o Container can assign the same bean for different clients.
o Lifecycle (postConstruct, preDestroy, prePassive, postActivate).
LINUX