Java Questions

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 1983
Q:

Are arrays primitive data types?

Answer In Java, Arrays are objects.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1973
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 1972
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 1955
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 1944
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 1924
Q:

When this. non-static datamember is compulsory inside non-static method

Answer

Whenever there is local- variable/parameter inside the method with same name as data member.


Ex:


Class Sample {


 int a;


  void show() {


   int a=5;


   system.out.println(a); // 5


   system.out.println(this.a);//23


  }


}


class MainApp {


  Public static void main(String[] args) {


  Sample s = new Sample();


   s.a = 23;


   s.show();


   }


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1923
Q:

What is the purpose of garbage collection in Java, and when is it used ?

Answer

The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused. A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1920