Interface Java Interview Questions – Set 02

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.

JavaServer Pages (JSP) technology is the Java platform technology for delivering dynamic content to web applications in a portable, secure and well-defined way. The JSP Technology allows us to use HTML, Java, JavaScript and XML in a single file to create high quality and fully functionaly User Interface components for Web Applications.

If a method is declared as protected, where may the method be accessed

A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared.

What is the difference between JDBC and ODBC

  1. a) OBDC is for Microsoft and JDBC is for Java applications. b) ODBC can’t be directly used with Java because it uses a C interface. c) ODBC makes use of pointers which have been removed totally from Java. d) ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required. e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.

What is adapter class

An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged()

What is a package?-

?– A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management

What are Encapsulation, Inheritance and Polymorphism?

Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.

Why will you use Comparator and Comparable interfaces?

java.util.Comparator
java.util.Comparator compares some other class’s instances.

java.lang.Comparable
java.lang.Comparable compares another object with itself.

Differentiate between final, finally and finalize.

The keyword is final. It is used for declaring a constant It prevents a class from producing subclasses.

finally is a code.It always executes when the try block is finished, Unless System.exit() has been called.finalize() is a method, Before discarding by the garbage collector it is invoked.

Differentiate JAR and WAR files

JAR files:

  • JAR files is the acronym stands for Java ARchive fles.
  • JAR files allow aggregating many files into one,
  • JAR is usually used to hold Java classes in a library.

WAR files:

  • WAR files is the acronym stands for Web ARchive fles.
  • WAR stores XML, java classes, and JavaServer pages
  • WAR is mainly used for Web Application purposes.

In a Java , how can you send program messages on the system console, but error messages, to a file?

The class System has a variable out that denotes the standard output.

The standard error device represents the variable err .

Naturally, they both point at the system console.

In this way, the standard output can be sent to the file:

Stream x = new Stream(new FileOutputStream(“error.txt”));

System.setErr(x);

System.Out(x);

What is the Set interface

The Set interface provides methods for accessing the elements of a finite mathematical set. Sets do not allow duplicate elements.

What is the difference between abstract class and interface

  1. a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.

What is a Java package and how is it used

A Java package is a naming context for classes and interfaces. A package is used to create a separate name space for groups of classes and interfaces.

Packages are also used to organize related classes and interfaces into a single API unit and to control accessibility to these classes and interfaces