Sunday, May 20, 2018

Define Jar,War,Ear file Interview Questions

Leave a Comment

What is Jar,War and Ear in Java

What is EAR file

Enterprise Archive file. A JAR archive that contains a J2EE application.

What is JAR file

Java Archive file it contains a J2EE application.

You can create a JAR file using the command

jar cf XYZ.jar *.class *.gif

if will compress all the .class files and the related gif files to the one file called jar

You can extract the JAR file using the command

jar xf XYZ.jar

Updating the existing JAR file

jar -uf XYZ.jar file1.class

What is WAR file

Enterprise Archive file. A JAR archive that contains a J2EE application.

You can create a WAR file using the command

jar -cfv XYZ.war
You can extract a WAR file using the command

jar -xfv XYZ.war
Read More

EJB Interview questions

Leave a Comment

EJB Interview questions

What is EJB

Enterprise JavaBeans.

What is EJB container

A container that implements the EJB component contract of the J2EE architecture. This contract specifies a run time environment for enterprise beans that includes security, concurrency, life-cycle management, transactions, deployment, naming, and other services. An EJB container is provided by an EJB or J2EE server.

What is EJB container provider

A vendor that supplies an EJB container.

What is EJB context

A vendor that supplies an EJB container. An object that allows an enterprise bean to invoke services provided by the container and to obtain the information about the caller of a client-invoked method.

What is EJB home object

An object that provides the life-cycle operations (create, remove, find) for an enterprise bean. The class for the EJB home object is generated by the container’s deployment tools. The EJB home object implements the enterprise bean’s home interface. The client references an EJB home object to perform life-cycle operations on an EJB object. The client uses JNDI to locate an EJB home object.

What is EJB JAR file

A JAR archive that contains an EJB module.

What is EJB module

A deploy able unit that consists of one or more enterprise beans and an EJB deployment descriptor.

What is EJB object

An object whose class implements the enterprise bean’s remote interface. A client never references an enterprise bean instance directly; a client always references an EJB object. The class of an EJB object is generated by a container’s deployment tools.

What is EJB server

Software that provides services to an EJB container. For example, an EJB container typically relies on a transaction manager that is part of the EJB server to perform the two-phase commit across all the participating resource managers. The J2EE architecture assumes that an EJB container is hosted by an EJB server from the same vendor, so it does not specify the contract between these two entities. An EJB server can host one or more EJB containers.

What is EJB server provider

A vendor that supplies an EJB server.

What is element

A unit of XML data, delimited by tags. An XML element can enclose other elements.

What is empty tag

A tag that does not enclose any content

What is enterprise bean

A J2EE component that implements a business task or business entity and is hosted by an EJB container; either an entity bean, a session bean, or a message-driven bean.

What is enterprise bean provider

An application developer who produces enterprise bean classes, remote and home interfaces, and deployment descriptor files, and packages them in an EJB JAR file.

What is enterprise information system

The applications that constitute an enterprise’s existing system for handling company wide information. These applications provide an information infrastructure for an enterprise. An enterprise information system offers a well-defined set of services to its clients. These services are exposed to clients as local or remote interfaces or both. Examples of enterprise information systems include enterprise resource planning systems, mainframe transaction processing systems, and legacy database

What is enterprise information system resource

An entity that provides enterprise information system-specific functionality to its clients. Examples are a record or set of records in a database system, a business object in an enterprise resource planning system, and a transaction program in a transaction processing system.

What is Enterprise JavaBeans (EJB)

A component architecture for the development and deployment of object-oriented, distributed, enterprise-level applications. Applications written using the Enterprise JavaBeans architecture are scalable, transactional, and secure.

What is Enterprise JavaBeans Query Language (EJB QL)

Defines the queries for the finder and select methods of an entity bean having container-managed
persistence. A subset of SQL92, EJB QL has extensions that allow navigation over the relationships defined in an entity bean’s abstract schema.

What is an entity

A distinct, individual item that can be included in an XML document by referencing it. Such an entity reference can name an entity as small as a character (for example, <, which references the less-than symbol or left angle bracket, <). An entity reference can also reference an entire document, an external entity, or a collection of DTD definitions.

What is entity bean

An enterprise bean that represents persistent data maintained in a database. An entity bean can manage its own persistence or can delegate this function to its container. An entity bean is identified by a primary key. If the container in which an entity bean is hosted crashes, the entity bean, its primary key, and any remote references survive the crash.

What is entity reference

A reference to an entity that is substituted for the reference when the XML document is parsed. It can reference a predefined entity such as < or reference one that is defined in the DTD. In the XML data, the reference could be to an entity that is defined in the local subset of the DTD or to an external XML file (an external entity). The DTD can also carve out a segment of DTD specifications and give it a name so that it can be reused (included) at multiple points in the DTD by defining a parameter entity.

What is error

A SAX parsing error is generally a validation error in other words, it occurs when an XML document is not valid, although it can also occur if the declaration specifies an XML version that the parser cannot handle. See also fatal error, warning.

What is Extensible Markup Language


What is external entity

An entity that exists as an external XML file, which is included in the XML document using an entity

What is external subset

That part of a DTD that is defined by references to external DTD files.

What is fatal error

A fatal error occurs in the SAX parser when a document is not well formed or otherwise cannot be processed. See also error, warning.

What is filter

An object that can transform the header or content (or both) of a request or response. Filters differ from Web components in that they usually do not themselves create responses but rather modify or adapt the requests for a resource, and modify or adapt responses from a resource. A filter should not have any dependencies on a Web resource for which it is acting as a filter so that it can be composable with more than one type of Web resource.

What is filter chain

A concatenation of XSLT transformations in which the output of one transformation becomes the input of thenext.

What is finder method

A method defined in the home interface and invoked by a client to locate an entity bean.

What is form-based authentication

An authentication mechanism in which a Web container provides an application-specific form for logging in. This form of authentication uses Base64 encoding and can expose user names and passwords unless all connections are over SSL.

What is general entity

An entity that is referenced as part of an XML document’s content, as distinct from a parameter
entity, which is referenced in the DTD. A general entity can be a parsed entity or an unparsed entity.

What is group

An authenticated set of users classified by common traits such as job title or customer profile. Groups
are also associated with a set of roles, and every user that is a member of a group inherits all the roles assigned to that group.

What is handle

An object that identifies an enterprise bean. A client can serialize the handle and then later deserialize it to obtain a reference to the enterprise bean.

What is home handle

An object that can be used to obtain a reference to the home interface. A home handle can be serialized and written to stable storage and de serialized to obtain the reference.

What is home interface

One of two interfaces for an enterprise bean. The home interface defines zero or more methods for managing an enterprise bean. The home interface of a session bean defines create and remove methods, whereas the home interface of an entity bean defines create, finder, and remove methods.
Read More

How To Delete the text box using the JavaScript Dynamically

Leave a Comment

Delete the text box using the JavaScript Dynamically 

This topic is to delete the textbox/textarea/selectbox which will be created dynamically in the application using java script.

If you need to delete the rows just u need to select that check box and go for the delete button .

You can have this code for using in your application this must be related to the button which you will use in your application the Code is:

JavaScript Code Example

function deleteRow() {
 try {
  var table = document.getElementById(myTable);
  var rowCount = table.rows.length;

  for (var i = 0; i < rowCount; i++) {
   var row = table.rows[i];
   var chkbox = row.cells[0].childNodes[0];
   if (null != chkbox && false == chkbox.checked) {

 } catch (e) {

HTML Code for Web Page

<INPUT type="button" value="Delete Row" onclick="deleteRow()" />
Read More

Core Java Interview Questions

Leave a Comment

Core Java Interview Questions

What are Checked and UnChecked Exception?

A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its sub classes.

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 sub classes. Class Error and its sub classes 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.

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.

What are different types of inner classes?

Nested top-level classes, Member classes, Local classes, Anonymous classes Nested top-level classes- If you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables.There can also be inner interfaces. All of these are of the nested top-level variety.

Member classes - Member inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.

Local classes - Local classes are like local variables, specific to a block of code. Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.

Anonymous classes - Anonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.

Are the imports checked for validity at compile time? e.g. will the code containing an import such as java.lang.ABCD compile?

Yes the imports are checked for the semantic validity at compile time. The code containing above line of import will not compile. It will throw an error saying,can not resolve symbol
symbol : class ABCD
location: package io

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.

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.

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

null unless we define it explicitly.

Can a top level class be private or protected?

No. A top level class 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.

What type of parameter passing does Java support?

In Java the arguments are always passed by value .

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

Primitive data types are passed by value.

Objects are passed by value or by reference?

Java only supports pass by value. With objects, the object reference itself is passed by value and so both the original reference and parameter copy both refer to the same object .
Read More

Java Basic Interview Questions for Beginners

Leave a Comment

Java Basic Interview Questions for Beginners

Can you help me debug my program?

If the problem you are having is not directly related to our software, we suggest that you use a Java development tool that helps you with debugging, and that you invest in some books or training to help you learn Java. There are many ways to build debugging into your program, and getting good training in Java programming is a good start to understanding how to do this.

Where can I get help learning Java?

There are a lot of books and online references to Java. A good starting place is at the JavaSoft website documentation index, which has links to white papers and the Java Tutorial. You can find books on Java at any of the major online book shopping sites.

Where do I get the JDK?

WebLogic 6.1 bundles JDK131. See our Platform support page for information about specific JDKs that we have tested and certified for use with WebLogic software.

Once you determine which version of the JDK you will be using, go to the JavaSoft website. Many platform vendors provide an optimized version of the JDK for their computers.

How do I set up my CLASSPATH?

Setting up your CLASSPATH correctly depends on what you are trying to do. The most common tasks are described below:

Starting WebLogic Server. See Setting the Classpath Option in the Starting and Stopping WebLogic Servers section of the Administration Guide. In addition, your WebLogic distribution includes shell scripts that you can use to start the server. These scripts, which are located in the domain directories under the config directory of your WebLogic Server distribution, automatically set up the CLASSPATH variable in the shell before starting the server.

Compiling Application Classes or Using WebLogic Server Utilities. See Setting the Classpath for Compiling in the Developing WebLogic Server Components section of Developing WebLogic Server Applications.

Working With WebLogic Server Code Examples. See the WebLogic Server Examples Guide located at samples/examples/examples.html in your WebLogic Server distribution.

Why won’t the examples work?

Usually problems with examples are related to your environment. Here are some troubleshooting hints:

1. If you are using a database, make sure you have run the utility utils.dbping to verify that your JDBC driver is correctly installed and configured.
2. Run the setEnv script to make sure your CLASSPATH is correctly set in the shell or DOS window in which you are running the examples. For more information, see Setting your development environment.
3. Check the instructions for the examples to make sure you have changed any user-specific variables in the code before compiling.
4. Verify that you are compiling with the -d option to direct the class files into the proper directory, as defined in the example instructions.
If the example is an applet, check the CODE and CODEBASE, and make sure WebLogic Server is running.

Where can I get help with Java error messages?

Many questions we receive at BEA are related to generic Java error messages and are not specific to WebLogic Server. Here are some links that contain helpful information about Java error messages.

Source Description

Sun’s Java Developer Connection
This forum includes Questions and Answers on a wide variety of Java topics, including error messages. Use the Search box for fast results. For example, type “classpath error” in the Search box.

Compiler Error Messages
An extensive list of compiler error messages, including the infamous NoClassDefFoundError.
Sun’s Java APIs:-
Check the Java API to see if there is an exception description for the class you are using.

Why did a client-server message generate a StackOverflowException?

If you are sending a particularly large data structure using, you may exceed the per-thread size limit for either the Java or native stack. You can increase the stack size by using the following command line options:

-ss Stacksize to increase the native stack size or
-oss Stacksize to increase the Java stack size,
where Stacksize is expressed as an integer followed by “k” or “m” for kbytes or mbytes. 

For example

$java -ss156k (native)
$java -oss600k (Java)

The default native stack size is 128k, with a minimum value of 1000 bytes. The default java stack size is 400k, with a minimum value of 1000 bytes.

Will a JIT make my Java application run faster?

A Just-In-Time compiler will make some Java applications run faster. A JIT works by storing generated machine code in memory and reusing it when possible. For example, if you execute the same operation 1000 times in a loop, a JIT will improve performance of this operation since the code will only be generated once. Applications with a lot of native methods will not see as much performance improvement as pure-Java applications.

If you use a JIT, you may want to turn off the JIT during debugging to facilitate stack tracing. If you are doing performance testing with a JIT, make sure that you execute the same test several times in the same invocation and then throw away the first result to get an idea of how long the transaction will take when your application is running in a steady state. The first time the code is executed, your test will take longer (the “code generation hit”).

Can I redistribute the JDK that is bundled with WebLogic Server?

BEA Systems has the non-exclusive right to grant a third party, such as an independent software vendor (ISV), the right to redistribute the JDK that is bundled with WebLogic Server without any modifications of any kind. The following are caveats to this general statement:

The ISV cannot remove or alter any proprietary legends or notices contained in the JDK. The ISV shall not decompile, disassemble, decrypt, extract, or otherwise reverse engineer or modify the JDK. The JDK may not be leased or assigned in whole or in part.

The ISV must enter into a signed agreement with its distributors on terms substantially similar to those contained here in this redistribution policy explanation.

The ISV requires an end user license agreement with the product within which it embeds WebLogic Server.

The embedding of the JDK in ISV products does not include maintenance and support of the JDK by the JDK Provider. BEA Systems shall be solely responsible for providing maintenance and support for its ISVs and distributors. The ISV shall be solely responsible for providing maintenance and support for the end users of its products.

If an ISV wants to ship a JDK that is different from the JDK that BEA ships with WebLogic Server, that ISV needs to get those bundling rights directly from Sun or HP. 

For example:

Assume that BEA ships WebLogic Server 6.0 with JDK 1.3 only, that BEA ships WebLogic Server 5.1 with JDK 1.1 only, and that an ISV wants to ship JDK 1.1 with WebLogic Server 6.0 in an integrated product offered by that ISV. Unless BEA, for BEA business reasons, elects to make WebLogic Server 6.0 with JDK 1.1 generally available, the ISV couldn’t ship JDK 1.1 with WebLogic Server 6.0 in an integrated product offered by that ISV under BEA’s agreement with that ISV or under BEA’s agreement with Sun. The ISV could, however, obtain its own binary distribution agreement for the JDK from Sun and under that agreement bundle JDK 1.1 with its value added software solution consisting of the ISV applications and WebLogic Server 6.0 integrated.
Read More

Java Thread Interview Questions

Leave a Comment

Java Thread Interview Questions

What are the two types of multitasking ?

a. Process-based.

b. Thread-based.

What is a Thread ?

A thread is a single sequential flow of control within a program.

What are the two ways to create a new thread?

a.Extend the Thread class and override the run() method.

b.Implement the Runnable interface and implement the run() method.

If you have ABC class that must subclass XYZ class, which option will you use to create a thread?

I will make ABC implement the Runnable interface to create a new thread, because ABC class will not be able to extend both XYZ class and Thread class.

Which package contains Thread class and Runnable Interface?

java.lang package

What is the signature of the run() method in the Thread class?

public void run()

Which methods calls the run() method?

start() method.

Which interface does the Thread class implement?

Runnable interface

What are the states of a Thread ?

Ready,Running,Waiting and Dead.

Where does the support for threading lie?

The thread support lies in java.lang.Thread, java.lang.Object and JVM.

In which class would you find the methods sleep() and yield()?

Thread class

In which class would you find the methods notify(),notifyAll() and wait()?

Object class

What will notify() method do?

notify() method moves a thread out of the waiting pool to ready state, but there is no guaranty which thread will be moved out of the pool.

Can you notify a particular thread?


What is the difference between sleep() and yield()?

When a Thread calls the sleep() method, it will return to its waiting state. When a Thread calls the yield() method, it returns to the ready state.

What is a Daemon Thread?

Daemon is a low priority thread which runs in the background.

How to make a normal thread as daemon thread?

We should call setDaemon(true) method on the thread object to make a thread as daemon thread.

What is the difference between normal thread and daemon thread?

Normal threads do mainstream activity, whereas daemon threads are used low priority work. Hence daemon threads are also stopped when there are no normal threads.

Give one good example of a daemon thread?

Garbage Collector is a low priority daemon thread.

What does the start() method of Thread do?

The thread’s start() method puts the thread in ready state and makes the thread eligible to run. start() method automatically calls the run () method.

What are the two ways that a code can be synchronized?

a. Method can be declared as synchronized.

b. A block of code be sychronised.

Can you declare a static method as synchronized?

Yes, we can declare static method as synchronized. But the calling thread should acquire lock on the class that owns the method.

Can a thread execute another objects run() method?

A thread can execute it’s own run() method or another objects run() method.

What is the default priority of a Thread?

Read More

Java Thread Interview Questions

Leave a Comment

Java Thread Interview Questions

What is threaded programming and when is it used?

Threaded programming is normally used when a program is required to do more than one task at the same time. Threading is often used in applications with graphical user interfaces; a new thread may be created to do some processor-intensive work while the main thread keeps the interface responsive to human interaction.
The Java programming language has threaded programming facilities built in, so it is relatively easy to create threaded programs. However, multi-threaded programs introduce a degree of complexity that is not justified for most simple command line applications.

Why not override Thread to make a Runnable?

There is little difference in the work required to override the Thread class compared with implementing the Runnable interface, both require the body of the run() method. However, it is much simpler to make an existing class hierarchy runnable because any class can be adapted to implement the run() method. A subclass of Thread cannot extend any other type, so application-specific code would have to be added to it rather than inherited.
Separating the Thread class from the Runnable implementation also avoids potential synchronization problems between the thread and the run() method. A separate Runnable generally gives greater flexibility in the way that runnable code is referenced and executed.

What’s the difference between a thread’s start() and run() methods?

The separate start() and run() methods in the Thread class provide two ways to create threaded programs. The start() method starts the execution of the new thread and calls the run() method. The start() method returns immediately and the new thread normally continues until the run() method returns.
The Thread class’ run() method does nothing, so sub-classes should override the method with code to execute in the second thread. If a Thread is instantiated with a Runnable argument, the thread’s run() method executes the run() method of the Runnable object in the new thread instead.

Depending on the nature of your threaded program, calling the Thread run() method directly can give the same output as calling via the start() method, but in the latter case the code is actually executed in a new thread.

Can I implement my own start() method?

The Thread start() method is not marked final, but should not be overridden. This method contains the code that creates a new executable thread and is very specialised. Your threaded application should either pass a Runnable type to a new Thread, or extend Thread and override the run() method.

What’s the difference between Thread and Runnable types?

A Java Thread controls the main path of execution in an application. When you invoke the Java Virtual Machine with the java command, it creates an implicit thread in which to execute the main method. The Thread class provides a mechanism for the first thread to start-up other threads to run in parallel with it.

The Runnable interface defines a type of class that can be run by a thread. The only method it requires is run, which makes the interface very easy to to fulfil by extending existing classes. A runnable class may have custom constructors and any number of other methods for configuration and manipulation.

How does the run() method in Runnable work?

It may help to think of the run method like the main method in standard single threaded applications. The run method is a standard entry point to run or execute a class. The run method is normally only executed in the context of an independent Thread, but is a normal method in all other respects.

What is a deadlock?

A condition that occurs when two processes are waiting for each other to complete before proceeding. The result is that both processes wait endlessly.

What are all the methods used for Inter Thread communication and what is the class in which these methods are defined?
A) a. wait(),notify() & notifyall()

b. Object class

What is the mechanisam defind in java for a code segment be used by only one Thread at a time?


What is the procedure to own the moniter by many threads?

Its not possible. A monitor can be held by only one thread at a time.

What is the unit for 500 in the statement, obj.sleep(500);?

500 is the no of milliseconds and the data type is long.

What are the values of the following thread priority constants?


What is the default thread at the time of starting a java application?

main thread

The word synchronized can be used with only a method. True/ False?

False. A block of code can also be synchronised.

What is a Monitor?

A monitor is an object which contains some synchronized code in it.

What are all the methods defined in the Runnable Interface?

only run() method is defined the Runnable interface.

How can i start a dead thread?

A dead Thread cannot be started again.

When does a Thread die?

Thread dies after completion of run() method.

What does the yield() method do?

The yield() method puts currently running thread in to ready state.

What exception does the wait() method throw?

The java.lang.Object class wait() method throws “InterruptedException”.

What does notifyAll() method do?

notifyAll() method moves all waiting threads from the waiting pool to ready state.

What does wait() method do?

wait() method releases CPU, releases objects lock, the thread enters into pool of waiting threads.
Read More