IT Community - Software Programming, Web Development and Technical Support

Java/J2EE interview Questions

This is a discussion on Java/J2EE interview Questions within the Interview Questions & Answers and Tips forums, part of the DiscussWeb IT Curriculum category; Hey guys, Let us discuss Java/J2EE interview Question... What is JVM (Java Virtual Machine)? Twist: - What are Java Byte ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > DiscussWeb IT Curriculum > Interview Questions & Answers and Tips

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-21-2007, 06:53 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Java/J2EE interview Questions

Hey guys,

Let us discuss Java/J2EE interview Question...

What is JVM (Java Virtual Machine)?

Twist: - What are Java Byte Codes?

JVM stands for Java Virtual Machine. It’s an abstract computer or virtual computer whichruns the compiled java programs. Actually JVM is a software implementation which standson the top of the real hardware platform and operating system. It provides abstractionbetween the compiled java program and the hardware and operating system.

So the compiled program does not have to worry about what hardware and operatingsystem he has to run in, it’s all handled by the JVM and thus attaining portability. All Javaprograms are compiled in to bytecodes. JVM can only understand and execute Javabytecodes. You can visualize Java bytecodes as machine language for JVM. Java compilertakes the .java files and compiles it to a “bytecode” file with .class file extension. Compilergenerates one class file for one source file.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-21-2007, 08:26 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

what is the difference between StringBuilder and StringBuffer class?

It is very much similar to StringBuffer except for one difference: it is not synchronized,which means that it is not thread-safe. The advantage of StringBuilder is good performance.In case of multithreading, you must use StringBuffer rather than StringBuilder.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-21-2007, 08:28 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

hey guys,


What are the situations you will need a constructor to be private?

Below are some of the situations when you will need a constructor to be private:-

To implement singleton pattern. That means only one instance of the object need tobe running.

When classes contain static methods. It makes sense that no object of the class needto be created.

If classes have only constants.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-21-2007, 08:30 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

hey,

Define casting? What are the different types of Casting?

Changing the type of the value from one type to other is termed as casting. For instancelook at the below code snippet in which we are trying to cast integer value to double datatype.

int i;
double d;
i = 10;
d = i; // we are trying to assign a int value to double

There are two types of casting explicit and implicit. To explicitly cast an expression prefixthe expression with type name as shown in the code snippet below.


Button mybtn = (Button) (myVector.elementAt(9));

In some situations JAVA runtime changes the type of an expression with out performinga cast. For instance in the below code snippet my inventory object is type casted andstored as type Object.

myVectorSales.add(objInventory);
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-21-2007, 08:35 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

hey guys,

Why do we use collections when we had traditional ways forcollection?

Before the collection framework JAVA provided ad hoc classes such as Dictionary, Vector,Stack and Properties to store and manipulate group of objects. Following are the mainreason why collection framework is more desirable than the traditional JAVA collectionobjects:-

√Traditional objects did not have the unifying theme. The way you access VECTORis different from Properties. Due to this ADHOC approach software is not easilyextendable and adaptable. One of the unifying themes in the new JAVA collection isthe iterator interface. It gives a unifying way for looping through JAVA collections.

√Ready made algorithms are one of the important features of the JAVA collection.Algorithms operate on collections and are defined as static methods within theCollections class. Thus, they are available for all collections. Each collection classneed not implement its own versions. The algorithms provide a standard means ofmanipulating collections.

√Implementation of dynamic arrays, linked lists, trees, and hash tables are done inefficient manner. In case of traditional JAVA collection you will need to code allthese implementation by yourself.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-29-2007, 06:16 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 544
itbarota is on a distinguished road
Default Re: Java/J2EE interview Questions

What is the difference between procedural and object-oriented programs?

a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code.
b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-29-2007, 06:18 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 544
itbarota is on a distinguished road
Default Re: Java/J2EE interview Questions

What are Encapsulation, Inheritance and Polymorphism?
*Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse
*Inheritance is the process by which one object acquires the properties of another object.
* Polymorphism is the feature that allows one interface to be used for general class actions.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-29-2007, 06:19 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 544
itbarota is on a distinguished road
Default Re: Java/J2EE interview Questions

What is the difference between Assignment and Initialization?-

Assignment can be done as many times as desired whereas initialization can be done only once.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-29-2007, 06:20 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 544
itbarota is on a distinguished road
Default Re: Java/J2EE interview Questions

What are Class, Constructor and Primitive data types?

*Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform.
*Constructor is a special kind of method that determines how an object is initialized when created.
*Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-29-2007, 06:21 AM
itbarota itbarota is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 544
itbarota is on a distinguished road
Default Re: Java/J2EE interview Questions

What is an Object and how do you allocate memory to it?
Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 09-13-2007, 12:38 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

what are include directives?
The include directive informs the JSP engine to include the content of the resource in thecurrent JSP page. Below is the syntax for include statement.
<%@ include file="Filename" %>
Below is a code snippet which shows include directive in action
<html>
<head>
<title>Directive in action</title>
</head>
<%@ include file="/companyname.html" %>
<body>
<h1>Directive in action</h1>
</body>
</html>companyname.html contains the following:
<p>Koirala and Koirala Limited</p>
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 09-13-2007, 12:39 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

How does JSP engines instantiate tag handler classes instances?

JSP engines will always instantiate a new tag handler instance every time a tag is encounteredin a JSP page. A pool of tag instances are maintained and reusing them where possible.When a tag is encountered, the JSP engine will try to find a Tag instance that is not beingused and use the same and then release
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 09-13-2007, 12:40 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

what’s the difference between JavaBeans and taglib directives?

JavaBeans and taglib fundamentals were introduced for reusability. But following are the
major differences between them:-
√Taglib are for generating presentation elements while JavaBeans are good for storing information and state.√Use custom tags to implement actions and JavaBeans to present information.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 09-13-2007, 12:42 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

what are the different scopes an object can have in a JSP page?

There are four scope which an object can have in a JSP page:-

Page Scope

Objects with page scope are accessible only within the page. Data only is valid for the current response. Once the response is sent back to the browser then data is no more valid. Even if request is passed from one page to other the data is lost.

Request Scope


Objects with request scope are accessible from pages processing the same request in which they were created. Once the container has processed the request data is invalid.Even if the request is forwarded to another page, the data is still available though not ifa redirect is required.

Session Scope

Objects with session scope are accessible in same session. Session is the time users spend using the application, which ends when they close their browser or when they go to another Web site. So, for example, when users log in, their user name could be stored in the session and displayed on every page they access. This data lasts until they leave the Web site or log out.

Application Scope

Application scope objects are basically global object and accessible to all JSP pages which lie in the same application. This creates a global object that's available to all pages.Application scope variables are typically created and populated when an application starts and then used as read-only for the rest of the application.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 09-13-2007, 12:43 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

what are different implicit objects of JSP?

pageContext :- The PageContext object.pageScope :- A Map of all the objects that have page scope.requestScope :- A Map of all the objects that have request scope.sessionScope :- A Map of all the objects that have session scope.applicationScope :- A Map of all the objects that have application scope.
param :- A Map of all the form parameters that were passed to your JSP page (for example,the HTML <input name="ourName" type="text"/> is passed to your JSP page as aform parameter).paramValues :- HTML allows for multiple values for a single form parameter. This is aMap of all the parameters, just like param, but in this object the values are an arraycontaining all of the values for a given parameter in the event that there's more than one.header :- A Map of all the request headers.headerValues :- For the same reasons as paramValues, a headerValues object is provided.cookie :- A Map of all the cookies passed to your JSP. The value returned is a Cookieobject.initParam :- A Map that maps context initialization parameter names to their parametervalues.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 09-13-2007, 12:44 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

what are different Authentication Options available in servlets?

There are four ways of authentication:-
√HTTP basic authentication
√HTTP digest authentication
√HTTPS client authentication
√Form-based authenticationLet’s try to understand how the above four ways work.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 09-13-2007, 12:46 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

Can you explain JDBCRealm?

A realm is a "database" of usernames, passwords, and user roles. When we say JDBCrealmwe mean all these attributes are stored in table. In order to connect to JDBC you need to make a context.xml and save the same in “META-INF “folder of the web application.Below is the context.xml snippet.
<Context path="/security" docBase="security" debug="0">
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99" driverName="com.mysql.jdbc.Driver"connectionURL="j dbc:mysql://localhost:3306/security?autoReconnect=true" connectionName="MyConn" connectionPassword="Password1" userTable="tblusers" userNameCol="username" userCredCol="password" userRoleTable="user_roles" roleNameCol="role_name" />
</Context>
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 09-13-2007, 12:47 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

How did you implement caching in JSP?

OSCache is an open-source caching library that's available free of charge from theOpenSymphony organization (for more details visit OSCache - OSCache). OSCache has a set of JSP tags that make it easy to implement page caching in your JSP application.Following are some Cache techniques it fulfills:-Cache entry An object that's stored into a page cache is known as a cache entry. In a JSP application,a cache entry is typically the output of a JSP page, a portion of a JSP page, or a servlet.

218Cache keyA page cache is like a hash table. When you save a cache entry in a page cache, you mustprovide a cache key to identify the cache data. You can use keys like URI, other parameterslike username, ipaddress to indentify cache data.Cache durationThis is the period of time that a cache entry will remain in a page cache before it expires.When a cache entry expires, it's removed from the cache and will be regenerated again.Cache scopeThis defines at what scope the data is stored application or session scope.<os:cache time="60"><%= new java.util.Date().toString() %></p></os:cache>The above tag says that refresh after every 60 seconds the user requests data. So if user1is requesting the page it will display fresh date and if an other user requests with in 60seconds it will show same data. If any other user requests the page after 60 second he willagain see refreshed date.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19 (permalink)  
Old 09-13-2007, 12:47 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

What is the difference between Servletcontext and ServletConfig ?

ServletConfig contains configuration data for the servlet in the form of name and valuepairs.Using the ServletConfigwe get reference to the ServletContext object. ServletContextgives the servlet access to information about its runtime environment such as web serverlogging facilities, version info, URL details, web server attributes etc.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20 (permalink)  
Old 09-13-2007, 12:48 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Thumbs up Re: Java/J2EE interview Questions

How do we prevent browser from caching output of my JSP pages?

You can prevent pages from caching JSP pages output using the below code snippet.<%response.setHeader("Cache-Control","no-cache"); //HTTP 1.1response.setHeader("Pragma","no-cache"); //HTTP 1.0response.setDateHeader ("Expires", 0); //prevents caching at the proxy server%>
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interview questions from TOP IT Companies venkat_charya Interview Questions & Answers and Tips 20 06-24-2009 09:13 PM
Asp Interview Questions sureshbb ASP and ASP.NET Programming 35 10-29-2008 07:58 PM
XML Interview Questions and Answer it.wily Interview Questions & Answers and Tips 35 11-21-2007 09:32 PM
MYSQL interview questions it.wily Interview Questions & Answers and Tips 1 09-04-2007 03:33 AM
Interview Questions shiva Interview Questions & Answers and Tips 6 08-24-2007 01:28 AM


All times are GMT -7. The time now is 03:43 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
Miami FL Divorce Lawyers      Pittsburgh Personal Injury Law      Austin TX Auto Accident Lawyer
Sedo - Buy and Sell Domain Names and Websites project info: discussweb.com Statistics for project discussweb.com etracker® web controlling instead of log file analysis

SEO by vBSEO 3.0.0