48. What is an Applet ? A java applet is program that can be included in a HTML page and be executed in a java enabled client browser. Applets are used for creating dynamic and interactive web applications.
49. Explain the life cycle of an Applet. An applet may undergo the following states:
: An applet is initialized each time is loaded.
: Begin the execution of an applet.
: Stop the execution of an applet.
: Perform a final cleanup, before unloading the applet.
50. What happens when an applet is loaded ? First of all, an instance of the applet’s controlling class is created. Then, the applet initializes itself and finally, it starts running.
51. What is the difference between an Applet and a Java Application ? Applets are executed within a java enabled browser, but a Java application is a standalone Java program that can be executed outside of a browser. However, they both require the existence of a Java Virtual Machine (JVM). Furthermore, a Java application requires a main method with a specific signature, in order to start its execution. Java applets don’t need such a method to start their execution. Finally, Java applets typically use a restrictive security policy, while Java applications usually use more relaxed security policies.
52. What are the restrictions imposed on Java applets ?Mostly due to security reasons, the following restrictions are imposed on Java applets:
- An applet cannot load libraries or define native methods.
- An applet cannot ordinarily read or write files on the execution host.
- An applet cannot read certain system properties.
- An applet cannot make network connections except to the host that it came from.
- An applet cannot start any program on the host that’s executing it.
53. What are untrusted applets ? Untrusted applets are those Java applets that cannot access or execute local system files. By default, all downloaded applets are considered as untrusted.
54. What is the difference between applets loaded over the internet and applets loaded via the file system ? Regarding the case where an applet is loaded over the internet, the applet is loaded by the applet classloader and is subject to the restrictions enforced by the applet security manager. Regarding the case where an applet is loaded from the client’s local disk, the applet is loaded by the file system loader. Applets loaded via the file system are allowed to read files, write files and to load libraries on the client. Also, applets loaded via the file system are allowed to execute processes and finally, applets loaded via the file system are not passed through the byte code verifier.
55. What is the applet class loader, and what does it provide ? When an applet is loaded over the internet, the applet is loaded by the applet classloader. The class loader enforces the Java name space hierarchy. Also, the class loader guarantees that a unique namespace exists for classes that come from the local file system, and that a unique namespace exists for each network source. When a browser loads an applet over the net, that applet’s classes are placed in a private namespace associated with the applet’s origin. Then, those classes loaded by the class loader are passed through the verifier.The verifier checks that the class file conforms to the Java language specification . Among other things, the verifier ensures that there are no stack overflows or underflows and that the parameters to all bytecode instructions are correct.
56. What is the applet security manager, and what does it provide ? The applet security manager is a mechanism to impose restrictions on Java applets. A browser may only have one security manager. The security manager is established at startup, and it cannot thereafter be replaced, overloaded, overridden, or extended.
57. What is the difference between a Choice and a List ? A Choice is displayed in a compact form that must be pulled down, in order for a user to be able to see the list of all available choices. Only one item may be selected from a Choice. A List may be displayed in such a way that several List items are visible. A List supports the selection of one or more List items.
58. What is a layout manager ? A layout manager is the used to organize the components in a container.
59. What is the difference between a Scrollbar and a JScrollPane ? A is a , but not a . A is a . A handles its own events and performs its own scrolling.
60. Which Swing methods are thread-safe ? There are only three thread-safe methods: repaint, revalidate, and invalidate.
61. Name three Component subclasses that support painting. The , , , and Applet classes support painting.
62. What is clipping ? Clipping is defined as the process of confining paint operations to a limited area or shape.
63. What is the difference between a MenuItem and a CheckboxMenuItem ? The class extends the class and supports a menu item that may be either checked or unchecked.
64. How are the elements of a BorderLayout organized ? The elements of a are organized at the borders (North, South, East, and West) and the center of a container.
65. How are the elements of a GridBagLayout organized ?The elements of a are organized according to a grid. The elements are of different sizes and may occupy more than one row or column of the grid. Thus, the rows and columns may have different sizes.
66. What is the difference between a Window and a Frame ?The class extends the Window class and defines a main application window that can have a menu bar.
67. What is the relationship between clipping and repainting ? When a window is repainted by the AWT painting thread, it sets the clipping regions to the area of the window that requires repainting.
68. What is the relationship between an event-listener interface and an event-adapter class ? An event-listener interface defines the methods that must be implemented by an event handler for a particular event. An event adapter provides a default implementation of an event-listener interface.
69. How can a GUI component handle its own events ? A GUI component can handle its own events, by implementing the corresponding event-listener interface and adding itself as its own event listener.
70. What advantage do Java’s layout managers provide over traditional windowing systems ? Java uses layout managers to lay out components in a consistent manner, across all windowing platforms. Since layout managers aren’t tied to absolute sizing and positioning, they are able to accomodate platform-specific differences among windowing systems.
71. What is the design pattern that Java uses for all Swing components ? The design pattern used by Java for all Swing components is the Model View Controller (MVC) pattern.
72. What is JDBC ? JDBC is an abstraction layer that allows users to choose between databases. JDBC enables developers to write database applications in Java, without having to concern themselves with the underlying details of a particular database.
73. Explain the role of Driver in JDBC. The JDBC Driver provides vendor-specific implementations of the abstract classes provided by the JDBC API. Each driver must provide implementations for the following classes of the java.sql package: , , , , and .
74. What is the purpose Class.forName method ? This method is used to method is used to load the driver that will establish a connection to the database.
75. What is the advantage of PreparedStatement over Statement ? PreparedStatements are precompiled and thus,their performance is much better. Also, PreparedStatement objects can be reused with different input values to their queries.
76. What is the use of CallableStatement ? Name the method, which is used to prepare a CallableStatement. A is used to execute stored procedures. Stored procedures are stored and offered by a database. Stored procedures may take input values from the user and may return a result. The usage of stored procedures is highly encouraged, because it offers security and modularity.The method that prepares a is the following:
77. What does Connection pooling mean ? The interaction with a database can be costly, regarding the opening and closing of database connections. Especially, when the number of database clients increases, this cost is very high and a large number of resources is consumed.A pool of database connections is obtained at start up by the application server and is maintained in a pool. A request for a connection is served by a connection residing in the pool. In the end of the connection, the request is returned to the pool and can be used to satisfy future requests.