Thursday, 10 November 2011

Java/J2EE interview questions: - Explanation of working thread .

One can start answering this Java/J2EE interview questions as follows: -
  • In working thread scheme, allocates one thread to execute one task.
  • When the task is complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method argument, typically execute().
  • The runnable tasks are usually stored in a queue until a thread host is available to run them.
  • The worker thread design pattern is usually used to handle many concurrent tasks where it is not important which finishes first and no single task needs to be coordinated with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.
View the following video on tiles integration with Struts 2: -



Know more on Java interview questions

Regards,

Get more on Java interview questions from author’s blog

Tuesday, 8 November 2011

Java interview questions: - Mention differences between Enumeration, ArrayList, Hashtable, Collections and Collection.

Following is the differences between Enumeration, ArrayList, Hashtable, Collections and Collection for the Java interview questions asked by the interviewer.
  • Enumeration: It is series of elements. It can be use to enumerate through the elements of a vector, keys or values of a hashtable. Used for read only operations on collections.
  •  ArrayList: It is re-sizable array implementation. Implements List interface It permits all elements, including null. It is not thread -safe.
  •  Hashtable: It maps key to value. You can use non-null value for key or value. It is part of group Map in collection.
  •  Collections: It implements Polymorphic algorithms which operate on collections.
  •  Collection: It is the root interface in the collection hierarchy.
See the following video which will show us practically Inheritance between beans and Spring: -



Visit for more  Java interview questions

Regards,

Also visit for more author’s blog on Java interview questions

Saturday, 5 November 2011

Java interview questions: - Describe JDBC and steps involved in the JDBC connection.

A widely asked  Java interview questions in most of the Java interview.

So one can start the answer as follows: -

Definition: -


JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications

Steps in the JDBC connection: -

Step 1: Register the database driver by using:
Class.forName(\" driver class for that specific database\" );

Step 2: Now create a database connection using:
Connection con = DriverManager.getConnection(url,username,password);

Step 3: Now create a query using:
Statement stmt = Connection.Statement(\"select * from TABLE NAME\");

Step 4: Execute the query:
stmt.exceuteUpdate();

Also see the following video on Java Builder Design Pattern as follows: -



Know more on  Java interview questions

Regards,


Get more on Java interview questions from author’s blog.

Wednesday, 2 November 2011

21 important Java/J2EE interview questions

This following part will cover the most asked Java/J2EE interview questions during Java/J2EE interview.

So have a look on the same and do revise it when ever you go for the Java/J2EE interview questions  interview.

Normally the Java’s interviewer starts with.....
  • What is the difference among JVM Spec, JVM Implementation, JVM Runtime?
  • What are JDK and JRE?
  • What is JIT?
  • What is a JVM heap?
  • What is sandbox?
  • What is Locale? 
  • What is a ResourceBundle class?
  • How will you get the platform dependent values like line separator, path separator? 
  • How does garbage collector decide which objects are to be removed? Can garbage collector be forced?
  • What is the final keyword denotes w.r.t class, method and variable?
  • What are the methods in Object? 
  • Can you instantiate the Math class?
  • What is the difference between the instanceof and getclass, these two are same or not?
  • Can main method be declared final? 
  • What is a native method?
  • Does Java provide any construct to find out the size of an object?
  • Is Empty .java file a valid source file?
  • Can a .java file contain more than one java classes?
  • What is the difference between an argument and a parameter?
  • What are the different scopes for Java variables? 
  • What are wrapper classes?
Also see the following video on on FlyWeight Pattern which will help you to boost your interview preparation: -




Get more study materials on Java/J2EE interview questions

Regards,

See for more author’s other blog on Java/J2EE interview questions


Saturday, 29 October 2011

Java/J2EE interview questions: - How would you create a thread pool in Java/J2EE??

While facing Java/J2EE interview questions you may come across this question by the interviewer. So you can your start with the answer as follows.

public class ThreadPool implements ThreadPoolInt.

This class is an generic implementation of a thread pool, which takes the following input: -
  • Size of the pool to be constructed.
  • Name of the class which implements Runnable and constructs a thread pool with active threads that are waiting for activation. Once the threads have finished processing they come back and wait once again in the pool.
This thread pool engine can be locked i.e. if some internal operation is performed on the pool then it is preferable that the thread engine be locked. Locking ensures that no new threads are issued by the engine. However, the currently executing threads are allowed to continue till they come back to the passive Pool.

Interested to learn more, then view the following detailed video on Java Builder pattern which is also asked during Java/J2EE interview questions: -



Visit for more Java/J2EE interview questions series.

Regards,

Also visit author’s blog for more Java/J2EE interview questions

Monday, 24 October 2011

Java/J2EE interview questions: – Distinguish between State and Strategy pattern .

This is one of the most asked JAVA/J2EE interview questions.

So one can differentiate this design pattern and answer this as follows: -

Strategy
State
Family of algorithms is interchangeable which means that every algorithm does the same thing but in different way.States are not interchangeable.
Encapsulate each algorithm into a class.We encapsulate each state into a class in state pattern.
Descendants should prepared for most possible events.
Can only process a few events according to the state machine model.
Concrete strategies usually don’t know the others.
Usually concrete states know other concrete states.
More dynamic modeling.More static modeling.

Also see the following video on Buider Design Pattern for the preparation of JAVA/J2EE interview questions: -


Visit for Java/J2EE interview questions

Regards,

Visit for more author's other blogs on Java/J2EE interview questions


Monday, 17 October 2011

Java/J2EE interview questions: - Is using StringBuffer always yields better performance than concatenation using +?

No, String Buffer need not yield a good performance over String concatenation using "+".

The type of concatenation plays a major role in deciding performance. If the concatenation can be completely resolved at coimpile time then String concatenation using + will yield better results
On the other hand if concatenation is done at run time using StringBuffer is more advisable, since StringBuffer objects are resolved at run time

Following are the two programs one showing compile time resolution and other run time and thus showing where StringBuffer will be useful.

Compile time resolution: 


This program takes String literals and performs concatenation using + as well as StringBuffer. Since the String literals could be resolved at compile time itself, this indicates a case of compile time resolution.


Code is self explanatory with proper comments given where ever required.
On executing the above code we get following result

Result:


Concatenation using + takes 0 millisecs
Concatenation using StringBuffer takes 63 millisecs
Performance using concatenation using + better than StringBuffer concatenation.

Conclusion: Since the above case if of compile time resolution performance using + concatenation yields a better result.

Run Time resolution:


Just a small modification to compile time code shown above can give us run time case for further analysis.

We change the concatenation used above to String conResult =""; conResult = conResult +"Welcome to the World of Java" +"Performance" +"@"+"questpond";

a similar change is done in StringBuffer . code snippet after change will look like





Result :


Concatenation using + takes 47 millisecs
Concatenation using StringBuffer takes 32 millisecs
Performance using concatenation using StringBuffer better than + concatenation.



Conclusion : the above case clearly shows StringBuffer giving more performance as compared to + concatenation at run time.

Overall final conclusion: Prefer StringBuffer whenever run time resolution concatenation is involved
View the following video on J2EE Design Pattern - Service Locator: -



Get more Java/J2EE interview questions