Interview Questions and Answers - Order By Newest Q431. Difference between Scanner and BufferedReader ? Which one is faster and Why ? Core Java
Ans. Scanner is used for parsing tokens from the contents of the stream while BufferedReader just reads the stream.
BufferedReader read files efficiently by using a buffer to avoid physical disk operations.
Buffer size of Scanner is usually smaller than the Buffered Writer.
BufferedReader is faster that Scanner as it just reads the Stream and doesn't Parse the tokens to read the stream into primitive data types. Sample Code for Scanner Sample Code for BufferedReader Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   file io   input output   scanner   bufferedreader  file handlingRarely asked as it was introduced with Java 8. Ans. DocLint Provide a means to detect errors in Javadoc comments early in the development cycle and in a way that is easily linked back to the source code. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java 8   doclint   java8 featuresRarely asked as it was introduced with Java 8. Q433. What are the errors identified by DocLint ? Core Java
Ans. Bad syntax, such as unescaped characters or unmatched parentheses Bad HTML, such as invalid or missing tags or attributes Bad references, such as referencing a non-existent type with @see Accessibility errors, such as a missing summary or caption from a table Missing info, such as an undocumented parameter Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java8   java 8   doclint Q434. Why Java uses Unicode System ? Core Java
Ans. Before Unicode there were many language / country standards like ASCII , ISO , KOI and BIG 5. In order to accommodate multiple language letters and to overcome problems with using different multiple standards , a new language standard was developed i.e unicode system. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   unicode Q435. What is the difference between out.println(a+b); and out.println (a+" " +b); in Java? with a=2 and b=1 Core Java
Ans. First will give the ouput as 3 and the second will give output as 2 1 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   system.out.println   coding Q436. Which sorting algorithm is used by Collections.sort() in Java ? Core Java
Ans. The sorting algorithm is a modified mergesort. This algorithm offers guaranteed n log(n) performance. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   algorithm   collections   collections.sort   sorting algorithm expert Try 1 Question(s) Test Q437. What is the difference between Data Type and Data Structure ? Core Java
Ans. Data type: a set of values together with operations on that type Data structure: a physical implementation of a data type Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   oops   data structure   data type Q438. How many elements will be there in TreeSet after the last line and Why ? TreeSet set = new TreeSet(); set .add(new String("abc")); set .add(new String("abc")); Core Java
Ans. One. As we haven't specified the type of TreeSet, it being evaluated with the first element insertion. Once it's identified that it's of type String and as no comparator has been defined, the comparison is done using the String compareTo method. String compareTo method compares the elements by the content / value. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   set   treeset   string   compareto   coding   code Q439. Which takes more memory - float or Float ? Core Java
Ans. float is a native data type whereas Float is a class. A Float object will always take more memory than float variable as there are metadata overheads with the objects. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   data type   float Asked in 3 Companies basic   frequent Q440. What is collision in hash collections ? Core Java
Ans. Collision is the situation when two different elements have the same Hash Code. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   collision   hashcode  hash code   hash collections   ebay Asked in 1 Companies intermediate   frequent Q441. What will be the output ?Integer a = 10, b =10;Integer c = 10, d = 1000;System.out.println(a == b);System.out.println(c ==d); Core Java
Ans. truefalse Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   coding   equality   object equality Q442. What is OutOfMemoryError in Java? Core Java
Ans. OutOfMemoryError in Java is a subclass of VirtualMachineError and is thrown by JVM when it runs out of heap memory. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  outofmemoryerror   error   exceptions   jvm   java   heap memory   heap Q443. Which interface does java.util.Hashtable implement ? a. List b. Set c. Collection d. Map Core Java
Ans. Map Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  hashtable   java   collections Q444. Which of the collections allows null as the key ?
a. HashTable
b. HashMap
c. TreeMap
d. LinkedHashMap Core Java
Ans. HashMap Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   map  hashtable Asked in 2 Companies basic   frequent Q445. Strings in switch were introduced in Which Java version ? a. Java 5 b. Java 6 c. Java 7 d. Java Core Java
Ans. Java 7 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   switch   string in switchRarely asked as it was introduced with Java 8. Q446. Which keyword specify that a variable is effectively final ? a. final b. No Keyword c. Both of the above d. None of the above Core Java
Ans. No Keyword Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java 8   java8   final   effectively final   rare Rarely asked as it was introduced with Java 8. Q447. Which of the following has been introduced with Java 8 ? a. StringBuffer b. StringBuilder c. StringFilter d. StringJoiner Core Java
Ans. StringJoiner Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   java8   java 8   string   stringjoiner Q448. What is GregorianCalendar class ?
Ans. This class provides support for traditional Western calendars. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  GregorianCalendar   Calendar   util   core java   rare Q449. What are fail-fast Iterators ? Core Java
Ans. Fail-fast iterators detect illegal concurrent modification during iteration and fail quickly and cleanly rather than risking arbitrary, non deterministic behavior at an undetermined time in future. Example could be of an Iterator failing if it smells ConcurrentModificationException. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  fail-fast Iterators  Iterators Asked in 5 Companies intermediate Q450. Print natural numbers sequentially with two threads. Core Java
Ans. http://stackoverflow.com/questions/18799591/print-natural-sequence-with-help-of-2-threads1-is-printing-even-and-2nd-is-pri Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  print natural numbers with two threads   multithreading   multi threading   threads   code   coding   makemytrip.comFrequently asked in face to face interviews. Q451. Write a program to print fibonacci series. Core Java
Ans. int count = 15;
int[] fibonacci = new int[count];
fibonacci[0] = 0;
fibonacci[1] = 1;
for(int x=2; x < count; x++){
fibonacci[x] = fibonacci[x-1] + fibonacci[x-2];
}
for(int x=0; x< count; x++){
System.out.print(fibonacci[x] + " ");
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ebay   fibonacci series Asked in 66 Companies basic   frequent Q452. What is the use of Synchronized block ? Core Java
Ans. The goal of a synchronised block is to achieve mutual exclusion i.e at one time, the segment of the code should be executed by single thread only and hence the lock needs to be retrieved before executing the segment and then released. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  synchronized block   synchronized   synchronization   multithreading   threads   mutual exclusion   concurrency Asked in 4 Companies intermediate   frequent Try 1 Question(s) TestMust know at all levels. Among Top 10 frequently asked questions in Java. Very frequently asked to fresh graduates or less experienced professionals. Ans. Its a facility for code reuse and independent extension wherein a derived class inherits the properties of parent class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inheritance  object oriented programming (oops)  oops concepts  oops concepts  java concepts  code reuse  code re-use   classes  derived classes Asked in 14 Companies basic   frequent Q454. What is ADT or Abtstract Data Type ? Core Java
Ans. ADT is a container which holds different types of objects with specifications.
For example - Stack, Array, Liked list, Tree Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  data types  abstract data types Q455. Write a method to convert all elements of a set to lower case. Core Java
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+convert+all+elements+of+a+collection&category=code Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  code  coding  string  String.toLowerCase  set  collections Q456. Write java code to Get all words from a String and display them Core Java
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=+Get+all+words+from+a+String&category=code Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  string   get all words from strings   string.splitRecently asked in Sophos Q457. Write a Method to get a map of words and their count by passing in the string Core Java
Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=Method+to+get+a+map+of+words&category=code Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  map  collections Asked in 2 Companies intermediate Q458. How is static and dynamic polymorphism achieved in Java ? Core Java
Ans. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  static polymorphism  object oriented programming (oops)  oops concepts   dynamic polymorphism  object oriented programming (oops)  oops concepts   polymorphism  object oriented programming (oops)  oops concepts   overloading   overriding   broadridg Asked in 1 Companies basic   frequent Q459. Why can't we declare a class abstract as well as final ? Core Java
Ans. Abstract means that the class is only meant to be subclassed whereas final means that it cannot be subclassed so both concepts - abstract and final are actually mutually exclusive and hence not permitted together. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  abstract   final   java keywords Asked in 1 Companies Very frequently asked to fresh graduates. Frequently asked in NSEiT and Accenture India Q460. Write a program to Generate prime numbers till a given number Core Java
Ans. public class Main {
public static void main(String args[]) {
int number = 2;
int count = 0;
long sum = 0;
int givenNumber = 1000;
while (count < givenNumber) {
if (isPrimeNumber(number)) {
sum = number;
count;
}
number;
}
System.out.println(sum);
}
private static boolean isPrimeNumber(int number) {
for (int i = 2; i <= number / 2; i) {
if (number % i == 0) {
return false;
}
}
return true;
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  generate prime numbers  code  coding Asked in 5 Companies basic   frequent