Interview Questions and Answers for 'Streams' | 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

   



Interview Questions and Answers for 'Streams' - 32 question(s) found - Order By Newest

next 30
  Q1. Explain OOPs

or

Explain OOPs Principles

or

Explain OOPs Concepts

or

Explain OOPs features

or

Tell me something about OOPs
Core Java
Ans. OOPs or Object Oriented Programming is a Programming model which is organized around Objects instead of processes. Instead of a process calling series of processes, this model stresses on communication between objects. Objects that all self sustained, provide security by encapsulating it's members and providing abstracted interfaces over the functions it performs. OOP's facilitate the following features

1. Inheritance for Code Reuse
2. Abstraction for modularity, maintenance and agility
3. Encapsulation for security and protection
4. Polymorphism for flexibility and interfacing

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

   Like         Discuss         Correct / Improve     oops  oops features     Asked in 260 Companies      basic        frequent


Frequently asked to fresh graduates.
  Q2. What is a Deadlock ?Operating System
Ans. When two threads are waiting each other and cant precede the program is said to be deadlock.

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

   Like         Discuss         Correct / Improve     java   threads   multi threading   operating system   deadlock  concurrency     Asked in 23 Companies      basic        frequent


 Q3. 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


Usually asked to entry level software developers.
  Q4. Write a program to swap two variables without using thirdCore Java
Ans. public static void main(String[] args) {
   int num1 = 1;   
   int num2 = 2;
   num1 = num1^num2;
   num2 = num1^num2;
   num1 = num1^num2;
   System.out.print("num1 = " + num1 +", num2 = "+num2);
}

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

   Like         Discuss         Correct / Improve     code  coding     Asked in 37 Companies      basic        frequent


 Q5. Will this code compile fine ?

ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(new File("newFile.txt")));
Core Java
Ans. Yes.

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

   Like         Discuss         Correct / Improve     java   io   file   fileio   coding   code   objectoutputstream   fileoutputstream   yesno  file handling


 Q6. Name few IO Stream classes and interfaces ?Core Java
Ans. http://www.buggybread.com/2015/01/java-stream-io-classes-and-interfaces.html

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

   Like         Discuss         Correct / Improve     java   io   input output   stream


 Q7. What is System.in in Java ?Core Java
Ans. It is an InputSream which is usually connected to the keyboard input of console program.

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

   Like         Discuss         Correct / Improve     System.in  Input Stream  Input Output


 Q8. Explain System.out.println ?Core Java
Ans. System is a class within java.lang package that contains several useful class fields and methods. It cannot be instantiated and hence can use only statically.even in this case this has been used statically i.e with class name itself and without creating an instance.

out is the static reference of Printstream declared as following in the System Class -

public final static PrintStream out = null;

println is the method of PrintStream class.

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

   Like         Discuss         Correct / Improve     System class  Streams  Input Output  println     Asked in 1 Companies      basic        frequent


 Q9. 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


 Q10. 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


 Q11. 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


 Q12. Which is the abstract parent class of FileWriter ?Core Java
Ans. OutputStreamWriter

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

   Like         Discuss         Correct / Improve     java   io   file   fileio   filewriter   outputstreamwriter  file handling


 Q13. Which class is used to read streams of raw bytes from a file?Core Java
Ans. FileInputStream

  Sample Code for FileInputStream

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

   Like         Discuss         Correct / Improve     java   io   file   fileio   fileinputstream  file handling


 Q14. Which is the Parent class of FileInputStream ?Core Java
Ans. InputStream

  Sample Code for InputStream

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

   Like         Discuss         Correct / Improve     java   io   file   fileio   fileinputstream   inputstream  file handling


 Q15. Which exceptions should be handled with the following code ?

FileOutputStream fileOutputStream = new FileOutputStream(new File("newFile.txt"));
Ans. FileNotFoundException

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

   Like         Discuss         Correct / Improve     java   io   file   fileio   coding   code   scjp   ocjp   filenotfoundexception   fileoutputstream  file handling


 Q16. 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


 Q17. How Spliterator in Java 8 different than iterator ?Core Java
Ans. Though there are many differences the way internally they both iterates the collections and streams respectively, but the main difference in performance that is achieved by spliterator as it can iterate Streams in Parallel whereas iterator only iterates collections sequentially.

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

   Like         Discuss         Correct / Improve     java8  java 8  spliterator  java 8 streams  streams


 Q18. Which is better in terms of performance - Iterator or Spliterator ?Core Java
Ans. Spliterator has better performance potential than iterators but only if the potential is used. Spliterator can iterate streams in parallel as well as in sequence whereas iterator can only iterate in sequence.

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

   Like         Discuss         Correct / Improve     iterator  collections  streams  parallel streams  Spliterator


 Q19. Difference between System.out.printf and System.out.println ?Core Java
Ans. println prints an additional end of line whereas printf doesnt.

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

   Like         Discuss         Correct / Improve     System class  Streams  Input Output  println  printf


 Q20. What is Spring Security ?Spring
Ans. Spring Security is a powerful and highly customizable authentication and access control framework. It is the de facto standard for securing Spring-based applications.

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

   Like         Discuss         Correct / Improve          Asked in 3 Companies


 Q21. What is the difference between the Reader/Writer java.io hierarchy and the Stream class hierarchy?Core Java
Ans. The Reader/Writer hierarchy is character oriented, whereas the Stream class hierarchy is byte oriented.

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

   Like         Discuss         Correct / Improve     java io  streams      intermediate


 Q22. Write a class / program that takes few numbers from the input and then output the average ?Core Java
Ans. public class Class{
   public static void main(String[] args){
      List<Integer> collector = new ArrayList();

      Scanner scanner = new Scanner(System.in);
      int x = scanner.nextInt();
      while(x != 0){
         collector.add(x);
         x = scanner.nextInt();
      }
      System.out.println(collector.stream().collect(Collectors.averagingInt(p->((Integer)p))));
   }
}

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

   Like         Discuss         Correct / Improve     coding  code  collector  streams  Collectors.average     Asked in 1 Companies


 Q23. What is a gobbler class ?Core Java
Ans. A gobbler class take care of reading from a stream and optionally write out to another stream. Allows for non blocking reads when invoking a process through Runtime.exec(). Moreover the user can specify a callback that is called whenever anything is read from the stream.

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

   Like         Discuss         Correct / Improve     gobbler  stream


 Q24. What is a shard in Kinesis stream ?Amazon Web Services (AWS)
Ans. A shard is a uniquely identified group of data records in a stream or we can say that Shard is a partition in Kinesis stream. A shard supports a fixed bandwidth i.e fixed number of messages per second. The total capacity of the stream is the sum of the capacities of its shards. If the data rate changes, we can allocate / deallocate more shards to accommodate that.

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

   Like         Discuss         Correct / Improve     Amazon AWS  AWS  Amazon Kinesis Stream  shard  shard in amazon kinesis


 Q25. What is the relationship between shard and partition key in kinesis stream ?Amazon Web Services (AWS)
Ans. A partition key is used to group data by shard within a stream. A partition key identifies which shard the message belong to.

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

   Like         Discuss         Correct / Improve     Amazon AWS  AWS  Amazon Kinesis Stream  shard  shard in amazon kinesis   partition key in amazon kinesis   shard and partition key


 Q26. What is the difference between stream and parallel stream ?Core Java
Ans. streams are used for sequential processing of data and parallel streams are used for parallel processing of data (only if the underlying processor is multicore).

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

   Like         Discuss         Correct / Improve     stream vs parallel stream  stream  parallel stream     Asked in 1 Companies


 Q27. How can i split a linked list in two parts in java 8?Core Java
Ans. This can be done using a Spliterator.

LinkedList list = Arrays.asList("names","numbs","birds","animals");
Spliterator split1 = list.Spliterator();
Spliterator split2 = split1.Spliterator();

Now, the LinkedList is split into split1 and split2.
use split2 first then split1 to check the output.

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

   Like         Discuss         Correct / Improve     java 8  parallel stream  spliterator     Asked in 1 Companies


 Q28. What are we doing here

list.stream().collect(Collectors.groupingBy(ClassA::getElement1,
               Collectors.averagingDouble(ClassA::getelement2)));
Core Java
Ans. We are averaging elements of a collection by element1 grouped by element1

* list is the reference of collection
* element1 is the member element returned by getElement1 method of ClassA
* element2 is the member element returned by getElement2 method of ClassA

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

   Like         Discuss         Correct / Improve     java 8  collections  java 8 streams  collectors


 Q29. What will the following code return

list.stream().collect(Collectors.groupingBy(ClassA::getElement1,
               Collectors.averagingDouble(ClassA::getElement2)));
Core Java
Ans. Map<DataType1,DataType2> where DataType1 is the data type of element1 ( returned by getelement1 method ) and DataType2 is the data type of element2 ( returned by getElement2 method )

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

   Like         Discuss         Correct / Improve     java 8  collections  java 8 streams


 Q30. 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


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: