Hyderabad:8008855666, Vizag:9966955666, Rajahmundry:9059061333, Kakinada:9618855666

Demo2 first
IEEE Projects on:Java & .NET
Demo2 second
Mobile Application Projects on:J2ME & ANDROID
Demo2 third
IEEE Projects on:Java & .NET
Demo2 fourth
Mobile Application Projects on:J2ME & ANDROID

Adv Java

1.What is Servlet?

ANSWER
servlet

2.What is a swing?

ANSWER
a style of jazz that was dominant in the 1930s, and performed by jazz big bands primarily for dancing audiences. a rhythmic style that involves elongating the first of a pair of consecutive eighth notes, and accenting the second of the two. The rhythm is derived from subdividing a quarter note into three equal parts (a triplet) rather than into an even number of parts. Therefore, swung eighth notes are not really eighth notes, but two legs of a triplet tied together, and the third articulated. an elusive quality that some jazz musicians use to describe music they like. (e.g. “that music swings!”)

3.What is the difference between Swing and AWT components?

ANSWER
AWT components are heavy-weight, whereas Swing components are lightweight. Hence Swing works faster than AWT. Heavy weight components depend on the local windowing toolkit. For example, java.awt.Button is a heavy weight component. Pluggable look and feel possible using java Swing. Also, we can switch from one look and feel to another at runtime in swing which is not possible in AWT.

4.Name the containers which use Border Layout as their default layout?

ANSWER
window, Frame and Dialog classes.

5.Name Container classes.

ANSWER
Window, Frame, Dialog, FileDialog, Panel, Applet, or ScrollPane

6.How can a GUI component handle its own events?

ANSWER
A component can handle its own events by implementing the required event-listener interface and adding itself as its own event listener.

7.Which package has light weight components?

ANSWER
javax.Swing package contains light weight components. All components in Swing, except JApplet, JDialog, JFrame and JWindow are lightweight components.

8.What are peerless components?

ANSWER
The peerless components are called light weight components.

8.What is a Container in a GUI?

ANSWER
A Container contains and arranges other components (including other containers) through the use of layout managers, which use specific layout policies to determine where components should go as a function of the size of the container.

9.How are the elements of different layouts organized?

ANSWER
A layout manager is an object that is used to organize components in a container. The different layouts available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout. FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements may be different sizes and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.

10.Which Container method is used to cause a container to be laid out and redisplayed?

ANSWER
validate()

11.Name Component subclasses that support painting.

ANSWER
The Canvas, Frame, Panel, and Applet classes support painting.

12.What is the purpose of the enableEvents() method?

ANSWER
The enableEvents() method is used to enable an event for a particular component. Normally, an event is enabled when a listener is added to an object for a particular event. The enableEvents() method is used by objects that handle events by overriding their event-dispatch methods.

13.What is the difference between a Window and a Frame?

ANSWER
The Frame class extends Window to define a main application window that can have a menu bar.

14.Which containers use a FlowLayout as their default layout?

ANSWER
The Panel and Applet classes use the FlowLayout as their default layout.

15.What is the preferred size of a component?

ANSWER
The preferred size of a component is the minimum component size that will allow the component to display normally.

16.What is Event-Driven-Thread (EDT) in Swing?

ANSWER
Event-Driven-Thread or EDT is a special thread in Swing and AWT. Event-Driven Thread is used to draw graphics and listen for events in Swing. You will get a bonus point if you able to highlight that time consuming operations like connecting to database, opening a file or connecting to network should not be done on EDT thread because it could lead to freezing GUI because of blocking and time consuming nature of these operations instead they should be done on separate thread and EDT can just be used to spawn those thread on a button click or mouse click. Read more: http://javarevisited.blogspot.com/2011/09/swing-interview-questions-answers-in.html#ixzz1tJTqpQZN

17.What are differences between Swing and AWT?

ANSWER
One of the classic java swing interview questions and mostly asked on phone interviews. There is couple of differences between swing and AWT: 1) AWT component are considered to be heavyweight while Swing component are lightweights 2) Swing has plug-gable look and feel. 3) AWT is platform depended same GUI will look different on different platform while Swing is developed in Java and is platform dependent. Read more: http://javarevisited.blogspot.com/2011/09/swing-interview-questions-answers-in.html#ixzz1tJU1x1Ia

18.What is difference between invokeAndWait and invokeLater?

ANSWER
This swing interview question is asked differently at different point. some time interviewer ask how do you update swing component from a thread other than EDT, for such kind of scenario we use SwingUtilities.invokeAndWait(Runnable r) and SwingUtilities.invokeLetter(Runnable r) though there are quite a few differences between these two, major one is invokeAndWait is a blocking call and wait until GUI updates while invokeLater is a non blocking asynchronous call. In my opinion these question has its own value and every swing developer should be familiar with these questions or concept not just for interview point of view but on application perspective. you can read more on my post How InvokeAndWait and InvokeLater works in Swing Read more: http://javarevisited.blogspot.com/2011/09/swing-interview-questions-answers-in.html#ixzz1tJUoWXcW

19.What is JDBC?

ANSWER
JDBC may stand for Java Database Connectivity. It is also a trade mark. JDBC is a layer of abstraction that allows users to choose between databases. It allows you to change to a different database engine and to write to a single API. JDBC allows you to write database applications in Java without having to concern yourself with the underlying details of a particular database.

20.What are the steps involved in establishing a JDBC connection?

ANSWER
This action involves two steps: loading the JDBC driver and making the connection.

21.How can you load the drivers?

ANSWER
Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it: Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”); Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code: Class.forName(”jdbc.DriverXYZ”);

22.How can you make the connection?

ANSWER
To establish a connection you need to have the appropriate driver connect to the DBMS. The following line of code illustrates the general idea: String url = “jdbc:odbc:Fred”; Connection con = DriverManager.getConnection(url, “Fernanda”, “J8?);

23.How can you create JDBC statements and what are they?

ANSWER
A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send. For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, the method to use is executeUpdate. It takes an instance of an active connection to create a Statement object. In the following example, we use our Connection object con to create the Statement object Statement stmt = con.createStatement();

24.What are the different types of Statements?

ANSWER
Regular statement (use createStatement method), prepared statement (use prepareStatement method) and callable statement (use prepareCall)

25.How can you retrieve data from the ResultSet?

ANSWER
JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object rs. ResultSet rs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”); String s = rs.getString(”COF_NAME”); The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get) the value stored in the column COF_NAME in the current row of rs.

26.How can you use PreparedStatement?

ANSWER
This special type of statement is derived from class Statement.If you need a Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement’s SQL statement without having to compile it first. PreparedStatement updateSales = con.prepareStatement("UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?");

27.How many types of JDBC Drivers are present and what are they?

ANSWER
JDBC drivers are divided into four types or levels. The different types of jdbc drivers are: Type 1: JDBC-ODBC Bridge driver (Bridge) Type 2: Native-API/partly Java driver (Native) Type 3: All Java/Net-protocol driver (Middleware) Type 4: All Java/Native-protocol driver (Pure)

28.What Class.forName will do while loading drivers?

ANSWER
It is used to create an instance of a driver and register it with the Driver Manager. When you have loaded a driver, it is available for making a connection with a DBMS.

29.What Class.forName will do while loading drivers?

ANSWER
It is used to create an instance of a driver and register it with the Driver Manager. When you have loaded a driver, it is available for making a connection with a DBMS.

30.How to call a Stored Procedure from JDBC?

ANSWER
The first step is to create a CallableStatement object. As with Statement and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure.

31.What is a "dirty read"?

ANSWER
Quite often in database processing, we come across the situation wherein one transaction can change a value, and a second transaction can read this value before the original change has been committed or rolled back. This is known as a dirty read scenario because there is always the possibility that the first transaction may rollback the change, resulting in the second transaction having read an invalid value.

32.What are the common tasks of JDBC?

ANSWER
Common tasks of JDBC are as follows: 1. Create an instance of a JDBC driver or load JDBC drivers through jdbc.drivers 2. Register a driver 3. Specify a database 4. Open a database connection 5. Submit a query 6. Receive result 7. Process result

33.What is Servlet?

ANSWER
A servlet is a Java technology-based Web component, managed by a container called servlet container or servlet engine, that generates dynamic content and interacts with web clients via a request/response paradigm.

34.Why is Servlet so popular?

ANSWER
Because servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server.

35.What is servlet container?

ANSWER
The servlet container is a part of a Web server or application server that provides the network services over which requests and responses are sent, decodes MIME-based requests, and formats MIME-based responses. A servlet container also contains and manages servlets through their lifecycle.

36.The code in a finally clause will never fail to execute, right?

ANSWER
Using System.exit(1); in try block will not allow finally code to execute.

37.How can a servlet refresh automatically if some new data has entered the database?

ANSWER
You can use a client-side Refresh or Server Push

38.What is filter? Can filter be used as request or response?

ANSWER
A filter is a reusable piece of code that can transform the content of HTTP requests,responses, and header information. Filters do not generally create a response or respond to a request as servlets do, rather they modify or adapt the requests for a resource, and modify or adapt responses from a resource.

39.What are the considerations for servlet clustering?

ANSWER
Objects stored in a session should be serializable to support in-memory replication of sessions. Also consider the overhead of serializing very large objects. Test the performance to make sure it is acceptable. Design for idempotence. Failure of a request or impatient users clicking again can result in duplicate requests being submitted. So the Servlets should be able to tolerate duplicate requests. Avoid using instance and static variables in read and write mode because different instances may exist on different JVMs. Any state should be held in an external resource such as a database. Avoid storing values in a ServletContext. A ServletContext is not serializable and also the different instances may exist in different JVMs. Avoid using java.io.* because the files may not exist on all backend machines. Instead use getResourceAsStream().

40.How do you get your servlet to stop timing out on a really long database query?

ANSWER
There are situations despite how much database tuning effort you put into a project, there might be complex queries or a batch process initiated via a Servlet, which might take several minutes to execute. The issue is that if you call a long query from a Servlet or JSP, the browser may time out before the call completes. When this happens, the user will not see the results of their request. There are proprietary solutions to this problem like asynchronous servlets in WebLogic, Async Beans in WebSphere etc but you need a solution that is portable. Let us look at portable solutions to this issue.

41.What is a JSP and what is it used for?

ANSWER
Java Server Pages (JSP) is a platform independent presentation layer technology that comes with SUN s J2EE platform. JSPs are normal HTML pages with Java code pieces embedded in them. JSP pages are saved to *.jsp files. A JSP compiler is used in the background to generate a Servlet from the JSP page.

42.What is JSP technology?

ANSWER
Java Server Page is a standard Java extension that is defined on top of the servlet Extensions. The goal of JSP is the simplified creation and management of dynamic Web pages. JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.

43.What is JSP page?

ANSWER
A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.

44.How many JSP scripting elements and what are they?

ANSWER
There are three scripting language elements: --declarations --scriptlets --expressions

45.What is Servlets and explain the advantages of Servlet life cycle?

ANSWER
Servlets are modules that run within the server and receive and respond to the requests made by the client. Servlets retrieve most of the parameters using the input stream and send their responses using an output stream. Servlets are used to extend the server side functionality of a website. They communicate with various application on the server side and respond to the request made by the client.

46.Whats the advantages using servlets over using CGI?

ANSWER
CGI programs run outside the webserver. So a new process must be started to execute a CGI program. CGI programs are designed to handle a single request at a time. After that they return the result to the web server and exit. On the other hand servlets can handle multiple requests concurrently. They run within web servers. They generate dynamic content that is easier to write and faster to run.

47. Purpose of servlets

ANSWER
A java enabled server’s functionality can be extended by a servlets. Usually a servlets is used to develop web applications in a web server. The servlets are used to create web pages which are called dynamic web pages which mean the content of a web page can change according to the input sent from the web client. Servlets are server independent and platform independent.

48.Describe the basics of Servlets

ANSWER
Servlets are java classes which run on a web server. The results produced by the servlet are viewed on a remote web server. Servlet is a server side component in web applications. The servlets performs the request / response paradigm using the web container. Servlets is the best alternative for CGI. HTTP servlets is advanced and mostly used on current web applications. These servlets responds to HTTP protocol requests that are being sent from a web server and returns web pages. Servlets container creates only one instance for each servlets. The requests are handled by a separate thread. Each thread will invoke doGet or doPost which in turn invokes the service() method where the actual servlet’s operations are authored.

49.Explain the purpose of Servlet interface.

ANSWER
The javax.servlet.HttpServlet / javax.servlet.Servlet is the interface that is to be implemented by all the servlets. The servlet’s code / actions / implementation is done by implementing this interface. The developers need to implement this interface when the application demands , or their application can not / chooses not to inherit from the GenericServlet or HttpServlet. For instance the RMI / CORBA that simulates the servlets will need to directly implement this interface. The life cycle methods , one init(),one or more service() and one destroy() will be implemented, and invoked by the network service. In addition to the life cycle methods, this interface can be used to return information about itself such as version, author, copyright etc.

50.What is HTTPServlet class?

ANSWER
The HTTPServlet class provides an abstract class that is to be sub classed which is suitable for a web site. The subclass of HTTPServlet class must override any one of the following methods: doGet(), doPost(), doPut(), doDelete(), init(), destroy(), or getServletInfo(). The service() method overriding has almost no reason because the service() method handles the HTTP requests by handler methods of HTTP request type such as doxxxx() methods.

0.

ANSWER

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>