Owner: Interview Questions In Java And Java EE URL:http://interviewjava.blogspot.com/ Join Date: Fri, 08 Jun 2007 16:46:10 -0500 Rating:0 Site Description: World of tricky Core Java Q&A Covering Object Oriented Analysis and Design,JVM Internals,Java Language Fundamentals(Datatypes,Keywords,Operators and Assignments,Identifies etc.,Declarations and Modifiers,Conversion,Casting and Promotion,Flow control,Asser Site statistics:Click here
Core Java Interview Questions 2015-04-03 10:38:00 Every year many thousand technocrats choose Java careers across the globe,after formally taking Java training classes,courses and/or Java certifications like SCJP etc.While appearing for technical interviews,these budding Java programmers face variety of technical questions, are asked to write code snippets to prove their mettle in relevant topics of Java.They are not only assessed on language basics but also on their familiarity with Java development tools, optimization of Java code,load tests,securing code through Java obfuscation and more. It is their performance in these interviews which decides their career fate and is highly dependent on to-the-point and not too verbose answers.What prompted me to create a blog on frequently asked and and not so frequently asked tricky Java interview questions? The answer is,as I have been through various technical interviews on Java and related technologies for all my career spent with this fascinating technology so I thought of sharing these qu
Java EE Interview Questions 2015-04-02 05:00:00 I hope my post on Java Interview Questions will be doing some good to all my targeted audience on Core Java and in this blog, I have essentially focussed on interview questions in several Java EE technologies(erstwhile J2EE).Apart from Java EE, I will also be covering interview questions on most widely used open source technologies like Struts,Hibernate,Spring and Velocity and more.I have constantly been asked by my readers to put something on personal interview questions, consequently, you may like to read my post on personal interview questions prior talking about Java Enterprise Edition.Sun Microsystems introduced Java EE 5 specification under JSR 244 and the final release was made public on May ,2006.Java EE has become a cornerstone technology for enterprise level web based solution development.It has more than three million downloads and more than twenty six vendors' application servers support this specification.I believe,it is significant to go through an introduction of Java
Master List Of Java EE Questions(Release I ) 2007-06-05 10: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 between J Read more:Master
, Release
Master List Of Core Java Questions 2007-06-04 02: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 diagrams? Read more:Master
How can you prevent caching in JSP? 2007-06-01 10: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-Control","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","no-store"); //HTTP 1.1
How will you handle runtime exceptions in your JSPs? 2007-06-01 09: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="ErrorHandling.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.
How can I show various kind of documents to a web client from JSP's and/or servlets? 2007-06-01 09: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"); 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"
Does JSP support XML pages creation? 2007-06-01 08: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.
Explain different constituents of JSP like comments,expressions,declarations,scriptlets. 2007-06-01 07: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 Declarations: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 scriptlets Read more:different
Explain the life-cycle methods of JSP 2007-06-01 06: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 JSP
Miscellaneous Core Java Questions With Short Answers 2007-05-29 10: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 co Read more:Short
Interview Questions on JSP 2007-04-19 04: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,scriptlets. 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 Questions on Servlet 2007-04-19 04: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?
What are Java Modifiers? 2007-04-18 06:31:00 Java classes, interfaces, and their members can be declared with one or more modifiers.They can be categorised as:Class Modifiers :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..
Java Servlets and JSPs 2007-04-18 04: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 do
Session Tracking In Servlets 2007-04-17 14: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 is s Read more:Tracking
What are implicit objects in JSP? 2007-04-17 14: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):
What is the difference between ' include file = ' and 'jsp:include page = ...' 2007-04-17 14:26:00 : The content of include
d 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.: 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.
Read more:difference
What is the difference between Java Servlets and Java ServerPages (JSP)? 2007-04-17 14:22:00 A JSP is a Servlet with a Web page flavor.There are more similarities than difference
s 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 on Applet-Servlet Communication 2007-04-17 14: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.Creat
How do you communicate between applet and servlet? 2007-04-17 14: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
How do you make servlet thread-safe? 2007-04-17 14:19:00 SingleThreadModel 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.
What is the difference in between encodeRedirectURL and encodeURL? 2007-04-17 14: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 encodeRedirectURL must ALWAYS be used within response.sendRedirect() commands.It is used for encoding session ids with URL but only while redirecting.
Read more:difference
Interview Questions on Struts Framework 2007-06-10 13:45:00 What is Struts and how it helps in web development? Explain Struts1.x in a nutshell? What are the methods in Action class? How you will handle errors and exceptions in Struts? How does Validator framework work in Struts? What is DispatchAction?
What is DispatchAction? 2007-06-10 13:33:00 org.apache.struts.actions.DispatchAction is responsible for-Dispatches to a public method named on a request parameter-Method name corresponds to the 'parameter' property of corresponding ActionMapping-useful when multiple similar actions are to be clubbed within a singe Action class in order to simplify the design.If you want to to insert,update and delete all actions on a database from a JSP with the same Action class in such case it will come quite handy.Here is how this JSP looks like: <html:form action="/saveSubscription"> <html:submit> <bean:message key="insert"/> </html:submit> <html:submit> <bean:message key="update"/> </html:submit> <html:submit> <bean:message key="delete"/> </html:submit> </html:form>To configure the use of this action in your struts-config.xml file, create an entry like this:<action path="/saveSubscription" type="org.apache.struts.actions.DispatchAction"
How does Validator framework work in Struts ? 2007-06-10 12:20:00 The Validator framework
is an open source project and is part of the Jakarta Commons subproject. The Commons project was created for the purpose of providing reusable components like the Validator. Other well-known Commons components include BeanUtils, Digester, and the Logging framework.It was first released in November 2002.Validator framework consists of the following components:- -Validators -Configuration Files -Resource Bundle -JSP Custom Tags -Validator Form ClassesValidators are Java classes which execute validation rule.The framework knows how to invoke a Validator class based on its method signature, as defined in a configuration file. Typically, each Validator provides a single validation rule, and these rules can be chained together to form a more complex set of rules.Configuration Files:There are two configuration files -validator.xml and -validator-rules.xmlvalidator-rules.xml contains all possible validations available to an application. The
How you will handle errors and exceptions in Struts? 2007-06-10 10:53:00 An efficient error and exception handling makes an application behave gracefully under abnormal conditions.Struts has errors and exception handling done in different ways.The form validations using Struts require a proper mechanism.For handling errors in Struts,it has two objects ActionError and ActionErrors.Whenever a form is submitted then cotroller receives request and then create ActionForm object which calls reset() method and stores ActionForm object to required scope and then it loads ActionForm object from request and calls validate() method.If validate method fails then errors are displayed on the form itself through <html:errors> tags. Exception Handling can be done in following ways:-try-catch block within -Using declarative exception handling.In struts-config.xml we can declare on which type of exception, a request should be redirected to.Use Global Exceptions tag in struts-config.xml<global-exceptions> <exception key="errors.MyException" t
What are the methods in Action class? 2007-06-10 07:48:00 An Actionclass
in the struts application extends Struts 'org.apache.struts.action.Action" class. Action class acts as wrapper around the business logic and provides an interface to the application's Model layer. Action class mediates between the View and Model layer in both directions it means it transfers data to and fro from the view layer and the specific business process layer.If you look at the sequence diagram, it gives you a correct picture how an Action class instance is invoked.When it is invoked then overridden execute() method is invoked.It is advisable not to put the business process logic inside execute method which should ideally have navigational logic details, instead move the database and business process logic to DAO layer.Struts Sequence DiagramThe return type of the execute() method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object,mapping of which is provided in st