Saturday 29 September 2018

Java / J2EE Technical Architect - Interview Questions and Answers


Check our new Java Interview Questions Search Tool


Q1.  Should we create system software ( e.g Operating system ) in Java ?

Ans. No, Java runs on a virtual machine called JVM and hence doesn't embed well with the underlying hardware. Though we can create a platform independent system software but that would be really slow and that's what we would never need. 

Q2.  What are the different types of memory used by JVM ?

Ans. Class , Heap , Stack , Register , Native Method Stack.

Q3.  What are the benefits of using Spring Framework ?

Ans. Spring enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product.

Spring is organized in a modular fashion. Even though the number of packages and classes are substantial, you have to worry only about ones you need and ignore the rest.

Spring does not reinvent the wheel instead, it truly makes use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE, Quartz and JDK timers, other view technologies.

Testing an application written with Spring is simple because environment-dependent code is moved into this framework. Furthermore, by using JavaBean-style POJOs, it becomes easier to use dependency injection for injecting test data.

Spring’s web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks.

Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.

Lightweight IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This is beneficial for developing and deploying applications on computers with limited memory and CPU resources.

Spring provides a consistent transaction management interface that can scale down to a local transaction

Q4.  What are various types of Class loaders used by JVM ?

Ans. Bootstrap - Loads JDK internal classes, java.* packages.

Extensions - Loads jar files from JDK extensions directory - usually lib/ext directory of the JRE

System  - Loads classes from system classpath. 

Q5.  What is PermGen or Permanent Generation ?

Ans. The memory pool containing all the reflective data of the java virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas. The Permanent generation contains metadata required by the JVM to describe the classes and methods used in the application. The permanent generation is populated by the JVM at runtime based on classes in use by the application. In addition, Java SE library classes and methods may be stored here.

Q6.  What is metaspace ?

Ans. The Permanent Generation (PermGen) space has completely been removed and is kind of replaced by a new space called Metaspace. The consequences of the PermGen removal is that obviously the PermSize and MaxPermSize JVM arguments are ignored and you will never get a java.lang.OutOfMemoryError: PermGen error.

Q7.  How does volatile affect code optimization by compiler?

Ans. Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile variables are never cached and hence their retrieval cannot be optimized.

Q8.  What things should be kept in mind while creating your own exceptions in Java?

Ans. All exceptions must be a child of Throwable.

If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.

You want to write a runtime exception, you need to extend the RuntimeException class.

Q9.  What is the best practice configuration usage for files - pom.xml or settings.xml ?

Ans. The best practice guideline between settings.xml and pom.xml is that configurations in settings.xml must be specific to the current user and that pom.xml configurations are specific to the project.

Q10.  Can you provide some implementation of a Dictionary having large number of words ? 

Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search.

Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList.

Further level up, we can have linked Hashmaps like ,

hashmap {
a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)
b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)
....................................................................................
z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)
}

upto n levels ( where n is the average size of the word in dictionary.

Q11.  What is database deadlock ? How can we avoid them?

Ans. When multiple external resources are trying to access the DB locks and runs into cyclic wait, it may makes the DB unresponsive. 

Deadlock can be avoided using variety of measures, Few listed below -

Can make a queue wherein we can verify and order the request to DB.

Less use of cursors as they lock the tables for long time.

Keeping the transaction smaller.

Q12.  Why Web services use HTTP as the communication protocol ?

Ans. With the advent of Internet, HTTP is the most preferred way of communication. Most of the clients ( web thin client , web thick clients , mobile apps )  are designed to communicate using http only. Web Services using http makes them accessible from vast variety of client applications. 

Q13.  Why using cookie to store session info is a better idea than just using session info in the request ?

Ans. Session info in the request can be intercepted and hence a vulnerability. Cookie can be read and write  by respective domain only and make sure that right session information is being passed by the client.

Q14.  Difference between first level and second level cache in hibernate ?

Ans. 1. First level cache is enabled by default whereas Second level cache needs to be enabled explicitly.

2. First level Cache came with Hibernate 1.0 whereas Second level cache came with Hibernate 3.0.

3. First level Cache is Session specific whereas Second level cache is shared by sessions that is why First level cache is considered local and second level cache is considered global.

Q15.  What are the ways to avoid LazyInitializationException ?

Ans. 1. Set lazy=false in the hibernate config file.

2. Set @Basic(fetch=FetchType.EAGER) at the mapping.

3. Make sure that we are accessing the dependent objects before closing the session.

4. Using Fetch Join in HQL.

Q16.  What are new features introduced with Java 8 ?

Ans. Lambda Expressions , Interface Default and Static Methods , Method Reference , Parameters Name , Optional , Streams, Concurrency.

Q17.  What things you would care about to improve the performance of Application if its identified that its DB communication that needs to be improved ?

Ans. 1. Query Optimization ( Query Rewriting , Prepared Statements )
2. Restructuring Indexes.
3. DB Caching Tuning ( if using ORM )
4. Identifying the problems ( if any ) with the ORM Strategy ( If using ORM )

Q18.  If you are given a choice to implement the code to either Insert a Record or Update if already exist, Which approach will you follow ?

1. Insert into the DB Table. If exception occurs, update the existing record.
2. Check if the record exists and update it if it exists, If not insert a new record.

Ans. In first case, there would be 2 DB calls in worst case and 1 in best case. In 2nd approach there will be always 2 DB calls.

Decision on the approach should depend on the following considerations -

1. How costly is the call to DB ? Are we using indices , hibernate etc

If calls to DB are costly , 1st approach should be the choice.

2. Exception Book keeping load upon exception.

The benefit of saving 1st call in approach 1 should be bigger than the Book keeping for the exception.

3. Probability of the exception in first apparoach.  

If the DB Table is almost empty, it makes sense to follow Approach 1 as majority of the 1st calls will pass through without exception.

Q19.  What would you do if you have to add a jar to the project using Maven ?

Ans. If its already there in Maven local repository, We can add that as a dependency in the project pom file with its Group Id, Artifact Id and version.

We can provide additional attribute SystemPath if its unable to locate the jar in the local repository.

If its not there in the local repository, we can install it first in the local repository and then can add it as dependency.

Q20.  Should we create system software ( e.g Operating system ) in Java ?

Ans. No, Java runs on a virtual machine called JVM and hence doesn't embed well with the underlying hardware. Though we can create a platform independent system software but that would be really slow and that's what we would never need. 

Q21.  Which UML diagrams you usually use for design ?

Ans. Use Case Diagram, Component Diagram for High level Design and Class Diagram , Sequence Diagram for low level design.

Q22.  How do you coordinate and communicate with the team developers ?

Ans. We as a team of developers , testers , analyst , lead and architect sit close to each other. Most of the time I would just jump to their seat and talk to them ( if required ). We have daily stand up where we discuss things that needs team attention. 

Q23.  What kind of software architecture your organization follow ?

Ans. We have multi tier architecture with multiple layers , We have series of web servers and applications in application tier, infrastructure libraries at middle tier and Database servers at the lower tier. We are using Oracle as Database, ESB ( Enterprise service Bus ) for asynchronous communication and Rest Web Services.

Q24.  Difference between Proxy and Adapter Deisgn Patterns ?

Ans. Adapter object has a different input than the real subject whereas Proxy object has the same input as the real subject. Proxy object is such that it should be placed as it is in place of the real subject.

Q25.  Difference between Adapter and Facade ?

Ans. The Difference between these patterns in only the intent. Adapter is used because the objects in current form cannot communicate where as in Facade , though the objects can communicate , A Facade object is placed between the client and subject to simplify the interface.

Q26.  Difference between Builder and Composite ?

Ans. Builder is a creational Design Pattern whereas Composite is a structural design pattern. Composite creates Parent - Child relations between your objects while Builder is used to create group of objects of predefined types.

Q27.  Difference between Factory and Strategy Design Pattern ?

Ans. Factory is a creational design pattern whereas Strategy is behavioral design pattern. Factory revolves around the creation of object at runtime whereas Strategy or Policy revolves around the decision at runtime.

Q28.  Shall we use abstract classes or Interfaces in Policy / Strategy Design Pattern ?

Ans. Strategy deals only with decision making at runtime so Interfaces should be used.

Saturday 15 September 2018

Top 50 XML Interview Questions & Answers

Download PDF Download PDF


1. What is a markup language?
Markup languages are designed for presentation of text in different formats, and it can also be used for transporting and storing data. This markup language specifies the code for formatting, layout and style of data .This markup code is called Tag.
HTML and XML are examples of Markup Language.
2. What is XML?
XML is called Extensible Markup Language which is designed to carry or transport and store data. XML tags are not as predefined as HTML, but we can define our own user tags for simplicity. It mainly concentrates on storing of data, not on displaying of data.
3. What are the features of XML?
Main features of XML are:
• Very easy to learn and implement
• XML files are text files, and no editor is required
• Minimal and a limited number of syntax rules in XML
• It is extensible, and it specifies that structural rules of tags
4. What are the differences between HTML and XML?
Following are the differences between HTML and XML:
HTML
XML
Markup language used to display dataMarkup language used to store data
Case InsensitiveCase sensitive
Designing web pagesUsed to transport and store data
Predefined TagsCustom Tags
Does not Preserve white spacesPreserve white spaces
StaticDynamic
5. Which tag is used to find the version of XML and the syntax?
Declaring the XML version is very important for each XML document and platform needs to be specified in which it is running.
xml-svg
6. What is XML DOM Document?
XML Document object represents the whole XML document, and it is the root of a document tree. It gives access to entire XML document – Nodes and Elements, and it has its own properties.
7. What is XPath?
XPath is used to find information in an XML document and contains standard functions. XPath is the major element in XSLT, and it is w3c recommendation.
8. What is an attribute?
An attribute provides more or additional information about an element than otherwise.
Example –

Attribute name can be given to an element person.
9. Can we have empty XML tags?
Yes, we can have empty tags in XML. Empty tags are used to indicate elements that have no textual content. Empty tags can be represented as

10. What are the advantages of XML DOM Document?
Advantages of XML DOM:
• XML structure is traversable, and it can be randomly accessed by traversing the tree.
• XML structure is modifiable, and values can be added, changed and removed
11. What are the basic rules while writing XML?
These are the basic rules while writing XML:
• All XML should have a root element
• All tags should be closed
• XML tags are case sensitive
• All tags should be nested properly
• Tag names cannot contain spaces
• Attribute value should appear within quotes
• White space is preserved
12. What is XML Element?
An XML document contains XML Elements, and it starts from an element’s start tag to end tag. It can contain:
• Other elements within main element
• An Attribute
• text
13. What is CDATA?
CDATA is unparsed character data that cannot be parsed by the XML parser. Character < and > are illegal in XML elements. CDATA section starts with <![CDATA[“ and end with “]]>”.
14. How comment can be represented in XML?
Comment can be represented as <!- – comments – -> as like HTML. This comment symbol is applicable for single or multiple lines.
15. What are XML Namespaces?
XML namespaces are used to avoid element name conflicts, and it can be avoided by using prefix before the name.
16. What is XML Parser?
XML Parser is used to convert from XML document into an XML DOM object which can be written in Javascript.
17. What is XSL?
XSL is a language used with XML for expressing style sheets as like CSS. It describes how to display an XML document for a given type.
18. Who is responsible for XML?
XML is a recommendation of the W3C – World Wide Web Consortium and the development are supervised by XML working group.
19. What is an XML Schema?
An XML schema gives the definition of an XML document, and it has following:
• Elements and attributes
• Elements that are child elements
• Order of child elements
• Data types of elements and attributes
20. What is well formed XML document?
A well-formed XML document must follow the following rules  –
• Every start tag should end with an end tag
• XML tags are case sensitive
• Empty tags are necessary to close with a forward slash
• All tags should be properly nested
21. Why XML has been used for development?
XML is used for development for following reasons:
• Used for Database driven websites
• Used to store data for e-commerce websites
• Used to transport and store data on internet
• XML is used for database and flat files
• Generate dynamic content by applying different style sheets
22. What is SGML?
SGML is large and powerful Standard Generalized markup Language which is used to define descriptions of the structure of different types of electronic document.
23.Can I execute a XML?
No, we cannot execute XML, and it is not a programming language to execute. It is just a markup language to represent the data.
24. What are the special characters used in XML?
<, > and & are the special characters used in XML. Because these characters are used for making tags.
25. What software is available for XML?
There are thousands of programs available for XML and updated list will be present in http://xml.coverpages.org.
26. Whether graphics can be used in XML? If so, How?
Yes, Graphics can be included in XML by using XLink and XPointer specifications. It supports graphic file formats like GIF, JPG, TIFF, PNG, CGM, EPS and SVG.
XLink:

27. Can I replace HTML with XML?
No, XML is not a replacement of HTML. XML provides an alternative approach to define own set of markup elements, and it is used for processing and storing data.
28. How can I include conditional statements in XML?
We cannot include conditional statement as like programming language.

This can be done by using Document Type Definition(DTD).

29. What are the benefits of XML?
Benefits of XML are
• Simple to read and understand
• XML can be done with a text editor
• Extensibility – No fixed tags
• Self – descriptive
• Can embed multiple data types
30. What are the disadvantages of XML?
Following are the disadvantages of XML:
• XML will be just a text file if elements and attributes are not defined properly.
• Overlapping markup is not permitted
31. What is DTD?

DTD is abbreviated as Document Type Definition and it is defined to build legal building blocks of an XML document. It defines the XML document structure with elements and attributes.
32. Why XSLT is important for XML?
XSLT is abbreviated as eXtensible Sytlesheet Language Transformation which is used to transform an XML document to HTML before it is displayed to the browser.
33. What are nested elements in XML?
If one or more elements are nested inside the root element is called nested element. Nesting can be easy to understand and also keeps order in an XML document.
34. What is XQuery?
XQuery was designed to query XML data which is nothing but SQL for database tables. XQuery is used to fetch the data from the XML file.
35. What is XLink and XPointer?
XLink is the standard way of creating hyperlinks in the XML files. Xpointer which allows those hyperlinks to point to more specific parts of the XML file or document.
36. Why XML editor is needed instead of Notepad?
XML editors are required to write error free XML documents, and it is used to validate against DTD or schema. Editors are able to check:
• Open and Close Tags
• XML against DTD
• XML against Schema
• Color code on XML Syntax
37. What is XML Encoding?
XML documents may contain Non-ASCII characters like French and Norwegian characters. XML Encoding is used to avoid errors and XML files have to be saved as Unicode.
38. Which XML is set to be valid XML?
When the XML file is validated against the Document Type Definition(DTD), then it is called valid XML. DTD is nothing but it defines the structure of an XML file.
39. What is Simple Element?
A simple element contain only text and following are the kinds of Simple Element:
  • No attributes
  • Doesn’t contain other elements
  • It cannot be empty
40. What is Complex Element?
A complex element contain other elements or attributes and following are kinds of Complex Elements:
  • It has empty elements
  • It contain other elements
  • It contain only text
  • It contain both other elements and text
41. Is there a way to describe XML data?
Yes, XML uses Document Type Definition (DTD) to describe the data.
42. What are the three parts of XSL?
XSL consists of three parts:
  • XSLT – Used to transform XML documents
  • XPath – Used for navigating in XML documents
  • XSL-FO – Used for formatting XML documents
43. What is the correct syntax when we define XML version?

is the correct declarative syntax used to define XML version.
44. If XML attribute name itself has double quotes, then how it can be represented?
Attribute name can be represented within single quotes if double quotes are present in the attribute name.
Example –

45. What are the types of XML Parsers?
There are two types of parsers – Non-Validating and Validating Parsers. Name itself implies Non-Validating will not validate the XML and Validating parser will validate the XML with DTD.
46. Whether root element is required for XML? If so, how many root elements are required?
Yes, root element is required, and it can have only one root element in each XML.
47. What is XML Signature?
XML Signature is recommended by W3C, and it acts as a digital signature for XML documents. If the signature is contained outside the document, it is called detached signature. If it contains inside the XML document, then it is called Enveloping signature.
48. What is Data Island?
An XML Data island is XML data embedded into a HTML page. This works only with the Internet.
49. What is DiffGram in XML?
A DiffGram is an XML format which is used to find current and original versions of XML document.
50. What is SAX?
SAX is an interface processing XML documents using events.




40 Latest Interview Questions and Answers on Spring, Spring MVC, and Spring Boot

  40 Latest Interview Questions and Answers on Spring, Spring MVC, and Spring Boot 1. What is Tight Coupling? When a class (ClassA) is depen...