Java Questions

Q:

What is the purpose of overriding toString() method?

Answer

we can override tostring() method to return String representation of our object data

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1820
Q:

What is JAR file?

Answer

A JAR file (short for Java Archive) is a ZIP file used to distribute a set of Java classes. It is used to store compiled Java classes and associated metadata that can constitute a program

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1818
Q:

How is final different from finally and finalize()?

Answer final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1811
Q:

What are the different JDBC drivers available ?

Answer

There are mainly four type of JDBC drivers available. They are:

Type 1 : JDBC-ODBC Bridge Driver - A JDBC-ODBC bridge provides JDBC API access via one or more ODBC drivers. Note that some ODBC native code and in many cases native database client code must be loaded on each client machine that uses this type of driver. Hence, this kind of driver is generally most appropriate when automatic installation and downloading of a Java technology application is not important. For information on the JDBC-ODBC bridge driver provided by Sun.

Type 2: Native API Partly Java Driver- A native-API partly Java technology-enabled driver converts JDBC calls into calls on the client API for Oracle, Sybase, Informix, DB2, or other DBMS. Note that, like the bridge driver, this style of driver requires that some binary code be loaded on each client machine.

Type 3: Network protocol Driver- A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative. It is likely that all vendors of this solution will provide products suitable for Intranet use. In order for these products to also support Internet access they must handle the additional requirements for security, access through firewalls, etc., that the Web imposes. Several vendors are adding JDBC technology-based drivers to their existing database middleware products.

Type 4: JDBC Net pure Java Driver - A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver. Several database vendors have these in progress.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1805
Q:

What is unwrapping?

Answer

Unwrapping is also called as unpacking or unboxing.


Getting the private data stored in the object by using methods is called unpacking or unwrapping.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1804
Q:

What is the difference between an Interface and an Abstract class ?

Answer

1.Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.


2.Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.


3.Members of a Java interface are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..


4.Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.


5.An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.


6.A Java class can implement multiple interfaces but it can extend only one abstract class.


7.Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.


8.In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1799
Q:

Why interface data is final?

Answer

bcoz interface does not contains any initializers and constructors to initialize its data members.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1789
Q:

Difference between Swing and Awt ?

Answer

AWT are heavy-weight componenets. Swings are light-weight components. Hence swing works faster than AWT.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1777