11 November 2020

#Java-08

Java 8
What were the issues that were fixed with the new Date and Time API of Java 8?
What was wrong with the old date and time?
What is UnaryOperator?
What is Type Inference? Is Type Inference available in older versions like Java 7 and Before 7 or it is available only in Java SE 8?
What is the use of the String::ValueOf expression in Java 8?
What is the use of the peek() method in Java 8?
What is the syntax of a predicate interface in Java 8?
What is the Supplier Functional Interface?
What is the similarity between Map and Flat map stream operation?
What is the purpose of filter method of stream in java 8?
What is the need of static method in Interface?
What is the most common type of Terminal operations?
What is the meaning of functional interfaces in Java 8?
What is the lambda expression in Java and How does a lambda expression relate to a functional interface?
What is the feature of the new Date and Time API in Java 8?
What is the easiest way to print the sum of all of the inumbers present in a list using Java 8?
What is the easiest way to print the current date and time using the new APIs in Java 8?
What is the easiest way to find and remove duplicate elements from a list using Java 8?
What is the easiest way to convert an array into a stream in Java 8?
What is the distinct feature of the Block of Code?
What is the Difference Between Map and flatMap Stream Operation?
What is the difference between limit and skip?
What is the difference between findFirst() and findAny()?
What is the Consumer Functional Interface?
What is the @FunctionalInterface annotation?
What is terminal operation?
What is StringJoiner?
What Is Stream Pipelining in Java 8?
What is statistics collector in Java 8?
What is Spliterator in Java SE 8?
What is skip?
What is Reference to an instance method?
What is Reference to a static method?
What is Reference to a constructor?
What is PremGen? Do we have PermGen in Java 8?
What is Predicate and BiPredicate interface?
What is peek?
What is Optional?
What is Optional in Java 8? What is the use of Optional?Advantages of Java 8 Optional?
What is Optional in Java 8?
What is Operator?
What is Nashorn?
What is Nashorn, JavaScript Engine?
What Is Nashorn in Java8?
What is Multiple Inheritance? How Java 8 supports Multiple Inheritance?
What is MetaSpace? How does it differ from PermGen?
What Is map?
What is LocalTime?
What is LocalDateTime APIs?
What is LocalDate?
What is limit?
What Is JJS?
What is Internal Iteration?
What is intermediate operation? What are the most commonly used Intermediate operations?
What is Function? BiFunction, UnaryOperator, BinaryOperator?
What is Function?
What is flatmap?
What is Filter operation?
What is External Iteration?
What is distinct?
What is Diamond Problem in interfaces due to default methods? How Java 8 Solves this problem?
What is Diamond Problem in Inheritance? How does Java 8 solve this problem?
What is default method?
What is Consumer and BIConsumer interface?
What is ChronoUnits in Java 8?
What is BinaryOperator?
What is BiFuction?
What is a type interface?
What Is a Stream? How Does It Differ from a Collection?
What is a stream, and how does it differ from a collection?
What is a Stream API? Why do we require the Stream API?
What is a Static Method? Why do we need Static methods in Java 8 Interfaces?
What is a lambda expression? Type? Feature?
What is a Functional Interface? What is SAM Interface?
What is :: (double colon) operator-Method References in Java 8?
What does the String::ValueOf expression mean?
What does the peek() method does? When should you use it?
What does the flatmap() function do? Why do we need it?
What do you mean by chromounits in java8?
What are type annotations? Name some common type annotations.
What are the various categories of pre-defined function interfaces?
What are the types of Method References available in java 8
What are the types and common ways to use lambda expressions?
What are the sources of data objects a Stream can process?
What are the similarities between map and flatMap stream operations in Java 8?
What are the main components of a Stream?
What are the important packages for the new Data and Time API?
What are the guidelines that are needed to be followed in Functional Interface?
What are the features added in Date Time API?
What are the defining rules of a functional interface?
What are the core API classes for date and time in Java 8?
What are static methods in Interfaces?
What are some standard Java pre-defined functional interfaces?
What are some of the examples of terminal operations in Java 8?
What are repeating annotations?
What are functional or SAM interfaces?
What are different ways to create Optional?
What are default methods in Java 8?
What are collectors in Java 8?
What are the advantages of Java 8’s Date and Time API over Old Date API and Joda Time API?
Is it possible to provide method implementations in Java Interfaces? If possible, how do we provide them?
Is it possible to define our own Functional Interface? Explain the rules to define a functional interface.
Is it possible to create a custom functional interface in Java 8?
Is it possible to call a static method of any interface in a class using Java 8?
Is is possible to define our own Functional Interface? What is @FunctionalInterface? What are the rules to define a Functional Interface?
If there is a conflict between Base Class Method definition and Interface Default method definition, which definition is picked?
How will you get current date and time using Java 8 Date and TIme API?
How to remove the duplicate elements from the list.
How to join the all employee names with “,” using java 8?
How to group by employee name from the list?
How to filter all the employee whose age is greater than 20 and print the employee names using java 8
How to count number of employees with age 18?
How is the Parameter List of Lambda Expression different from the Lambda Arrow Operator?
How is a Base64 encoder that encodes URLs created in Java 8?
How is a Base64 decoder created in Java 8?
How do we find maximum age of employee?
How do sort all the employee on the basis of age?
How can you print the date of the next occurring next weekdays using Java 8?
How are Collections different from Stream?
Ho do we find the employee with name “Tommy”.
Differentiate between findFirst() and findAny() in the Stream API of Java 8.
Differentiate between Collection API and Stream API in Java 8.
Describe Some of the Functional Interfaces in the Standard Library.
Can you name the common types of functional interfaces in the standard library?
Can you give examples of intermediate operations in Java 8?
Can you briefly explain the working of the random keyword in Java 8?
Can we list the numbers and remove the duplicate elements in the list using Java SE 8 features?
Can we have a generic functional interface?
Can we have a default method definition in the interface without specifying the keyword "default"?
Can JavaScript code be executed from Java 8 codebase?
Can a functional interface extend/inherit another interface?
Difference between Iterator and Spliterator?
Difference - Predicate and Function?
Difference - PermGenSpace and MetaSpace
Difference - Map and FlatMap stream operation
Difference - Java’s OLD Java Date API vs Java 8’s Date and Time API?
Difference - Intermediate Operations and Terminal Operations
Difference - Functional Programming and Object-Oriented Programming?
Difference - findFirst() and findAny()
Difference - Collection API and Stream API?
Difference - Internal iteration and External iteration?
Explain local datetime API in Java8?
Why was a new version of Java needed in the first place?
Why lambda expression is called a poly expression?
Why do we need new Date and Time API in Java SE 8?Explain how Java SE 8 Data and Time API solves issues of Old Java Date API?
Why do we need change to Java again?
Which class implements the encoder used for encoding byte data in Java 8?
When do we need to use Internal Iteration? When do we need to use External Iteration?
When do we go for Java 8 Stream API? Why do we need to use Java 8 Stream API in our projects?
Topic
Lambda expression
  • Lambda expressions have three parts: a list of parameters, and arrow, and a body: (Object o) -> System.out.println(o);
  • It is a way to create an anonymous function
  • It can have zero (represented by empty parentheses), one or more parameters.
  • To help iterate, filter and extract the data
  • Internally it using functional interface
  • It treated as function. So compiler will not create.class file
  • A lambda expression can have zero, one or more parameters.
  • If the lambda expression doesn't return a result, a return statement is optional.
  • However, lambda expressions don't contain the information about which functional interfaces are implementing.
Method references
  • Reference to a static method
  • Reference to an instance method
  • Reference to a constructor
Functional interface
  • An Interface that contains exactly one abstract method is known as a functional interface.
  • It can have any number of default, static methods but can contain only one abstract method. It can also declare the methods of the object class.
  • Functional Interface is also known as Single Abstract Method Interfaces or SAM Interfaces.
  • An empty interface is not considered a functional interface.
  • A functional interface can extend another interface only when it does not have any abstract method.
  • The Java API has many one-method interfaces such as Runnable, Callable, Comparator, ActionListener, and others.
  • Chain function
  • Types
    • Function - BiFunction
    • Consumer - BiConsumer
    • Predicate -BiPredicate
    • Supplier
Stream API
  • Stream does not store elements
  • A pipeline is a sequence of aggregate operations.
  • It simply conveys elements from a source such as a data structure, an array, or an I/O channel, through a pipeline
  • Stream is lazy and evaluates code only when required.
  • The elements of a stream are only visited once during the life of a stream. Like an Iterator, a new stream must be generated to revisit the same elements of the source.
  • Intemediate operations (Pipelining) - Most of the stream operations return stream itself so that their result can be pipelined.
    • Zero or more intermediate operations
    • map()
    • filter()
    • sorted()
    • limit()
    • skip()
    • flatmap()
  • Terminal operations
    • foreach
    • collect
    • Reduce
    • count
    • allMatch()
    • nonMatch()
    • anyMatch()
    • min()
    • max()
  • Parallel stream
  • DoubleSummaryStatistics
  • Automatic iterations
Default method
  • Interfaces can have default methods with implementation in Java 8 on later.
  • Interfaces can have static methods as well, similar to static methods in classes.
  • Default methods were introduced to provide backward compatibility for old interfaces so that they can have new methods without affecting existing code.
Optional clause
  • Null checks are not required.
  • No more NullPointerException at run-time.
  • No more Boilerplate code
  • Methods
    • get() : If a value is present in this Optional, returns the value, otherwise throws NoSuchElementException.
    • isPresent() : This method returns an Optional with the specified present non-null value.
    • empty() : This static method returns an empty Optional instance. No value is present for this Optional.
    • ifPresent() : If a value is present, invoke the specified consumer with the value, otherwise, do nothing.
    • orElse() : Return the value if present otherwise returns another.
    • orElseGet() : Return the value if present, otherwise invoke other and return the result of that invocation.
    • orElseThrow() : Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
Java Data/Time API
  • LocalDate - A LocalDate represents a year-month-day in the ISO calendar and is useful for representing a date without a time
  • YearMonth - The YearMonth class represents the month of a specific year.(YearMonth.lengthOfMonth())
  • MonthDay - The MonthDay class represents the day of a particular month, such as New Year's Day on Jan 1.
  • Year - The Year class represents a year
  • Other Class
    • ChronoUnit
    • TemporalAdjusters
Base64
Collection API improvements
  • Iterator default method forEachRemaining(Consumer action) to perform the given action for each remaining element until all elements have been processed or the action throws an exception.
  • Collection default method removeIf(Predicate filter) to remove all of the elements of this collection that satisfy the given predicate.
  • Collection spliterator() method returning Spliterator instance that can be used to traverse elements sequentially or parallel.
  • Map replaceAll(), compute(), merge() methods.
  • Performance Improvement for HashMap class with Key Collisions
Java IO improvements
  • ConcurrentHashMap compute(), forEach(), forEachEntry(), forEachKey(), forEachValue(), merge(), reduce() and search() methods.
  • CompletableFuture that may be explicitly completed (setting its value and status).
  • Executors newWorkStealingPool() method to create a work-stealing thread pool using all available processors as its target parallelism level.
Collectors
  • Collectors is a final class that extends the Object class.
  • Methods
    • Collectors.toList()
    • Collectors.toSet()
    • Collectors.summingDouble()
    • Collectors.averagingDouble()
    • Collectors.counting()
Other
  • ThreadLocal static method withInitial(Supplier supplier) to create instances easily.
  • The Comparator interface has been extended with a lot of default and static methods for natural ordering, reverse order, etc.
  • min(), max() and sum() methods in Integer, Long and Double wrapper classes.
  • logicalAnd(), logicalOr() and logicalXor() methods in Boolean class.
  • ZipFile.stream() method to get an ordered Stream over the ZIP file entries. Entries appear in the Stream in the order they appear in the central directory of the ZIP file.
  • Several utility methods in Math class.
  • jjs command is added to invoke Nashorn Engine.
  • jdeps command is added to analyze class files
  • JDBC-ODBC Bridge has been removed.
  • PermGen memory space has been removed

No comments:

Post a Comment

Most views on this month