Java Interview Questions -40

Java Interview Questions -40

1.What is session tracking and how do you track a user session in servlets?

Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password. b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server. c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.

2.What is Server-Side Includes (SSI)?

Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension.

3.What are cookies and how will you use them?

Cookies are a mechanism that a servlet uses to have a client hold a small amount of state-information associated with the user. a) Create a cookie with the Cookie constructor: public Cookie(String name, String value) b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse. addCookie(Cookie cookie) c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie().
Is it possible to communicate from an applet to servlet and how many ways and how?- Yes, there are three ways to communicate from an applet to servlet and they are: a) HTTP Communication(Text-based and object-based) b) Socket Communication c) RMI Communication

4.What is connection pooling?

With servlets, opening a database connection is a major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request. The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection() method of the ConnectionPool for getting Connection object it can use; it calls returnConnection() to give the connection back to the pool.

5.Why should we go for interservlet communication?

Servlets running together in the same server communicate with each other in several ways. The three major reasons to use interservlet communication are: a) Direct servlet manipulation - allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object) b) Servlet reuse - allows the servlet to reuse the public methods of another servlet. c) Servlet collaboration - requires to communicate with each other by sharing specific information (through method invocation)

6.Is it possible to call servlet with parameters in the URL?

Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).

7.What is Inet address?

Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.

8.What is Domain Naming Service(DNS)?

It is very difficult to remember a set of numbers(IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.

9.What is URL?

URL stands for Uniform Resource Locator and it points to resource files on the Internet. URL has four components: http://www. address. com:80/index.html, where http - protocol name, address - IP address or host name, 80 - port number and index.html - file path.

10.What is RMI and steps involved in developing an RMI object?

Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application

11.What is RMI architecture?

RMI architecture consists of four layers and each layer performs specific functions: a) Application layer - contains the actual object definition. b) Proxy layer - consists of stub and skeleton. c) Remote Reference layer - gets the stream of bytes from the transport layer and sends it to the proxy layer. d) Transportation layer - responsible for handling the actual machine-to-machine communication.

12.what is UnicastRemoteObject?

All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.

13.Explain the methods, rebind() and lookup() in Naming class?

rebind() of the Naming class(found in java. rmi) is used to update the RMI registry on the server machine. Naming. rebind(”AddSever”, AddServerImpl); lookup() of the Naming class accepts one argument, the rmi URL and returns a reference to an object of type AddServerImpl.

14.what is a Java Bean?

A Java Bean is a software component that has been designed to be reusable in a variety of different environments.

15.What is a Jar file?

Jar file allows to efficiently deploying a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files. The package java. util. zip contains classes that read and write jar files.

16.What is BDK?

BDK, Bean Development Kit is a tool that enables to create, configure and connect a set of set of Beans and it can be used to test Beans without writing a code.

17.What is Servlet chaining?

Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.

18.How do servlets handle multiple simultaneous requests?

The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost() and service()) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.

19.What is the difference between TCP/IP and UDP?

TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.

20.What are JSP Directives?

A JSP directive affects the overall structure of the servlet class. It usually has the following form:<%@ directive attribute=”value” %> However, you can also combine multiple attribute settings for a single directive, as follows:<%@ directive attribute1=”value1? attribute 2=”value2? . . . attributeN =”valueN” %> There are two main types of directive: page, which lets to do things like import classes, customize the servlet superclass, and the like; and include, which lets to insert a file into the servlet class at the time the JSP file is translated into a servlet

21.What are Predefined variables or implicit objects?

To simplify code in JSP expressions and scriptlets, we can use eight automatically defined variables, sometimes called implicit objects. They are request, response, out, session, application, config, pageContext, and page.

22.What are JSP ACTIONS?

JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Available actions include: jsp:include - Include a file at the time the page is requested. jsp:useBean - Find or instantiate a JavaBean. jsp:setProperty - Set the property of a JavaBean. jsp:getProperty - Insert the property of a JavaBean into the output. jsp:forward - Forward the requester to a newpage. Jsp: plugin - Generate browser-specific code that makes an OBJECT or EMBED

23.How do you pass data (including JavaBeans) to a JSP from a servlet?

(1) Request Lifetime: Using this technique to pass beans, a request dispatcher (using either “include” or forward”) can be called. This bean will disappear after processing this request has been completed. Servlet: request. setAttribute(”theBean”, myBean); RequestDispatcher rd = getServletContext(). getRequestDispatcher(”thepage. jsp”); rd. forward(request, response); JSP PAGE:<jsp: useBean id=”theBean” scope=”request” class=”. . . . . ” />(2) Session Lifetime: Using this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it. Servlet: HttpSession session = request. getSession(true); session. putValue(”theBean”, myBean); /* You can do a request dispatcher here, or just let the bean be visible on the next request */ JSP Page:<jsp:useBean id=”theBean” scope=”session” class=”. . . ” /> 3) Application Lifetime: Using this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it. Servlet: GetServletContext(). setAttribute(”theBean”, myBean); JSP PAGE:<jsp:useBean id=”theBean” scope=”application” class=”. . . ” />

24.How can I set a cookie in JSP?

response. setHeader(”Set-Cookie”, “cookie string”); To give the response-object to a bean, write a method setResponse (HttpServletResponse response) - to the bean, and in jsp-file:<% bean. setResponse (response); %>

25.What is JSP?

JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you can’t do any client side validation with it. The advantages are: a) The JSP assists in making the HTML more functional. Servlets on the other hand allow outputting of HTML but it is a tedious process. b) It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it.

26.What are JSP scripting elements?

JSP scripting elements lets to insert Java code into the servlet that will be generated from the current JSP page. There are three forms: a) Expressions of the form <%= expression %> that are evaluated and inserted into the output, b) Scriptlets of the form<% code %>that are inserted into the servlet’s service method, and c) Declarations of the form <%! Code %>that are inserted into the body of the servlet class, outside of any existing methods.

27.If your UI seems to freeze periodically, what might be a likely reason?

A callback implementation like ActionListener.actionPerformed or MouseListener.mouseClicked is taking a long time to execute thereby blocking the event dispatch thread from processing other UI events.

28.Which Swing methods are thread-safe?

The only thread-safe methods are repaint(), revalidate(), and invalidate()

29.Why won’t the JVM terminate when I close all the application windows?

The AWT event dispatcher thread is not a daemon thread. You must explicitly call System.exit to terminate the JVM.

30.Who is loading the init() method of servlet?

Web server

31.What are the different servers available for developing and deploying Servlets?

a) Java Web Server b) JRun g) Apache Server h) Netscape Information Server i) Web Logic

32.How can I delete a cookie with JSP?

Say that I have a cookie called “foo, ” that I set a while ago & I want it to go away. I simply: <% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %>

33.How are Servlets and JSP Pages related?

JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.

34.What are the classes and interfaces for servlets?

There are two packages in servlets and they are javax. servlet and

35.How many ways can we track client and what are they?

The servlet API provides two ways to track client state and they are: a) Using Session tracking and b) Using Cookies.

36.What are the classes and interfaces for servlets?

There are two packages in servlets and they are javax. servlet and

37.What is the difference between an applet and a servlet?

a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.

38.What is the difference between doPost and doGet methods?

a) doGet() method is used to get information, while doPost() method is used for posting information. b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.

39.What is the life cycle of a servlet?

Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client’s requests through service() method. c) The server removes the servlet through destroy() method.

40.Who is loading the init() method of servlet?

Web server

41.What is the difference between an applet and a servlet?

a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.

42.What is the difference between doPost and doGet methods?

a) doGet() method is used to get information, while doPost() method is used for posting information. b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.

43.What is the life cycle of a servlet?

Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client’s requests through service() method. c) The server removes the servlet through destroy() method.

44.Can a class be it’s own event handler? Explain how to implement this.

Sure. an example could be a class that extends Jbutton and implements ActionListener. In the actionPerformed method, put the code to perform when the button is pressed.

45.Why does JComponent have add() and remove() methods but Component does not?

because JComponent is a subclass of Container, and can contain other components and jcomponents.

46.How would you create a button with rounded edges?

there’s 2 ways. The first thing is to know that a JButton’s edges are drawn by a Border. so you can override the Button’s paintComponent(Graphics) method and draw a circle or rounded rectangle (whatever), and turn off the border. Or you can create a custom border that draws a circle or rounded rectangle around any component and set the button’s border to it.

47.If I wanted to use a SolarisUI for just a JTabbedPane, and the Metal UI for everything else, how would I do that?

in the UIDefaults table, override the entry for tabbed pane and put in the SolarisUI delegate. (I don’t know it offhand, but I think it’s "com.sun.ui.motiflookandfeel.MotifTabbedPaneUI" - anything simiar is a good answer.)

48.What class is at the top of the AWT event hierarchy?

java.awt.AWTEvent. if they say java.awt.Event, they haven’t dealt with swing or AWT in a while.

49.What are the different servers available for developing and deploying Servlets?

a) Java Web Server b) JRun g) Apache Server h) Netscape Information Server i) Web Logic

50.How many ways can we track client and what are they?

The servlet API provides two ways to track client state and they are: a) Using Session tracking and b) Using Cookies.

51.Why should the implementation of any Swing callback (like a listener) execute quickly?

Because callbacks are invoked by the event dispatch thread which will be blocked processing other events for as long as your method takes to execute.

52.In what context should the value of Swing components be updated directly?

Swing components should be updated directly only in the context of callback methods invoked from the event dispatch thread. Any other context is not thread safe?

53.Why would you use SwingUtilities.invokeAndWait or SwingUtilities.invokeLater?

I want to update a Swing component but I’m not in a callback. If I want the update to happen immediately (perhaps for a progress bar component) then I’d use invokeAndWait. If I don’t care when the update occurs, I’d use invokeLater.

54.Explain how to render an HTML page using only Swing.

Use a JEditorPane or JTextPane and set it with an HTMLEditorKit, then load the text into the pane.

55.How would you detect a keypress in a JComboBox?

This is a trick. most people would say ‘add a KeyListener to the JComboBox’ - but the right answer is ‘add a KeyListener to the JComboBox’s editor component.’

57.What is the difference between the ‘Font’ and ‘FontMetrics’ class?

The Font Class is used to render ‘glyphs’ - the characters you see on the screen. FontMetrics encapsulates information about a specific font on a specific Graphics object. (width of the characters, ascent, descent)

58.What is JVM (Java Virtual Machine) ?

JVM stands for Java Virtual Machine. It’s an abstract computer or virtual computer which runs the compiled java programs. Actually JVM is a software implementation which stands on the top of the real hardware platform and operating system. It provides abstraction between the compiled java program and the hardware and operating system. So the compiled program does not have to worry about what hardware and operating system he has to run in, it’s all handled by the JVM and thus attaining portability. All Java programs are compiled in to bytecodes. JVM can only understand and execute Java bytecodes. we can visualize Java bytecodes as machine language for JVM. Java compiler takes the .java files and compiles it to a “bytecode” file with .class file extension. Compiler generates one class file for one source file.
59.What is JIT (Just-in-Time) Compilation ?

When JVM compiles the class file he does not compile the full class file in one shot. Compilation is done on function basis or file basis. Advantage gained from this is that heavy parsing of original source code is avoided. Depending on need basis the compilation is done. This typ of compilation is termed as JIT or Just-in- Time compilation.
60.How do you implement inheritance in Java?

inheritance is implemented by using “EXTEND” keyword.
61.How can we implement polymorphism in Java ?

Polymorphism is the capability of an action or method to do different things based on the object that it is acting upon. There are two types of polymorphism:-
Method Polymorphism through overloading.
62.What are packages ?

Packages group related classes and interfaces together and thus avoiding any name conflicts. From OOP’s point of view packages are useful for grouping related classes together. Classes are group together in a package using “package” keyword.
63.What is the use if “instanceof” keyword ?

“ instanceof ” keyword is used to check what is the type of object. F
64.What are Native methods in Java ?

There may be times when we want to call subroutines which are written in some other language other than Java like C++, VB6 etc.
65.Explain in depth Garbage collector ?

Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. This frees the programmer from having to keep track of when to free allocated memory, thereby preventing many potential bugs. Thus making programmers more productive as they can now put more effort in coding rather than worrying about memory management.
The only disadvantage of garbage collector is it adds overheads. Because the JVM (Java virtual machine) has to keep a constant track of the objects which are not referenced and then free these unreferenced objects on fly. This whole process has a slight impact on the application performance. But garbage collector has a good algorithm and it runs in its own thread thus having a least impact on the application performance but still it has some impact.
66.How can we force the garbage collector to run?

Garbage collector can be run forcibly using “System.gc()” or “Runtime.gc()”
67.What’s the use of JAVAP tool ?

javap disassembles compiled Java files and spits out representation of the Java program. This is a useful option when the original source code is not available.
68.What are applets ?

Applets are small applications that are accessed from web server automatically installed, and run from the browser. Once an applet arrives on the client it has limited access to resources thus ensuring security for the end user. An applet is controlled by the software that runs it. Usually, the underlying software is a browser, but it can also be applet viewer. If you run the applet source code from eclipse it runs inside an applet viewer. All applets should inherit from applet class.
Below are sequences of events which occur in applet:-
The init Method: The init method is called when the applet is first loaded. Init method can be used to initialize color, fonts or any type of one type operation needed for the applet.
The start Method: The start method is called when user visits a browser with an applet on it. In start method applet spawns a thread in which it runs the paint method.
paint() is called every time when applet has to re-display everything. paint() event can occur due to various reasons .
69.In which package is the applet class located?

Applet classes are located in " java.applet "package.
70.How can you copy one array in to a different array?

System.arraycopy(myOldArray, 0, myNewArray, 0, length);+
71.what’s the main difference between ArrayList / HashMap and Vector / Hashtable?

Vector / HashTable are synchronized which means they are thread safe. Cost of thread safe is performance degradation. So if you are sure that you are not dealing with huge number of threads then you should use ArrayList / HashMap.But yes you can still
synchronize List and Map’s using Collections provided methods :-
List OurList = Collections.synchronizedList (OurList);
Map OurMap = Collections.synchronizedMap (OurMap);
72.what is a StringBuffer class and how does it differs from String class?

StringBuffer is a peer class of String that provides almost all functionality of strings. String represents fixed-length, immutable character sequences. Comparatively StringBuffer represents mutable, growable and writeable character sequences. But StringBuffer does not create new instances as string so it’s more efficient when it comes to intensive concatenation operation.
73.What is JAVAdoc utility?

Javadoc parses comments in JAVA source files and produced HTML pages for the same. Below is the syntax for the same javadoc [ options ] [ packagenames ] [ sourcefiles ] [ @files ] Arguments can be in any order. Options Command-line options that is doctitle, windowtitle, header, bottom etc
Packagenames: -A series of names of packages, separated by spaces, such as java.lang java.lang.reflect java.awt. You must separately specify each package you want to document. Javadoc uses -sourcepath to look for these package names. Javadoc does not recursively traverse subpackages.
sourcefiles :-A series of source file names, separated by spaces, each of which can begin with a path and contain a wildcard such as asterisk (*). The path that precedes the source file name determines where javadoc will look for it. (Javadoc does not use -sourcepath to look for these source file names.)
@files: - One or more files that contain packagenames and sourcefiles in any order, one name per line.
74.How much subclasses you can maximum in Inheritance?
In one of our old JAVA projects we had an inheritance depth of five. Believe us we never liked that code. It’s bad to have a huge inheritance depth. A maintainable inheritance depth should be maximum 5. Anything above that is horrible. There is no limit as such specified anywhere that there is some limit on the inheritance sub classing . But depending on environments you will get stack over flow error.

75.What is the purpose of web client in J2EE?

The web client is very important part and it has other two parts that defines the way it functions:
Dynamic part: that gives the dynamic web pages using various markup languages like XML, HTML, etc. This is the part that is generated by using the web components that run in the web tier. The web browser is required to render the pages.
Static part: that provides static pages from the server to the client that doesn’t change according to the demands. It remains static all the time and provide the information that is like support information or about us.
The web client is known as thin client that is a very simple web based client doesn’t do any query, execution of business rules and connecting applications. It provides lightweight operations and provides the security, speed and different services to run the applications on the server.

76.How is applet different from other technologies used in J2EE?

Applets are client application that is small in size and it is included in the web tier. It provides the tools to communicate with the users and allow the drawings to be made by using the graphical interface. The applets are written in Java language. This gets executed on the virtual machine used by the Java and installed on the web browser. The plug in required by the client system for the use of security policy that executes the application in the web browser successfully. The components use API keys for creating the web client programs and run the application on the client side. As, no security is allowed the files are not required on the client system. It presents more modular approach to design the application using applets.

77.What is the purpose of the Application Clients in J2EE?

Application client runs on the client side and provide a way to the user to handle the task that is allowing the user to use the interface. The interface that is provided is graphical and tools are given for the help. The graphical user interface is created using swing and advanced window toolkit from the command line interface. These clients can use the applications directly due to the applications being handled at the business tier. The application client communicates throughout the HTTP connection using the servlet and the Java beans component architecture. The application client also includes various components to manage the overall data flow for the communication purpose between the server and the client.

78.What is the communication process of the application using the Java Beans?

JavaBeans components allow an object to be used to use the instance variables. The instance variables consist of get and set methods that are used on the server side to get the data information from the user and set it in the server. It provides lot of variations and elements can be used for the client tier. The client communicates through the business logic that is being provided by the server to run the applications. The web browser is used to communicate through the server by going through the pages that is being made and the transfer happens from the web tier. The J2EE application uses thin client or thick client that provides the lightweight and heavyweight functionality to the client and keep the load also to minimal on the server as well.

79.Explain the use of containers in J2EE?

Containers acts as an interface between a platform and a component that is at the low level and it provides the functionality that is supported by the component. Application clients get executed first and then the beans. It keeps the beans assembled at one place so that it can be used and deployed using the containers. The application consists of the components that are platform specific so the containers allow them to be bundled at one place and then used in the application just by giving the name and the path. The assembling of the beans requires the configuration settings to be seen for each component that is used inside the J2EE application or just by J2EE.

80.What are the Container settings that are being provided by the J2EE server?

J2EE server supports the customization of the server by providing the services like security, transaction management, Java naming directory and other services that can be used to provide the component based architecture. There are different types of containers that exist:
Enterprise JavaBeans (EJB) container:  This is the container that manages the execution of the beans used for J2EE applications.
Web container:  This manages the page execution and other components used by the applications.
Application client container:  This controls and manages the application level components. These are used by the client and they run on teh client side.
Applet container:  it is used to manage the applets that are executed by the web browser and uses Java plug-in.

81.What are the models provided by the J2EE?

The Interface that is used provide remote connectivity to the database and the J2EE provides:
Security model to allow the user to configure the web component to use the resource that can be accessed by the users that are permitted to use it.
Transaction model allow the user to show the relationship between the methods to allow easy transaction that is treated as the single transaction.
Lookup services, which allow easy identification of the interfaces to provide multiple naming and the directory services to the application that uses the components and access it.
Remote connectivity model allow the user to manage the communications that are made at the low level between the clients and the beans. The bean gets created by the client that produces a method for executing an application.

82.What are the tools contained in J2EE to help develop an application?

J2EE application creation requires some modules and tools that are created to deliver the archive file. The archive file is used with any archive manager but it is termed as the standard java archive file (JAR) that consists of the interfaces and components together in one. It consists of the application and deployment tools to create the EAR file and adding them in the JAR file. The tools that are used:
• Deployment descriptors are used to contain the beans and the files that are related to each using the JAR archive container.
• JAR file using the application client consists of the descriptors, class files and the application related data to be used to create an application.
• WAR file is used to collect all the data at one place and populate it accordingly.

83.What are the tasks performed by J2EE enterprise Bean developer?

Enterprise Bean Developer platform uses many services for different components and it is always required that the task has to be mentioned such as:
JAR file is an important file that consists of all the archived files and is used by the Java itself. It is used to perform the following tasks:
• The source code has to be written and compiled properly
• The deployment descriptor is used to specify the application that need to run.
• The class files that are of the extension .class file create a bundle and it is being bundled to be used as a single file. It requires the descriptor to be there in the JAR file.

84.What are the features that are provided by different components of J2EE?

J2EE provides a reference to all the components that it is using to allow an application deployment tool to be used for various purposes. The deployment tool is used to assemble, verify, and deploy the J2EE applications. These tools are used to automate the procedure of writing and compiling a code. The tools can be used using the command line or the graphical user interface. The interface is used as graphical and allows configuring different components of the J2EE as:
• J2EE applications can be chosen to configure, package and deploy those applications on the server. These provide easy integration properties and can be used to create an API.
• J2EE provides enterprise beans that allow the same operations to be used which is provided in the application part. It also provides the same functionality for the web components, application clients and the resource adaptors that provide resources to the application for execution.

85.What is the procedure to be followed to create a J2EE application?

To create the application in J2EE it requires to have predefined components that need to be used in order to successfully execute the application. The components that are used, Enterprise bean, application client and the web component. To build the component it is necessary to create an application. This file name can be given according to the requirement and this will get stored in the EAR file like file-name.ear. The procedure that is followed for this is:
1. The tool that is used is the deploy-tool. This can be done by selecting the file and then new and then application in the new.
2. The browse option can be selected to select the application that needs to be included.
4. Enter the field name and save the file with the name that is entered by the user.
5. Save and exit and a new application gets created.

86.What do you understand by the JTA and JTS in reference to j2ee?

JTA (java transaction API) The JTA is responsible for providing an interface that allows the user to segregate transactions in a way that it does not depend on the transaction manger implementation. The transaction processing monitor is responsible for coordinating the transactions across various resources. Every resource has its own manager. The JTA architecture makes it mandatory for each resource manager to implement the interface so that it can be managed by the TP monitor.
JTS (java transaction service) The JTS is used for the implementation of the transaction manager. It is responsible for providing services related to transaction to the various parties involved in distributed transactions. These can be the application server, the communication resource manager or a standalone transactional application.
The JTA can be considered to be a high level transaction interface used by an application to control a transaction whereas the JTS can be considered to be a low level api used in the background processes.

87.Why is J2EE the choice for distributed multi-tiered Applications?

J2EE is a platform that uses multi-tiered distributed application divided into components that are divided on the basis of function, applications and other components that gets installed with the platform. There are different parts that are used for this multi-tiered application:
• Client-tier components: this is the component that is used to run on the client machine.
• Web-tier components: They are executed and maintained on a j2ee server.
• Business-tier components: These are also executed and maintained on a j2ee server.
• Enterprise information system (EIS): This tire of software executes specifically on EIS servers.

88.How can user package J2EE components?

The j2ee components of an application are packaged separately and then are bundled into a j2ee application. All the related files of a component such as the html, server utility classes etc. are clubbed together along with a deployment descriptor and assembled into a module. This module can be added to a j2ee application. The deployment descriptor is made using an xml file and it defines a components deployment settings. A j2ee application comprises of one or multiple enterprise bean, web or client component modules. Every j2ee application and the modules that make it have their own deployment descriptor file. Depending upon the design requirements the final enterprise solution may consist of one or more j2ee applications

89.What are the ways in which resource file can be used in struts?

Defining message resources in struts-config file.Programmatically using resource files in Java classes or in JSP files.

90.Explain the term 'architecture of the application'?

Architecture is the set of rules (or framework) to bring in some common way of assembling or using J2EE components in the application. This helps in bringing consistency between codes developed by various developers in the team.

91.Which is the architecture followed by struts?

Struts follows MVC architecture.

92.What are components corresponding o M, V and C in struts?

Model : The model represents the data of an application. Anything that an application will persist becomes a part of model. The model also defines the way of accessing this data ( the business logic of application) for manipulation. It knows nothing about the way the data will be displayed by the application. It just provides service to access the data and modify it. Here 'Form Bean' represents Model layer.
View : The view represents the presentation of the application. The view queries the model for its content and renders it. The way the model will be rendered is defined by the view. The view is not dependent on data or application logic changes and remains same even if the business logic undergoes modification. JSP represents View Layer.
Controller : All the user requests to the application go through the controller. The controller intercepts the requests from view and passes it to the model for appropriate action. Based on the result of the action on data, the controller directs the user to the subsequent view. Action classes (action servlets) represent Controller layer.

93.Differentiate between the terms 'Design Patterns', 'Framework' and 'Architecture'.

Design Pattern: The various solutions arrived at for the known problem. This helps to avoid re-inventing the wheel. The risk-free solution can be easily used by others. For example, singleton is the design pattern that you can use instantly to enfore one object per class. You do not need to think of this on your own.
Framework: A framework is a structure or set of rules, used to solve or address complex issues. It is basically a reusable designf for the J2EE applications. For example, Struts, JSF,etc., are the frameworks. You can use these frameworks based on the requirements of your application and each has its own set of advantages.
Architecture: It is a design that describes how the various components in the application fit together. For example, MVC is an architecture which is helpful to define how the components interact within the application.

94.What is the difference between ActionForm and DynaActionForm?

In action form, you need to define the form class that extends ActionForm explicitly, whereas you can define the form dynamically inside the struts-config file when using DynaActionForm.

95.How can you use Validator framework in struts?

Validator Frameworks are helpful when the application needs server-side validation such that the particular set of validations occur very frequently within the same application. This avoids writing complex code in validation() method in every form bean. Using validator framework, there are different pre-written validations in place. You can customize these validations in XML file.

96.What are client-side and server-side vaidations?

Client-side validations: These are the validations that id done using javascripts. There is always a danger involved that the user can get through (crack-through) these validations. But for some simple validations, like converting lower-case to upper-case or date validations can be done, you can use javascripts.
Server-side validations: These are the validations done in server-side using Java components (Form bean or in business logics) where the user has no chance to crookedly get through the system.

97.Define the terms authentication and authorisation?

Authentication is the process/rule that validates if the user is allowed to access the system or not.
Authorization is the process/rule that validates if the user is allowed to access the particular part of the system or not. This occurs after user's successful authentication.

98.What are the components provided in J2EE to perform authentication and authorization?

Authentication – RequestProcessor and/or Filter.
Authorization - DTO, JDO or Java or Action classes.

99.Give the difference between between 'DispatchAction' and 'Action'?

A DispatchAction contains various different methods other than the standard execute() method in Action classes. These methods are executed based on some request parameter. For example, you can code in such a way that three buttons (namely Insert, Delete, Update) buttons correspond to different methods such as insert(), delete() and udpate(). The submit button in JSP would have the property that has the value which matches to any one of the methods defined in DispatchAction class.

100.What is pagination technique? How can you design them in struts?

Pagination is the technique where the bulk of results are split into different pages and only the information where the user can conveniently see are displayed in a page. (Like in Goooooogle). This can be achieved in many ways, but the simplest method is to have a query string (say http://www.testwebsite?pageNumber=2) would lead to information corresponding to resultset rows from 11 to 20. Assuming that you want to display 10 related rows of information, you can set the formula as follows:
Starting row = (pageNumber-1) * + 1 which is equal to 11.
Ending row = Starting row + which is equal to 20.

101.How can you populate the drop-down list using form properties?

There are many ways for this. But the best method is to use which defines collection that needs to be used to populate the drop-down list, the property to store the selected value and the collection that is used to display the labels (what we see in JSP page). For Example,
html:options collection="form-collection-property"

102.What is the XML parser provided in struts? Can you use it for other purposes?

'Digester' framework. Yes we can use for our applications to store and parse our application-related data.


Post a Comment