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. |
|
| ||||
Core Java - Interview Questions and Answers for 'Java 8' - 37 question(s) found - Order By Newest | ||||
Not frequently asked as it was introduced with Java 8. | ||||
| ||||
Ans. Final variable means a variable that has been declared final and hence cannot be de referenced after initialization. Effective final means a variable that has not been declared final but haven't been reassigned the value after initialization. First is the regulation that restricts the reassignment and will raise a compilation error if we try to do so. Second is the outcome without the restriction. Effective Final is the eventual treatment of the variable that is required for many features. For eq - Java 8 requires that local variables referenced from a lambda expression must be final or effectively final.It means all local referenced from lambda expressions must be such that their value shouldn't be changed after initialization whether declared final or not. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   java 8   final   effective final   final vs effective final   lambda expressions expert | ||||
Try 2 Question(s) Test | ||||
Not frequently asked as it was introduced with Java 8. | ||||
| ||||
Ans. StringJoiner is a util method to construct a string with desired delimiter. This has been introduced with wef from Java 8. Sample Code StringJoiner strJoiner = new 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 | ||||
| ||||
Ans. Interfaces don't have member elements and method definitions that could cause diamond problem. With Java 8, Interfaces have default method definitions. This could have created diamond problem but Java introduced a compile time check for "duplicate default methods" in case same method is derived from multiple interfaces and no definition is overridden by the class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  diamond problem  interfaces  java 8  default methods | ||||
Not frequently asked as it was introduced with Java 8. | ||||
| ||||
Ans. Optional is a good way to protect application from runtime nullPointerException in case the the absent value has been represented as null. So basically Optional class provides the type checking during compile time and hence will never result in NPE. For ex - List intList.add(Optional.empty()); intList.add(Optional.of(new Employee("abc"))); intList.add(Optional.of(new Employee("xyz"))); intList.add(Optional.of(new Employee("123"))); System.out.println(intList.get(0).getName()); So Now , even when the first list element is empty, this code will never throw an NullPointerException. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   java 8   optional | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/java-optional-classes-and-interfaces.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   optional   java 8   java8 | ||||
| ||||
Ans. Earlier any class implementing an interface was supposed to implement all methods declared in an interface. There was no place for optionally implementing all or subset of methods.Though we have abstract classes wherein we could have provided such a mechanism by declaring some methods as abstract while providing definition for some. But as Abstract classes have a body and are comparatively heavier than interfaces and interfaces associate closely to the concept of providing interfacing than abstract classes, Java might have though of providing optional implementation for default methods. This way same interface can be reused in variety of ways rather than making copies of an interface to suit different needs. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 8   java8  interface default methods  default methods Asked in 6 Companies | ||||
| ||||
Ans. Optional is to be used for arguments / atrributes which are indeed optional i.e the request should continue even if they aren't provided. It should not be used for mandatory attributes or arguments as we would like application to shout out ( with error message / exception trace ) to signify a problem. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  optional  nullpointerexception  java8  java 8 Asked in 1 Companies | ||||
| ||||
Ans. ConcurrentMap is an interface and it is a member of the Java Collections Framework. It represents a Map that is capable of handling concurrent access to it without affecting the consistency of entries in a map. ConcurrentMap interface present in java.util.concurrent package. HashMap operations are not synchronized, while Hashtable provides synchronization. Though Hashtable is thread-safe, it is not very efficient. To solve this issue, the Java Collections Framework introduced ConcurrentMap in Java 1.5. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Concurrent Interface   java.util.concurrent   Java 8 Concurrency   java concurrency   java 8 Asked in 1 Companies | ||||
Not frequently asked as it was introduced with Java 8. | ||||
| ||||
Ans. This is an informative annotation that specify that the interface is a functional interface. A Function Interface has only one abstract method and many default methods. Compiler generates an error if the interface specified with the annotation doesn't abide by the specifications for functional interface. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   java 8   functional interface   default methods | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
Ans. They all does the same task i.e to compute statistical information on the stream of data. They differ by the way they store the statistical information as they expect a different data type of the values being used. IntSummaryStatistics and LongSummaryStatistics expect non floating point values and hence stores the statistical information like min,max and sum as non floating values ( int or long ) whereas DoubleSummaryStatistics stores these information as floating value. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   java 8   lambda expressions   doublesummarystatistics   intsummarystatistics   longsummarystatistics   summarystatistics | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/migrating-to-java-8-new-classes_62.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java 8   java.io   java8 | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/migrating-to-java-8-new-classes_25.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java.util   util   java 8   java8 | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
Ans. http://www.buggybread.com/2015/01/migrating-to-java-8-new-classes.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java.lang   java8   java 8 | ||||
Rarely 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 features | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
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 | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
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. | ||||
| ||||
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 | ||||
| ||||
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error. For example - interface MyInterface { public void default myMethod(){ } } interface MyInterface2 { public void default myMethod(){ } } class MyClass implements MyInterface,MyInterface2 { } This code will compilation error "Duplicate Default Method" if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  default methods  java 8  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem   interfaces | ||||
Rarely asked as it was introduced with Java 8. | ||||
| ||||
Ans. We can refer to a function using this operator like System.out.println(intList.stream().reduce(Math::max).get()); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  :: operator   lambda expression  java 8 | ||||
| ||||
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 | ||||
| ||||
Ans. Introduced with java 8 , Method References help us to point to methods by their name. A method references is described using :: symbol | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  method reference  java 8  lambda expressions | ||||
| ||||
This question was recently asked at 'IBM'.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  synchronization  concurrency  java 8  java8 Asked in 1 Companies | ||||
| ||||
Ans. set1.stream().filter(p->p.element1.equals("Hello")).findAny().isPreent(); or set1.stream().map(A::getElement1).anyMatch("Hello"::equals) | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  lambda expressions  java 8  java8  java 8 filter  findAny() | ||||
| ||||
Ans. List emp = Arrays.asList("American", "Indian", "Finn"); emp.stream().filter(em -> em.startsWith("A")).forEach(System.out.println); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java8  java 8  lambda Asked in 1 Companies | ||||
| ||||
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 | ||||
| ||||
Ans. Create interface with the only one non-overriding abstract method and annotate it with @FunctionalInterface | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  functional interface  java 8 Asked in 1 Companies | ||||
| ||||
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 | ||||
| ||||
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 | ||||
| ||||
Ans. String str = "I had been saying that he had been there"; Map<String,Long> countWords = Arrays.asList(str.split(" ")).stream().filter(p->p.length() = 5).collect(Collectors.groupingBy(p->p,Collectors.counting())); System.out.println(countWords); | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  Collectors  lambda  filter  coding  java 8 | ||||
| ||||
Ans. Filters are used to filter object in stream on certain criteria. Collector is used to collect outcome of the stream. Collector is a terminal operation. List numbers = List.of(1,2,3,4,5,6,7); List evenNumbers = numbers.stream().filter(n -> n%2==0).collect(Collectors.toList()); The above code will filter out odd numbers and return the list of even number. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  collectors  filters  java 8 | ||||