Core Java - Interview Questions and Answers for 'File' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Core Java - Interview Questions and Answers for 'File' - 52 question(s) found - Order By Rating

next 30
 Q1. Which jar files need to be included for using Hibernate ?Hibernate
Ans. hibernate-orm
hibernate-validator
hibernate-ogm
hibernate-search

or you can download hibernate core with all dependencies.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     hibernate jar files   hibernate     Asked in 1 Companies


 Q2. Does Java generate .class file for interfaces ? Core Java
Ans. Yes

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     .class file  java byte code  interfaces


 Q3. Write code to create a folder if it doesn't exist.Core Java
Ans. File folder = new File(path);
      
if(!folder.exists()){
try {
folder.mkdir();
            
} catch (Exception e) {}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     code  coding  file handling      basic


 Q4. How does encoding affect using Reader / writer classes or Stream classes in Java ? Core Java
Ans. Which group of bytes represent which character is defined by character encoding. So when reading character by character from a stream of bytes using Reader, specifying character encoding becomes significant as the same group of bytes can represent different character in different character encoding(Eg UTF-8 and UTF-16 etc.)

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     File io  File handling  Reader  Writer  Stream     Asked in 1 Companies


 Q5. Write code to read data from a file and write it to a file with 2 threads using the thread name contentCore Java
 This question was recently asked at 'verifone'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     threads  file  file handling     Asked in 1 Companies


 Q6. How to see last 500 lines of a log or text file Unix
Ans. tail -500 <FILE_NAME>

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     unix  log file


 Q7. In a file there are 1 million words . Find 10 most frequent words in that file.Design
 This question was recently asked at 'Amazon'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling     Asked in 1 Companies


 Q8. As root, if you have to assign the owner for the file and set only read permission for the owner, Write a unix command to do it.Unix
Ans. chmod 477

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     unix commands  setting file permissions  chown  chmod


 Q9. What are the different types of log files you have come across ?Logging
Ans. error , access , authentication , message , database etc

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     logging  log files  types of log files


 Q10. What is a host file ?Operating System
Ans. It's an operating system file that maps IP address to host names. The hosts file assists the OS in addressing networked components and serves the function of translating human friendly hostnames into numeric protocol addresses, called IP addresses, that identify and locate a host in an IP network.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     host file  operating system     Asked in 1 Companies


 Q11. What are the ways in which an application can maintain config variables ?
Ans. 1. Property files
2. config xml
3. Database

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     config  property files


 Q12. What is the use of Property files ?
Ans. Property files are used to maintain configurable values as key value pairs.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     config  property files


 Q13. What is the difference between RollingFile and RollingRandomAccessFile in log4j ?
Log4j
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     log4j  RollingFile  RollingRandomAccessFile


 Q14. What is ACL ?Operating System
Ans. Access Control List or ACL is the list of permissions attached to an object in the File System.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     acl  file system  file security  object security  operating system


 Q15. Why is it important to close files and streams ?Core Java
Ans. Optimizing Resource utilization. When you open a file using any programming language , that is actually a request to operating system to access the file. When such a request is made , resources are allocated by the OS. When you gracefully close those files, those resources are set free.

In Java if you don’t close the streams and files, Garbage collection identifies the open files which have lost the reference and hence will close them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling


 Q16. What is SAR file ?IBM WCS
Ans. Its the Store Archive that holds the store Assets in the compressed form.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     SAR file  store archieve


 Q17. Upon compiling the following class, What .class files will get created

public class OuterClass{
class InnerClass{
}
}
Core Java
Ans. OuterClass.class AND OuterClass$InnerClass.class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     class files  compilation  compile  inner classes   nested classes


 Q18. Given two files with list of words, write a program to show the common words in both filesCore Java
Ans. import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.*;
public class Common {
public static void main(String ar[])throws Exception
   {
      File f=new File("a.txt");
File f1=new File("x.java");
      System.out.println(f.exists());
FileInputStream fin = new FileInputStream(f);
      FileInputStream fin1 = new FileInputStream(f1);

      byte b[]=new byte[10000];
byte b1[]=new byte[10000];
fin.read(b);
fin1.read(b1);
String s1 = new String(b);
String s2 =new String(b1);

String words1[] = s1.trim().split(" ");
String words2[] = s2.trim().split(" ");
Listlist1 = new ArrayList<>(Arrays.asList(words1));
Listlist2 = new ArrayList<>(Arrays.asList(words2));
list1.retainAll(list2);
System.out.println(list1);
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling  file io  code  coding     Asked in 1 Companies


 Q19. What is the difference between

File f = new File("homexyz.txt");

and

File f = File.createTempFile("xyz",".txt","home"); ?
Core Java
Ans. First will not create physical file in storage whereas the second will.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling  File.createTempFile  file handling      intermediate        rare


 Q20. How to specify the sequence in which sub modules needs to be built ?Maven
Ans. By specifying the modules in the same sequence in the parent pom.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     maven  pom file  maven modules


 Q21. Watching a directory for changes. Monitoring a directory.Core Java
Ans. http://www.logicbig.com/tutorials/core-java-tutorial/java-nio/java-watch-service/

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling  monitoring directory


 Q22. Have you ever tried compressing data using Java ?Core Java
Ans. Yes, we can use ZipInputStream class for compressing the FileInputstream object.

  Sample Code for ZipInputStream

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     file handling  FileInputstream  ZipInputStream  file handling


 Q23. How and when the Buffer is cleared when using Buffered Writer Classes ?Core Java
Ans. Buffer is cleared in 2 circumstances, i.e 1. naturally when the buffer is filled and 2. explicitly when the method flush is called ( for flushing the residual )

Ideally we just need to call flush once at the end of file writing so that the residual content should be dumped to file.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     BufferedWriter  Writer  PrintWriter  File io  flush  file handling


 Q24. Tell something about BufferedWriter ? What are flush() and close() used for ?
Ans. BufferedWriter is temporary source for data storage.BufferedWriter is used to write character data to the file.Flush() is method available in B.W which ensures that all data items are written to file including last character.Close() is used to closes the character output stream.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java io   input output   file handling   file io   output stream   bufferedwriter   flush   close


 Q25. What is Scanner class used for ? when was it introduced in Java ?Core Java
Ans. Scanner class introduced in Java 1.5 for reading Data Stream from the imput device. Previously we used to write code to read a input using DataInputStream. After reading the stream , we can convert into respective data type using in.next() as String ,in.nextInt() as integer, in.nextDouble() as Double etc

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java5   scanner   file io   file input   data input stream  file handling      basic


 Q26. What is Spring configuration file?Spring
Ans. Spring configuration file is an XML file. This file contains the classes information and describes how these classes are configured and introduced to each other.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     j2ee   spring   mvc   frameworks   web applications   spring configuration file     Asked in 1 Companies


 Q27. What is a stream and what are the types of Streams and classes of the Streams?Core Java
Ans. A Stream is an abstraction that either produces or consumes information. There are two types of Streams :

Byte Streams: Provide a convenient means for handling input and output of bytes.

Character Streams: Provide a convenient means for handling input & output of characters.

Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.

Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   file io   streams   byte stream   character stream  file handling     Asked in 3 Companies


 Q28. What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?Core Java
Ans. The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented

  Sample Code for InputStream

  Sample Code for OutputStream

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   file io   streams   reader class   writer class   inputstream   outputstream   stream  file handling


 Q29. What is the purpose of the System class?Core Java
Ans. The purpose of the System class is to provide access to system resources.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   system   io   file io


 Q30. Which of the following is a canonical path ?

1. C:\directory\..\directory\file.txt
2. C:\directory\subDirectory1\directory\file.txt
3. \directory\file.txt
Ans. 2nd

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   io   file   fileio


next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: