Interview 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 1507
Q:

How to create Directory on the HD?

Answer

To create directory on the HD we use mkDir() method:


boolean mkDir();


This method returns true if the directory is created on HD


This method returns false if the directory is already existing on HD

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1703
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 1495
Q:

How to check that whether the file object is pointing a folder or not?

Answer

boolean isDirectory();

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1666
Q:

How to get last modified date of a file?

Answer

long lastModified();


we can give this return value to a date object and we can get data to be displayed.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1475
Q:

How to get contents of the folder?

Answer

File[] listFiles();


this method returns list of files stored in a directory.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1597
Q:

What is Thread?

Answer

A Thread is a block of code that can be executed in parallel with another block of code.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2218
Q:

What is MultiTasking?

Answer

Executing more than one program simultaniously.(i.e at time)


Ex:


Windows media player  is a program


Internet explorer(IE) is another program executing both the programs  at a time is called multi tasking.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1996