DirectoryTechnologyBlog Details for "Interview Questions in Java and Java EE"

Interview Questions in Java and Java EE

Interview Questions in Java and Java EE
Interview Questions on Core Java and Java EE
Articles: 1, 2, 3, 4

Articles

Is it must to close all my ResultSets, Statements and Connections?
2007-06-09 23:29:00
This is absolutely necessary and critical to close all the JDBC resources.When you are using JDBC API you are not only allocating resources on Java side but in a database server as well. Failure to properly close Result Sets, Stat ements (and PreparedStatements and CallableStatements) and Connect ions can cause -Exhaustion of connections that can be opened or used - No new result sets creation - No execution of any queries of any kind - DB server get very slow - Your program/database server will crash
More About: Close , Must
Differentiate TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE?
2007-06-09 22:43:00
TYPE_SCROLL_INSENSITIVE specifies that a resultset is scrollable in either direction but is insensitive to changes committed by other transactions or other statements in the same transaction. TYPE_SCROLL_SENSITIVE specifies that a resultset is scrollable in either direction and is affected by changes committed by other transactions or statements within the same transaction.This needs a small coding effort to verify this differntiation.Any volunteers? Please write in your comments to put your understanding about this concept.
More About: Rent , Sens , Sensitive , Diff
How can a cursor move in scrollable result sets?
2007-06-09 21:35:00
JDBC result sets are created with three properties: type, concurrency and holdability.The type can be one of-TYPE_FORWARD_ONLY-TYPE_SCROLL_INSENSIT IVE -TYPE_SCROLL_SENSITIVE. The concurrency can be one of-CONCUR_READ_ONLY-CONCUR_UPDATABLE.The holdability can be one of-HOLD_CURSORS_OVER_COMMIT-CLOSE_CURSORS _AT_COMMIT.JDBC allows the full cross product of these. Some database like SQL 2003 prohibits the combination {TYPE_SCROLL_INSENSITIVE, CONCUR_UPDATABLE}, but this combination is supported by some vendors, notably Oracle.The movable cursors,moving forward and backward on a resultset is one of the new features in the JDBC 2.0 API. There are also methods that let you move the cursor to a particular row and check the position of the cursor.Statement stmt = con.createStatement(Result Set.TYPE_SCROLL _SENSITIVE,ResultSet.CONCUR_READ_ONLY);Re sultSet resultSet = stmt.executeQuery("SELECT FNAME, LNAME FROM EMPLOYEE");while (resultSet.next()) { . . . // iterates forward through resultSet } ...
More About: Sets , Cursor , Move
Master List Of Java EE Questions(Release I )
2007-06-05 17:32:00
ServletsWhat is a servlet? Explain its lifecycle.What is the difference between CGI and servlets? What is a middleware and what is the functionality of Webserver?Can there be more than one instance of a servlet at one time ?Why there are no constructors in servlets?What is a Servlet Context?What is meant by Session tell me something about HttpSession? What is the difference between GenericServlet and HTTPServlet?What is the difference between doGet and doPost methods of HttpServlet class? Why do GenericServlet and HttpServlet class implement Serializable interface?How will you pass values from HTML to the servlet?Can you use System.exit in your servlet end code?If my browser does not support Cookie and my server sends a Cookie instance what will happen? Can you use System.exit in your servlet end code?What is the difference in between encodeRedirectURL and encodeURL?How do you make servlet thread-safe?How do you communicate between applet and servlet?JSPWhat is the difference betwee...
More About: Questions , Java , List , Release , Master
Master List Of Core Java Questions
2007-06-04 09:54:00
OOPSWhat is an Object? What is a Class? What is OOAD? What is Data Abstraction ? What is Data Encapsulation? What is the difference between Data Abstraction and Information Hiding? What is Inheritance and what are different types of it? Why Java uses Singly rooted hierarchy? Why does Java not support Multiple Inheritance? Why is Java not 100% pure OOP language? What is Early Binding? What is Polymorphism/Late Binding? What is method overloading? What is method overriding? How is Java different from C++? What is UML and how is it useful in designing large systems? Is UML useful for procedural programming ?What are different notations used in UML ?What is a Use case and an Actor?How to identify an Actor? What is Generalization? What is Association and how it maps into a Java class? What is Aggregation and how it maps into a Java class? What is Composition and how it maps into a Java class?What is Dependency and how it maps into a Java class?What is the purpose of State machine diagram...
More About: Questions , List , Core , Master
How can you prevent caching in JSP?
2007-06-01 17:03:00
Execute the following scriptlet at the beginning of your JSP pages  to prevent JSPs from being cached by browsers.You need both the statements to  take care of some of the older browser versions. <%response.setHeader("Cache-Contr ol","no-cache"); //HTTP 1.1response.setHeader("Pragma", "no-cache"); //HTTP 1.0response.setDateHeader ("Expires", 0); //prevents caching at the proxy server %>  If the above fails, try changing the first line to response.setHeader("Cache-Control&qu ot;,"no-store"); //HTTP 1.1
More About: Caching , Vent
How will you handle runtime exceptions in your JSPs?
2007-06-01 16:57:00
JSP runtime exceptions are handled through the implicit object named "exception". This exception object can be used in a special type of JSP page called an error page, where you display the exception's name and class, its stack trace, and an informative message for your user. In any JSP which is made eligible for catching exceptions then it must have a mention to error page in @page directive,something like:<%@ page errorPage="ErrorHand ling.jsp" %>The error page, in this case ' ErrorHandling.jsp', has 'isErrorPage' attribute in page directive which should be set to true. When a JSP page has been declared an errorPage, it is made available an object with name of "exception" of type java.lang.Throwable.
More About: Exception , Runtime , Handle
How can I show various kind of documents to a web client from JSP's and/or
2007-06-01 16:26:00
You can show MS Word, Excel or PDF or any other type of document through your JSP or servlet by using :response.setContentType("mime/type& quot;);   and in jsp directive  <%@ page contentType="mime/type" %>. In case of MS Word documents contentType is "application/msword" In case of Excel it is "application/vnd.ms-excel"In case of PDF it is "application/pdf"
More About: Show , Documents , Vario , Client
Does JSP support XML pages creation?
2007-06-01 15:51:00
The answer is Yes. There are two ways you could use XML data in a JSP page:? Convert the XML elements into server-side objects and then extract the object properties.? Invoke a transformation on the XML data. The static XML tags may be included as static template portions of the JSP page.The dynamic generation of XML tags occur through bean components or custom tags that generate XML output.The other mechanism of dynamic XML data use in JSP could be by XML transformation.This technique uses XSLT(a W3C standard for transforming an XML to XML/HTML/PDF) which could be used either for formatting data in a desired fashion or simply extracting the data from an XML.
More About: Support , Creation , Pages , Ages
Explain different constituents of JSP like comments,expressions,declaration
2007-06-01 14:29:00
JSP Comments :The JSP supports two type of comments :--Output-HiddenJSP Output Comments are those ones which can be viewed on the HTML file, while Hidden Comments are never shown.JSP Expressions :The JSP expression tag is inserts Java values directly into the output. The syntax of the Expression tag is:This kind of tag contains is evaluated, converted to a String, and inserted where the expression appears in the JSP file.JSP Declaration s:JSP declarations are used to declare variables.To add a declaration, the sequences is used to enclose declarations,and ends in semi-colon. These variables can be used within functions and expressions.It is not a good practice to declare variables in global space as such variable are shared by multiple threads and which may change it's values in an inconsistent manner.To avoid such a scenario one must make these variables as synchronized but then it hampers the performance of the JSP .Usually variables are declared within local scope of Java scriptl...
More About: Sion , Xpress
Explain the life-cycle methods of JSP
2007-06-01 13:52:00
JSP has following three life cycle methods:a) jspInit(): It is the very first method which is called by JSP container to initialize the servlet instance.All JSPs implement the javax.servlet.jsp.JspPage interface that has two methods: jspInit and jspDestroy. It is important to implement when one has to load some database driver for example.b)_jspService(): The JSP container calls the _jspservice() for each request and it passes the request and the response objects.The _jspService() method corresponds to the body of the JSP page. This method is defined automatically by the JSP container and should never be defined by the JSP page author. That is why _jspService() method can not be overridden.c) jspDestroy(): When an instance of JSP is going to be destroyed then JSP container calls this method .It is used for cleaning up Both jspInit() and jspDestroy() methods can be overridden within a JSP page.This method helps in reclaiming resources like network and database connections when a J...
More About: Life , Cycle , Methods , Method
Miscellaneous Core Java Questions With Short Answers
2007-05-29 17:43:00
-In a Java program, how can you divert program messages to the system console, but error messages, say to a file?A. The class 'System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed: Stream stream = new Stream(new FileOutputStream("error.txt")); System.setErr(stream); System.setOut(stream); -How do you know if an explicit object casting is needed? A. In order to assign a superclass object to a variable of a subclass,one needs to do explicit casting. For example: Person person; Man man; man = (Man)person;While automatic casting happens when you typecast a subclass object as parent class object. - What's the difference between the methods sleep() and wait() A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread...
More About: Questions , Answers , Core , Short
How will you differentiate the following two ways of loading a database dri
2007-05-22 22:55:00
(1)DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());(2)Cla ss.forName("oracle.jdbc.driver.OracleDriv er");In case one, to load the driver, one needs an appropriate class to load, make a driver instance and register it with the JDBC driver manager. Class.forName() will cause the class to create an instance, and call the current class loader's DriverManager.registerDriver() method to announce its presence.While DriverManager.registerDriver registers an instance of the with driver manager.
More About: Database , Load , Taba , Rent , Base
Questions on Java Database Connectivity
2007-05-02 15:21:00
What is JDBC ? What are four drivers available in JDBC? How do you establish database connection using JDBC?What are the different types of Statements? What is PreparedStatement and how is different from Statement? What is the difference between executeQuery () and execute() ?What is the difference between executeQuery () and executeUpdate()? How do you call a stored procedure in Java ? What are new features from JDBC2.0 onwards?How can a cursor move in scrollable result sets?(new)Differentiate TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE?(new) How will you differentiate the following two ways of loading a database driver?(new)
More About: Questions , Database , Taba , Connect
Interview Questions on JSP
2007-04-19 11:12:00
Hers is a list of questions on JSP(All answers open in new tab/window) :What is the difference between Java Servlets and Java ServerPages (JSP)? What is the difference between page directive 'include' and 'jsp include' action command? What is the difference between 'jsp:forward' and HttpResponse.sendRedirect()? What is the difference between 'include file=".."' and 'jsp:include page = ... '?What are implicit objects in JSP? Explain the life-cycle methods of JSP Explain different constituents of JSP like comments,expressions,declarations,scriptl ets. Does JSP support XML pages creation? How can I show various kind of documents to a web client from JSP's and/or servlets? How will you handle runtime exceptions in your JSPs? How can you prevent caching in JSP?
More About: Questions , Interview
More Questions on Servlet
2007-04-19 11:11:00
How will you pass values from HTML to the servlet?Can you use System.exit in your servlet end code?If my browser does not support Cookie and my server sends a Cookie instance what will happen? Can you use System.exit in your servlet end code?What is the difference in between encodeRedirectURL and encodeURL?How do you make servlet thread-safe?How do you communicate between applet and servlet?
More About: Questions
What are Java Modifiers?
2007-04-18 13:31:00
Java classes, interfaces, and their members can be declared with one or more modifiers.They can be categorised as:Class Modi fiers :ClassModifier : one ofpublic protected privateabstract static final strictfpField Modifiers FieldModifier: one ofpublic protected privatestatic final transient volatileMethod Modifiers MethodModifier: one ofpublic protected private abstract staticfinal synchronized native strictfpConstructor Modifiers ConstructorModifier: one ofpublic protected privateThe following matrix of the all modifiers in Java shows which modifier maps to which element:-More on access specifiers..
More About: Java
Explain the usage of java.util.Date and more classes and APIs for date hand
2007-04-18 11:46:00
The class java.util.Date-Represents a point in time.-Corresponds to the number of milliseconds since the start of the Unix epoch on January 1, 1970, 00:00:00 GMT.-This class depends on System.currentTimeMillis() to obtain the current point in time,which actually returns a long value and its accuracy and precision is determined by the implementation of System and underlying OS.Apart from this class there are several other classes like GregorianCalendar,SimpleTimeZone,SimpleDa teFormat,DateFormatSymbols,java.sql.Date, java.sql.Time ,java.sql.Timestamp which are used for handling date and time related problems.In the table shown below a very brief purposes of these classes have been summarized:
More About: Java , Classes , Hand , Usage , Sage
How do you set Java library path programatically?
2007-04-18 11:10:00
Java library path can be set by choosing an option as:- -Djava.library.path=your_pathWhile setting the java.library.path property to "." instructs the Java virtual machine to search for native libraries in the current directory.And you execute your code as : java -Djava.library.path=. HelloWorldThe "-D" command-line option sets a Java platform system property. But these values are 'read only' like many of the system properties, the value in java.library.path is just FYI and changing it doesn't actually change the behaviour of the JVM.If you want to load a library from a specific location, you can use System.load() instead with the full path to the library.
More About: Library , Java , Amat , Gram , Ally
Java Servlets and JSPs
2007-04-18 11:07:00
Here I go with the list of questions on Servlets and JSPs.All answers open in a new window, so in order to get back to the list of questions, you will have to close the window(s) with answers.Have a good time while going through the answers and if you have more questions/doubts/queries in your kitty/mind and want them here, please do not hesitate to write to me.I will try to answer those questions to the best of my knowledge and list them here.Check out e-books and other resources available on web, on Java Servlets and JSPs for detailed study.What is a servlet? Explain its lifecycle.What is the difference between CGI and servlets? What is a middleware and what is the functionality of Webserver?Can there be more than one instance of a servlet at one time ?Why there are no constructors in servlets?What is a Servlet Context?What is meant by Session tell me something about HttpSession? What is the difference between GenericServlet and HTTPServlet?What is the difference between doGet and...
Session Tracking In Servlets
2007-04-17 21:28:00
As HTTP is a stateless protocol, any interaction between client browser and servlet lasts as long as the browser is connected to server and the moment browser is closed this session is lost,in no way server will know anything about its client,if client access this server again.In applications where keeping a track of end user is must like in an online shopping or online banking applications,keeping a track of session between user and server is a must.In servlets, various mechanisms are suggested for maintaining session between both entities.One of them is through cookies.Cookies are server sent,small bits of text files which are stored in client browser and this is dependent upon whether client browser supports cookies or not.By default these cookies are deleted the moment client-server communication ends but they can persist for a specified period of time by a developer.When the browser access the same site again then already stored cookie in browser is exchanged with server.Here i...
More About: Servlets , Sion , Tracking , Trac
What are implicit objects in JSP?
2007-04-17 21:27:00
The objects which are created by web container and are available in a JSP page for various information extractions from there objects.The different implicit objects in JSPs are(click on image to enlarge):
More About: Objects
What is the difference between ' include file = ' and 'jsp:include page = .
2007-04-17 21:26:00
: The content of included file is textually embedded in the page that has directive.It occurs at compile time. If included file changes, the changed content will not be included in the output. This approach is used in template creations where code from one jsp file is included in multiple jsp files.jsp:include page="..">: It is like a function call from one jsp to another jsp. The inclusion of one jsp content to another happens at execution time. This approach is handy for web application modularization.If included file changes then the new contents will be included in the output.
More About: File , Page , Difference , Ferenc , The D
What is the difference between 'jsp:forward' and HttpResponse.sendRedirect(
2007-04-17 21:25:00
is processed at the server end for forwarding a client request to a specified URL while HttpResponse.sendRedirect () method is used at the client end for request redirection.
More About: Ward , Difference , Ferenc , The D
What is the difference between page directive 'include' and 'jsp: include'
2007-04-17 21:22:00
JSP directive is interpreted at the compile time and text is merged before JSP being converted into servlet.While in case of is interpreted at the runtime where text is merged with JSP at runtime, may be a servlet or a JSP is included at runtime.
More About: Page , Difference , Ferenc , The D , Ween
What is the difference between Java Servlets and Java ServerPages (JSP)?
2007-04-17 21:22:00
A JSP is a Servlet with a Web page flavor.There are more similarities than differences between the two.JSP uses its own tags which are ultimately using tag libraries implemented in Java .The source code of a servlet  with HTML embedded in out. print (...) statements, gives dynamic features to webpages but that makes a cumbersome process to maintain servelts from web design perspective.If someone has implemented GUI related code inside servlet then each time a small GUI change will result in recompilation of the whole code.Hence business logic centric development should be done inside servlet and JSP gives a choice of combining both in much targeted way.JSP was devised to differentiate the tasks of web designers,responsible for look and feel of the webpages, from web developers who deal in business logic development.So both entities have focused interest met through JSP.In fact, a JSP gets compiled into a servlet.
More About: Servlets , Pages , Difference , Ferenc
More on Applet-Servlet Communication
2007-04-17 21:21:00
An applet-servlet/server communication can occur in following ways:Approach I:This approach reads ASCII and Binary data through applet and servlet communication.It makes sense when applet is talking to an arbitrary server-side program or reading the content of static Web pages.As Http is a request/response protocol when a connection is established, you send a request. The server processes the request,creates a response and sends it.And once you receive it,that is the end of the connection.An applet can read the content sent by the server by first creating a URLConnection derived from the URL of the server-side program and then attaching a BufferedInputStream to it.As Http is a request/response protocol when a connection is established, you send a request. The server processes the request,creates a response and sends it.And once you receive it,that is the end of the connection.This reading from server can be summarized in following steps:1.Create URL object where Applet is hosted2.Cr...
More About: Communication , Comm
How do you communicate between applet and servlet?
2007-04-17 21:20:00
The communication between an Applet and Servlet can occur through 'Http Tunneling' with Object serialization.It is technique through which an applet can send data to servlet through object serialization bypassing firewall over HTTP.A socket connection is established from client to server and in the process if there is any firewall at client side then that can also be bypassed but does not work in case if there is a firewall on remote host server side....more
More About: Communicate , Cate , Comm , Ween
How do you make servlet thread-safe?
2007-04-17 21:19:00
SingleThread Model interface once implemented makes a servlet thread safe,though not in complete sense.It ensures that servlet handles only one request at a time. In this case only one thread will be able to execute service() method at a time.Though it affects the performance of the servlet to a great extent. In STM container creates multiple instances of servlet.This interface is deprecated from Servlet API version 2.4. It does not resolve all thread safety related issues of a servlet, as most of session attributes and static variables can still be shared across multiple threads at the same time.The other ways to handle such situations can be avoid creating instance variables or synchronizing the block of code accessing those resources.
More About: Make , Safe
What is the difference in between encodeRedirectURL and encodeURL?
2007-04-17 21:18:00
encodeURL is used for all URLs in a servlet's output. It helps session ids to be encoded with the URL. Moreover it rewrites URLs relative to the current document.if the url is not starting with 'http//.' and encodes any parameters added with the request.addQueryParameter or request.addURLParameter methods.As per Servlet API the encodeRedirect URL must ALWAYS be used within response.sendRedirect() commands.It is used for encoding session ids with URL but only while redirecting.
More About: Difference , Ferenc , The D , Encoder
More articles from this author:
1, 2, 3, 4
51457 blogs in the directory.
Statistics resets every week.


Contact | About
© Blog Toplist 2008 - Supported by Web Catalog - SEO by FeWorks
eXTReMe Tracker