
Originally Posted by
naga
1.What is JSP? Describe its concept. JSP is a technology that combines HTML/XML markup languages and elements of Java programming Language to return dynamic content to the Web client, It is normally used to handle Presentation logic of a web application, although it may have business logic.
2.What are the lifecycle phases of a JSP?
JSP page looks like a HTML page but is a servlet. When presented with JSP page the JSP engine does the following 7 phases.
1.Page translation: -page is parsed, and a java file which is a servlet is created.
2.Page compilation: page is compiled into a class file
3.Page loading : This class file is loaded.
4.Create an instance :- Instance of servlet is created
5.jspInit() method is called
6._jspService is called to handle service calls
7._jspDestroy is called to destroy it when the servlet is not required.
3.What is a translation unit? JSP page can include the contents of other HTML pages or other JSP files. This is done by using the include directive. When the JSP engine is presented with such a JSP page it is converted to one servlet class and this is called a translation unit, Things to remember in a translation unit is that page directives affect the whole unit, one variable declaration cannot occur in the same unit more than once, the standard action jsp:useBean cannot declare the same bean twice in one unit.
4.How is JSP used in the MVC model? JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.
5.What are context initialization parameters? Context initialization parameters are specified by the in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP.
6.What is a output comment? A comment that is sent to the client in the viewable page source. The JSP engine handles an output comment as un-interpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser.
7.What is a Hidden Comment? A comment that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or “comment out” part of your JSP page.
8.What is a Expression? Expressions are act as place holders for language expression, expression is evaluated each time the page is accessed.
9.What is a Declaration? It declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as semicolons separate them. The declaration must be valid in the scripting language used in the JSP file.
10.What is a Scriptlet? A scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language, use any of the JSP implicit objects or any object declared with a .
11.What are the implicit objects? List them. Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. The implicit objects are:
orequest
oresponse
opageContext
osession
oapplication
oout
oconfig
opage
oexception
12.What’s the difference between forward and sendRedirect? When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container And then returns to the calling method. When a sendRedirect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward.
13.What are the different scope values for the ? The different scope values for are:
opage
orequest
osession
oapplication
14.Why are JSP pages the preferred API for creating a web-based client program? Because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.
15.Is JSP technology extensible? Yes, it is. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.
16.What is difference between custom JSP tags and beans? Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files. Custom tags and beans accomplish the same goals — encapsulating complex behavior into simple and accessible forms. There are several differences:
oCustom tags can manipulate JSP content; beans cannot.
oComplex operations can be reduced to a significantly simpler form with custom tags than with beans.
oCustom tags require quite a bit more work to set up than do beans.
oCustom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page.
oCustom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
1.What is the purpose of finalization? - The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup processing before the object is garbage collected.
2.What is the difference between the Boolean & operator and the && operator? - If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
3.How many times may an object’s finalize() method be invoked by the garbage collector? - An object’s finalize() method may only be invoked once by the garbage collector.
4.What is the purpose of the finally clause of a try-catch-finally statement? - The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.
5.What is the argument type of a program’s main() method? - A program’s main() method takes an argument of the String[] type.
6.Which Java operator is right associative? - The = operator is right associative.
7.Can a double value be cast to a byte? - Yes, a double value can be cast to a byte.
8.What is the difference between a break statement and a continue statement? - A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
9.What must a class do to implement an interface? - It must provide all of the methods in the interface and identify the interface in its implements clause.
10.What is the advantage of the event-delegation model over the earlier event-inheritance model? - The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component’s design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.
11.How are commas used in the intialization and iteration parts of a for statement? - Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.
12.What is an abstract method? - An abstract method is a method whose implementation is deferred to a subclass.
13.What value does read () return when it has reached the end of a file? - The read() method returns -1 when it has reached the end of a file.
14.Can a Byte object be cast to a double value? - No, an object cannot be cast to a primitive value.
15.What is the difference between a static and a non-static inner class? - A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
16.If a variable is declared as private, where may the variable be accessed? - A private variable may only be accessed within the class in which it is declared.
17.What is an object’s lock and which object’s have locks? - An object’s lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object’s lock. All objects and classes have locks. A class’s lock is acquired on the class’s Class object.
18.What is the % operator? - It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
19.When can an object reference be cast to an interface reference? - An object reference be cast to an interface reference when the object implements the referenced interface.
20.Which class is extended by all other classes? - The Object class is extended by all other classes.
21.Can an object be garbage collected while it is still reachable? - A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.
22.Is the ternary operator written x : y? z or x ? y : z ? - It is written x ? y : z.
23.How is rounding performed under integer division? - The fractional part of the result is truncated. This is known as rounding toward zero.
24.What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy? - The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.
25.What classes of exceptions may be caught by a catch clause? - A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.
26.If a class is declared without any access modifiers, where may the class be accessed? - A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package.
27.Does a class inherit the constructors of its superclass? - A class does not inherit constructors from any of its superclasses.
28.What is the purpose of the System class? - The purpose of the System class is to provide access to system resources.
29.Name the eight primitive Java types. - The eight primitive types are byte, char, short, int, long, float, double, and boolean.
30.Which class should you use to obtain design information about an object? - The Class class is used to obtain information about an object’s design.
1.What is garbage collection? What is the process that is responsible for doing that in java? - Reclaiming the unused memory by the invalid objects. Garbage collector is responsible for this process
2.What kind of thread is the Garbage collector thread? - It is a daemon thread.
3.What is a daemon thread? - These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly.
4.How will you invoke any external process in Java? - Runtime.getRuntime().exec(….)
5.What is the finalize method do? - Before the invalid objects get garbage collected, the JVM give the user a chance to clean up some resources before it got garbage collected.
6.What is mutable object and immutable object? - If a object value is changeable then we can call it as Mutable object. (Ex., StringBuffer, …) If you are not allowed to change the value of an object, it is immutable object. (Ex., String, Integer, Float, …)
7.What is the basic difference between string and stringbuffer object? - String is an immutable object. StringBuffer is a mutable object.
8.What is the purpose of Void class? - The Void class is an uninstantiable placeholder class to hold a reference to the Class object representing the primitive Java type void.
9.What is reflection? - Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.
10.What is the base class for Error and Exception? - Throwable
11.What is the byte range? -128 to 127
12.What is the implementation of destroy method in java.. is it native or java code? - This method is not implemented.
13.What is a package? - To group set of classes into a single unit is known as packaging. Packages provides wide namespace ability.
14.What are the approaches that you will follow for making a program very efficient? - By avoiding too much of static methods avoiding the excessive and unnecessary use of synchronized methods Selection of related classes based on the application (meaning synchronized classes for multiuser and non-synchronized classes for single user) Usage of appropriate design patterns Using cache methodologies for remote invocations Avoiding creation of variables within a loop and lot more.
15.What is a DatabaseMetaData? - Comprehensive information about the database as a whole.
16.What is Locale? - A Locale object represents a specific geographical, political, or cultural region
17.How will you load a specific locale? - Using ResourceBundle.getBundle(…);
18.What is JIT and its use? - Really, just a very fast compiler… In this incarnation, pretty much a one-pass compiler — no offline computations. So you can’t look at the whole method, rank the expressions according to which ones are re-used the most, and then generate code. In theory terms, it’s an on-line problem.
19.Is JVM a compiler or an interpreter? - Interpreter
20.When you think about optimization, what is the best way to findout the time/memory consuming process? - Using profiler
21.What is the purpose of assert keyword used in JDK1.4.x? - In order to validate certain expressions. It effectively replaces the if block and automatically throws the AssertionError on failure. This keyword should be used for the critical arguments. Meaning, without that the method does nothing.
22.How will you get the platform dependent values like line separator, path separator, etc., ? - Using Sytem.getProperty(…) (line.separator, path.separator, …)
23.What is skeleton and stub? what is the purpose of those? - Stub is a client side representation of the server, which takes care of communicating with the remote server. Skeleton is the server side representation. But that is no more in use… it is deprecated long before in JDK.
24.What is the final keyword denotes? - final keyword denotes that it is the final implementation for that method or variable or class. You can’t override that method/variable/class any more.
25.What is the significance of ListIterator? - You can iterate back and forth.
26.What is the major difference between LinkedList and ArrayList? - LinkedList are meant for sequential accessing. ArrayList are meant for random accessing.
27.What is nested class? - If all the methods of a inner class is static then it is a nested class.
28.What is inner class? - If the methods of the inner class can only be accessed via the instance of the inner class, then it is called inner class.
29.What is composition? - Holding the reference of the other class within some other class is known as composition.
30.What is aggregation? - It is a special type of composition. If you expose all the methods of a composite class and route the method call to the composite method through its reference, then it is called aggregation.
31.What are the methods in Object? - clone, equals, wait, finalize, getClass, hashCode, notify, notifyAll, toString
32.Can you instantiate the Math class? - You can’t instantiate the math class. All the methods in this class are static. And the constructor is not public.
33.What is singleton? - It is one of the design pattern. This falls in the creational pattern of the design pattern. There will be only one instance for that entire JVM. You can achieve this by having the private constructor in the class. For eg., public class Singleton { private static final Singleton s = new Singleton(); private Singleton() { } public static Singleton getInstance() { return s; } // all non static methods … }
34.What is DriverManager? - The basic service to manage set of JDBC drivers.
35.What is Class.forName() does and how it is useful? - It loads the class into the ClassLoader. It returns the Class. Using that you can get the instance ( “class-instance”.newInstance() ).