Java Questions

Q:

How to create a file on the hard disk by using File class object?

Answer

We can use the following method call:


boolean createNewFile();


This method creates a new file on the HD. 


 


If a file is already existing with the name given in the constructor then this method does not creates file on HD.


If file is successfully created then this method returns true.


If file is already existing on the HD then this method returns false.


This method may throw IOException whenever IO error is generated while creating file on HD.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1487
Q:

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

Answer

An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1480
Q:

What is a ResultSet ?

Answer

A table of data representing a database result set, which is usually generated by executing a statement that queries the database.


 


ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1477
Q:

What is Thread ?

Answer

A thread is a lightweight subprocess, a smallest unit of processing. It is a separate path of execution. It shares the memory area of process.



As shown in the above figure, thread is executed inside the process. There is context-switching between the threads. There can be multiple processes inside the OS and one process can have multiple threads.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1467
Q:

If super class ref is pointing sub class object then by using super class ref is it possible to call sub class newly defined method?

Answer

yes if the method is ovreriding method


no if the method is not overriding method

Report Error

View answer Workspace Report Error Discuss

Subject: Java

134 1464
Q:

What is JDBC Driver ?

Answer

The JDBC Driver provides vendor-specific implementations of the abstract classes provided by the JDBC API. This driver is used to connect to the database.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1462
Q:

How to check that the file object is pointing a file on HD?

Answer

boolean isFile();

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1460
Q:

What is Auto boxing and unboxing?

Answer

Autoboxing is the process of converting a primitive type data into its corresponding wrapper class object instance.


Example:


Integer number = new Integer (100); // number is now refers to the object 100


 


Unboxing is the process of converting a wrapper instance into a primitive type.


Example: 


Integer number = new Integer (100); 


int num = number;// without type casting number would be changed into int type

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1459