public static void main(String[] args) throws IOException { List allUser = Arrays.asList ( new Welcome ("Amit", "Kumar"), new Welcome ("Amit", "Jain"), new Welcome ("Vineet", "Sinha")); List sortedUser = allUser.stream() //n1
Correct Answer : Get Lastest Questions and Answer : Explanation: As you can see output of the code, it clearly says that output sorted in descending order by first name and ascending order by last name.
Comparator java.util.Comparator.thenComparing(Function super Welcome, ? extends String> keyExtractor)
Returns a lexicographic-order comparator with a function that extracts a Comparable sort key.
Stream java.util.stream.Stream.sorted(Comparator super Welcome> comparator)
Returns a stream consisting of the elements of this stream, sorted according to the provided Comparator. For ordered streams, the sort is stable. For unordered streams, no stability guarantees are made. This is a stateful intermediate operation. Parameters: comparator a non-interfering, stateless Comparator to be used to compare stream elements
Question : You have been given below code
package com.hadoopexam;
public enum INR { RS1(100), QUARTERRS(25); private int value;
public INR(int value) { this.value = value; }
public int getValue() { return value; } }
package com.hadoopexam;
public class Coin {
public static void main(String[] args) { INR inr = new INR.QUARTERRS; System.out.println(inr.getValue()); } }
There seems to be a compile time error. How, will fix it?
A. Remove new keyword from this line INR inr = new INR.QUARTERRS; B. Correct statement as INR inr = new INR.QUARTERRS(); C. Keep INR class as subclass of Coin class. D. Change the access modifier public to private for INR(int value) 1. A,B 2. B,C 3. Access Mostly Uused Products by 50000+ Subscribers 4. A,D 5. B,D
Enums are implicitly declared public, static, and final, which means you cannot extend them.
When you define an enumeration, it implicitly inherits from java.lang.Enum. Internally, enumerations are converted to classes. Further, enumeration constants are instances of the enumeration class for which the constant is declared as a member.
You can apply the valueOf() and name() methods to the enum element to return the name of the enum element.
If you declare an enum within a class, then it is by default static.
You cannot use the new operator on enum data types, even inside the enum class
You can compare two enumerations for equality using == operator.
If enumeration constants are from two different enumerations, the equals() method does not return true.
When an enumeration constant's toString() method is invoked, it prints the name of the enumeration constant.
The static values() method in the Enum class returns an array of the enumeration constants when called on an enumeration type.
Enumeration constants cannot be cloned. An attempt to do so will result in a CloneNotSupportedException.
Question : You have been given below code, what is expected behavior?
package com.hadoopexam;
class PDFScanner implements AutoCloseable { public void close() throws Exception { System.out.print("3 Scanner closed, "); }
public void scanPDF() throws Exception { System.out.print("1 PDF Scanner , "); throw new Exception("2 Unable to scan, "); } }
package com.hadoopexam;
class PDFPrinter implements AutoCloseable { public void close() throws Exception { System.out.print("5 Printer closed, "); }
public void printCoursePDF() { System.out.print("4 Print pdf, "); } }
Correct Answer : Get Lastest Questions and Answer : Explanation: Both of the classes instances will be created in try block. try (PDFScanner courseScanner = new PDFScanner(); PDFPrinter taskPrinter = new PDFPrinter())
Next it will call courseScanner.scanPDF();
It prints : 1 PDF Scanner ,
Then it will throw throw new Exception("2 Unable to scan, ");
It will call the reverse order of close() method for each resources opened in try block. Hence, Printer will be closed first. "5 Printer closed" then Scanner will be closed "3 Scanner closed" and then main method exception block will be called.
You cannot assign to the resource variables declared in the try-with-resources within the body of the try-with-resources statement. This is to make sure that the same resources acquired in the try-with-resources header are released in the finally block.
It is a common mistake to close a resource explicitly inside the try-with-resources statement. Remember that try-with-resources expands to calling the close() method in the finally block, so the expanded code will have a double call to the close() method if you explicitly provide a close() method.
The documentation of the close() method in the Scanner class says that if the scanner object is already closed, then invoking the method again will have no effect. So, you are safe in this case. However, in general, you cannot expect all the resources to have implemented a close() method that is safe to call twice. So, it is a bad practice to explicitly call the close() method inside a try-with-resource statement.
Which of the following statement is correct? 1. In character streams (e.g. HadoopExam.com), data is handled in terms of bytes (e.g. 0100001001), in byte streams, data is handled in terms of Unicode characters e.g. UTF-8. UTF-16.
2. Character streams are suitable for reading or writing to files such as executable files, image files, and files in low-level file formats such as .zip, .class, and .jpg.