Java Interview Questions and Answers

Java Interview Questions and Answers -18

1.What is resource manager connection ?

An object that represents a session with a resource manager.

2.What is resource manager connection factory ?

An object used for creating a resource manager connection.

3.What is RMI ?

Remote Method Invocation. A technology that allows an object running in one Java virtual machine to invoke methods on an object running in a different Java virtual machine.

4.What is resource adapter module ?

A deployable unit that contains all Java interfaces, classes, and native libraries, implementing a resource adapter along with the resource adapter deployment descriptor.

5.What is resource manager ?

Provides access to a set of shared resources. A resource manager participates in transactions that are externally controlled and coordinated by a transaction manager. A resource manager typically is in a different address space or on a different machine from the clients that access it. Note: An enterprise information system is referred to as a resource manager when it is mentioned in the context of resource and transaction management.

6.What is role mapping ?

The process of associating the groups or principals (or both), recognized by the container with security roles specified in the deployment descriptor. Security roles must be mapped by the deployer before a component is installed in the server.

7.What is role (security) ?

An abstract logical grouping of users that is defined by the application assembler. When an application is deployed, the roles are mapped to security identities, such as principals or groups, in the operational environment. In the J2EE server authentication service, a role is an abstract name for permission to access a particular set of resources. A role can be compared to a key that can open a lock. Many people might have a copy of the key; the lock doesn't care who you are, only that you have the right key.

8.What is rollback ?

The point in a transaction when all updates to any resources involved in the transaction are revWhat is RMI-IIOP ?
A version of RMI implemented to use the CORBA IIOP protocol. RMI over IIOP provides interoperability with CORBA objects implemented in any language if all the remote interfaces are originally defined as RMI interfaces.

9.What is role (development) ?

The function performed by a party in the development and deployment phases of an application developed using J2EE technology. The roles are application component provider, application assembler, deployer, J2EE product provider, EJB container provider, EJB server provider, Web container provider, Web server provider, tool provider, and system administrator.

10.What is root ?

The outermost element in an XML document. The element that contains all other elements.

11.What is server certificate ?

Used with the HTTPS protocol to authenticate Web applications. The certificate can be self-signed or approved by a certificate authority (CA). The HTTPS service of the Sun Java System Application Server Platform Edition 8 will not run unless a server certificate has been installed.

12.What is server principal ?

The OS principal that the server is executing as.

13.What is session ?

An object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests.

14.What is session bean ?

An enterprise bean that is created by a client and that usually exists only for the duration of a single client-server session. A session bean performs operations, such as calculations or database access, for the client. Although a session bean can be transactional, it is not recoverable should a system crash occur. Session bean objects either can be stateless or can maintain conversational state across methods and transactions. If a session bean maintains state, then the EJB container manages this state if the object must be removed from memory. However, the session bean object itself must manage its own persistent data.

15.What is SGML ?

Standard Generalized Markup Language. The parent of both HTML and XML. Although HTML shares SGML's propensity for embedding presentation information in the markup, XML is a standard that allows information content to be totally separated from the mechanisms for rendering that content.

16.What is SOAP ?

Simple Object Access Protocol. A lightweight protocol intended for exchanging structured information in a decentralized, distributed environment. It defines, using XML technologies, an extensible messaging framework containing a message construct that can be exchanged over a variety of underlying protocols.

17.What is SAX ?

Abbreviation of Simple API for XML.

18.What is Simple API for XML ?

An event-driven interface in which the parser invokes one of several methods supplied by the caller when a parsing event occurs. Events include recognizing an XML tag, finding an error, encountering a reference to an external entity, or processing a DTD specification.

19.What is schema ?

A database-inspired method for specifying constraints on XML documents using an XML-based language. Schemas address deficiencies in DTDs, such as the inability to put constraints on the kinds of data that can occur in a particular field. Because schemas are founded on XML, they are hierarchical. Thus it is easier to create an unambiguous specification, and it is possible to determine the scope over which a comment is meant to apply.

20.What is Secure Socket Layer (SSL) ?

A technology that allows Web browsers and Web servers to communicate over a secured connection.

21.What is security attributes ?

A set of properties associated with a principal. Security attributes can be associated with a principal by an authentication protocol or by a J2EE product provider or both.

22.What is security constraint ?

A declarative way to annotate the intended protection of Web content. A security constraint consists of a Web resource collection, an authorization constraint, and a user data constraint.

23.What is security context ?

An object that encapsulates the shared state information regarding security between two entities.

24.What is security policy domain ?

A scope over which security policies are defined and enforced by a security administrator. A security policy domain has a collection of users (or principals), uses a well-defined authentication protocol or protocols for authenticating users (or principals), and may have groups to simplify setting of security policies.

25.What is security role ?

An abstract logical grouping of users that is defined by the application assembler. When an application is deployed, the roles are mapped to security identities, such as principals or groups, in the operational environment. In the J2EE server authentication service, a role is an abstract name for permission to access a particular set of resources. A role can be compared to a key that can open a lock. Many people might have a copy of the key; the lock doesn't care who you are, only that you have the right key.

26.What is security technology domain ?

A scope over which the same security mechanism is used to enforce a security policy. Multiple security policy domains can exist within a single technology domain.

27.What is security permission ?

A mechanism defined by J2SE, and used by the J2EE platform to express the programming restrictions imposed on application component developers.

28.What is security permission set ?

The minimum set of security permissions that a J2EE product provider must provide for the execution of each component type.

29.What is security view ?

The set of security roles defined by the application assembler.

30.What is service element ?

A representation of the combination of one or more Connector components that share a single engine component for processing incoming requests.

31.What is service endpoint interface ?

A Java interface that declares the methods that a client can invoke on a Web service.

32.What is servlet ?

A Java program that extends the functionality of a Web server, generating dynamic content and interacting with Web applications using a request-response paradigm.

33.What is servlet container ?

A container that provides the network services over which requests and responses are sent, decodes requests, and formats responses. All servlet containers must support HTTP as a protocol for requests and responses but can also support additional request-response protocols, such as HTTPS.

34.What is servlet container, distributed ?

A servlet container that can run a Web application that is tagged as distributable and that executes across multiple Java virtual machines running on the same host or on different hosts.

35.What is servlet context ?

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.

36.What is servlet mapping ?

Defines an association between a URL pattern and a servlet. The mapping is used to map requests to servlets.

37.What is tool provider ?

An organization or software vendor that provides tools used for the development, packaging, and deployment of J2EE applications.

38.What is transaction manager ?

Provides the services and management functions required to support transaction demarcation, transactional resource management, synchronization, and transaction context propagation.

39.What is Unicode ?

A standard defined by the Unicode Consortium that uses a 16-bit code page that maps digits to characters in languages around the world. Because 16 bits covers 32,768 codes, Unicode is large enough to include all the world's languages, with the exception of ideographic languages that have a different character for every concept, such as Chinese.

40.What is transaction attribute ?

A value specified in an enterprise bean's deployment descriptor that is used by the EJB container to control the transaction scope when the enterprise bean's methods are invoked. A transaction attribute can have the following values: Required, RequiresNew, Supports, NotSupported, Mandatory, or Never.

41.What is transaction ?

An atomic unit of work that modifies data. A transaction encloses one or more program statements, all of which either complete or roll back. Transactions enable multiple users to access the same data concurrently.

42.What is URI ?

Uniform resource identifier. A globally unique identifier for an abstract or physical resource. A URL is a kind of URI that specifies the retrieval protocol (http or https for Web applications) and physical location of a resource (host name and host-relative path). A URN is another type of URI.

43.What is URL ?

Uniform resource locator. A standard for writing a textual reference to an arbitrary piece of data in the World Wide Web. A URL looks like this: protocol://host/local info where protocol specifies a protocol for fetching the object (such as http or ftp), host specifies the Internet name of the targeted host, and local info is a string (often a file name) passed to the protocol handler on the remote host.

44.What is URL path ?

The part of a URL passed by an HTTP request to invoke a servlet. A URL path consists of the context path + servlet path + path info, where Context path is the path prefix associated with a servlet context of which the servlet is a part. If this context is the default context rooted at the base of the Web server's URL namespace, the path prefix will be an empty string. Otherwise, the path prefix starts with a / character but does not end with a / character. Servlet path is the path section that directly corresponds to the mapping that activated this request. This path starts with a / character. Path info is the part of the request path that is not part of the context path or the servlet path

45.What is Universal Description, Discovery and Integration (UDDI) project ?

An industry initiative to create a platform-independent, open framework for describing services, discovering businesses, and integrating business services using the Internet, as well as a registry. It is being developed by a vendor consortium.

46.What is Universal Standard Products and Services Classification (UNSPSC) ?

A schema that classifies and identifies commodities. It is used in sell-side and buy-side catalogs and as a standardized account code in analyzing expenditure.

47.What is unparsed entity ?

A general entity that contains something other than XML. By its nature, an unparsed entity contains binary data.

48.What is URN ?

Uniform resource name. A unique identifier that identifies an entity but doesn't tell where it is located. A system can use a URN to look up an entity locally before trying to find it on the Web. It also allows the Web location to change, while still allowing the entity to be found.

49.What is user data constraint ?

Indicates how data between a client and a Web container should be protected. The protection can be the prevention of tampering with the data or prevention of eavesdropping on the data

50.What is user (security) ?

An individual (or application program) identity that has been authenticated. A user can have a set of roles associated with that identity, which entitles the user to access all resources protected by those roles.

51.What is transaction isolation level ?

What is transaction isolation level The degree to which the intermediate state of the data being modified by a transaction is visible to other concurrent transactions and data being modified by other transactions is visible to it.

52.What is virtual host ?

Multiple hosts plus domain names mapped to a single IP address.

53.What is W3C ?

World Wide Web Consortium. The international body that governs Internet standards. Its Web site is

54.What is WAR file ?

Web application archive file. A JAR archive that contains a Web module.

55.What is warning ?

A SAX parser warning is generated when the document's DTD contains duplicate definitions and in similar situations that are not necessarily an error but which the document author might like to know about, because they could be. See also fatal error, error.

56.What is Web application ?

An application written for the Internet, including those built with Java technologies such as JavaServer Pages and servlets, as well as those built with non-Java technologies such as CGI and Perl.

57.What is Web container, distributed ?

A Web container that can run a Web application that is tagged as distributable and that executes across multiple Java virtual machines running on the same host or on different hosts.

58.What is Web container provider ?

A vendor that supplies a Web container.

59.What is Web application, distributable ?

A Web application that uses J2EE technology written so that it can be deployed in a Web container distributed across multiple Java virtual machines running on the same host or different hosts. The deployment descriptor for such an application uses the distributable element.

60.What is Web component ?

A component that provides services in response to requests; either a servlet or a JSP page.

61.What is Web container ?

A container that implements the Web component contract of the J2EE architecture. This contract specifies a runtime environment for Web components that includes security, concurrency, life-cycle management, transaction, deployment, and other services. A Web container provides the same services as a JSP container as well as a federated view of the J2EE platform APIs. A Web container is provided by a Web or J2EE server.

62.What is Web module ?

A deployable unit that consists of one or more Web components, other resources, and a Web application deployment descriptor contained in a hierarchy of directories and files in a standard Web application format.

63.What is Web resource ?

A static or dynamic object contained in a Web application that can be referenced by a URL.

64.What is validating parser ?

A parser that ensures that an XML document is valid in addition to being well formed. See also parser.

65.What is value-binding expression ?

A JavaServer Faces EL expression that refers to a property of a backing bean. A component tag uses this expression to bind the associated component's value or the component instance to the bean property. If the component tag refers to the property via its value attribute, then the component's value is bound to the property. If the component tag refers to the property via its binding attribute then the component itself is bound to the property.

66.What is Web resource collection ?

A list of URL patterns and HTTP methods that describe a set of Web resources to be protected.

67.What is Web server provider ?

A vendor that supplies a Web server.

68.If I do not provide any arguments on the command line, then the String array of Main method will be empty or null?

It is empty. But not null.

69.What is Web server ?

Software that provides services to access the Internet, an intranet, or an extranet. A Web server hosts Web sites, provides support for HTTP and other protocols, and executes server-side programs (such as CGI scripts or servlets) that perform certain functions. In the J2EE architecture, a Web server provides services to a Web container. For example, a Web container typically relies on a Web server to provide HTTP message handling. The J2EE architecture assumes that a Web container is hosted by a Web server from the same vendor, so it does not specify the contract between these two entities. A Web server can host one or more Web containers.

70.How can one prove that the array is not null but empty using one line of code?

Print args.length. It will print 0. That means it is empty. But if it would have been null then it would have thrown a NullPointerException on attempting to print args.length.

71.What is Web service ?

An application that exists in a distributed environment, such as the Internet. A Web service accepts a request, performs its function based on the request, and returns a response. The request and the response can be part of the same operation, or they can occur separately, in which case the consumer does not need to wait for a response. Both the request and the response usually take the form of XML, a portable data-interchange format, and are delivered over a wire protocol, such as HTTP.

72.What is XHTML ?

An XML look-alike for HTML defined by one of several XHTML DTDs. To use XHTML for everything would of course defeat the purpose of XML, because the idea of XML is to identify information content, and not just to tell how to display it. You can reference it in a DTD, which allows you to say, for example, that the text in an element can contain < em > and < b > tags rather than being limited to plain text.

73.What is XLink ?

The part of the XLL specification that is concerned with specifying links between documents.

74.What is XML registry ?

An infrastructure that enables the building, deployment, and discovery of Web services. It is a neutral third party that facilitates dynamic and loosely coupled business-to-business (B2B) interactions.

75.What is XML Schema ?

The W3C specification for defining the structure, content, and semantics of XML documents.

76.What is XPath ?

An addressing mechanism for identifying the parts of an XML document.

77.What is XPointer ?

The part of the XLL specification that is concerned with identifying sections of documents so that they can be referenced in links or included in other documents.

78.What is XSL-FO ?

A subcomponent of XSL used for describing font sizes, page layouts, and how information flows from one page to another.

79.What is component (JavaServer Faces technology) ?

A user interface control that outputs data to a client or allows a user to input data to a JavaServer Faces application.

80.What is the first argument of the String array in main method?

The String array is empty. It does not have any element. This is unlike C/C++ where the first element by default is the program name.

81.What environment variables do I need to set on my machine in order to be able to run Java programs?

CLASSPATH and PATH are the two variables.

82.Can an application have multiple classes having main method?

Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Main method only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classes having main method.

83.Can I have multiple main methods in the same class?

No the program fails to compile. The compiler says that the main method is already defined in the class.

84.What is XLL ?

The XML Link Language specification, consisting of XLink and XPointer.

85.What is XML ?

Extensible Markup Language. A markup language that allows you to define the tags (markup) needed to identify the content, data, and text in XML documents. It differs from HTML, the markup language most often used to present information on the Internet. HTML has fixed tags that deal mainly with style or presentation. An XML document must undergo a transformation into a language with style tags under the control of a style sheet before it can be presented by a browser or other presentation mechanism. Two types of style sheets used with XML are CSS and XSL. Typically, XML is transformed into HTML for presentation. Although tags can be defined as needed in the generation of an XML document, a document type definition (DTD) can be used to define the elements allowed in a particular type of document. A document can be compared by using the rules in the DTD to determine its validity and to locate particular elements in the document. A Web services application's J2EE deployment descriptors are expressed in XML with schemas defining allowed elements. Programs for processing XML documents use SAX or DOM APIs.

86.Do I need to import java.lang package any time? Why ?

No. It is by default loaded internally by the JVM.

87.Can I import same package/class twice? Will the JVM load the package twice at runtime?

One can import the same package or same class multiple times. Neither compiler nor JVM complains abt it. And the JVM will internally load the class only once no matter how many times you import the same class.

88.What is well-formed ?

An XML document that is syntactically correct. It does not have any angle brackets that are not part of tags, all tags have an ending tag or are themselves self-ending, and all tags are fully nested. Knowing that a document is well formed makes it possible to process it. However, a well-formed document may not be valid. To determine that, you need a validating parser and a DTD.

89.What is Xalan ?

An interpreting version of XSLT.

90.What are Checked and UnChecked Exception?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making an exception checked forces client programmers to deal with the possibility that the exception will be thrown. eg, IOException thrown by's read() method? Unchecked exceptions are RuntimeException and any of its subclasses. Class Error and its subclasses also are unchecked. With an unchecked exception, however, the compiler doesn't force client programmers either to catch the exception or declare it in a throws clause. In fact, client programmers may not even know that the exception could be thrown. eg, StringIndexOutOfBoundsException thrown by String's charAt() method? Checked exceptions must be caught at compile time. Runtime exceptions do not need to be. Errors often cannot be.

91.What is Overriding?

When a class defines a method using the same name, return type, and arguments as a method in its superclass, the method in the class overrides the method in the superclass. When the method is invoked for an object of the class, it is the new definition of the method that is called, and not the method definition from superclass. Methods may be overridden to be more public, not more private.

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

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

93. What is the purpose of garbage collection in Java, and when is it used?

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

94. Describe synchronization in respect to multithreading.

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchonization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors.

95.What is static in java?

Static means one per class, not one for each object no matter how many instance of a class might exist. This means that you can use them without creating an instance of a class. Static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object. A static method in a superclass can be shadowed by another static method in a subclass, as long as the original method was not declared final. However, you can't override a static method with a nonstatic method. In other words, you can't change a static method into an instance method in a subclass.

96.What is final?

A final class can't be extended ie., final class may not be subclassed. A final method can't be overridden when its class is inherited. You can't change value of a final variable (is a constant).

97.What if the main method is declared as private?

The program compiles properly but at runtime it will give "Main method not public." message.

98.What if the static modifier is removed from the signature of the main method?

Program compiles. But at runtime throws an error "NoSuchMethodError".

99.What if I write static public void instead of public static void?

Program compiles and runs properly.

100.What if I do not provide the String array as the argument to the method?

Program compiles but throws a runtime error "NoSuchMethodError".

101.Does importing a package imports the subpackages as well? e.g. Does importing com.MyTest.* also import com.MyTest.UnitTests.*?

No you will have to import the subpackages explicitly. Importing com.MyTest.* will import classes in the package MyTest only. It will not import any class in any of it's subpackage.

102.What is the difference between declaring a variable and defining a variable?

In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization.

e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.

103.What is the default value of an object reference declared as an instance variable?

null unless we define it explicitly.

104.Can a top level class be private or protected? A: No. A top level clas.s can not be private or protected. It can have either "public" or no modifier. If it

does not have a modifier it is supposed to have a default access.If a top level class is declared as private the compiler will complain that the "modifier private is not allowed here". This means that a top level class can not be private. Same is the case with protected.

105.What type of parameter passing does Java support?

In Java the arguments are always passed by value .

106.Primitive data types are passed by reference or pass by value?

Primitive data types are passed by value.

107. Explain different way of using thread?

The thread could be implemented by using runnable interface or by inheriting from the Thread class. The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.

108.What are pass by reference and passby value?

Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

Also Read:



Post a Comment