Skip to content

Latest commit

 

History

History
134 lines (126 loc) · 5.81 KB

README.md

File metadata and controls

134 lines (126 loc) · 5.81 KB

Java CI with Gradle

java8

Interface

  • default methods - it has implementation and can be overridden in implemented classes
  • static methods - it has implementation and cannot be overridden in implemented classes
  • multiple inheritance

Functional Interface - @FunctionalInterfaces doesn't make interfaces are functional, only if interface has only one method other than default and static methods

New Functional Interfaces in Java 8

  • Lambda = (method parameters)->{method definition}
  • Method Reference - a shorcut to Lambdas = className::methodName

java.util.functions

  • Consumer, BiConsumer
  • Function, BiFunction, UnaryOperator, BinaryOperator
  • Predicate, BiPredicate
  • Supplier

java.util.streams

  1. add or remove operations can be done on collections only
  2. add or remove operations cannot be done on streams students.stream().add students.stream().re
  3. Collections can get particular object
  4. Streams cannot get any particular object log.info(students.stream().get);
  5. Streams are lazy performed - intermediate operations cannot be performed if terminal operations are not performed
  6. intermediate operations are filters
  7. terminal operations are collect
  8. Collections are eagerly construct
  9. Stream are lazy construct only invoke if terminal operations
  10. Collections are travers multiple times
  11. Stream are travers only once
  12. Collections iterate external
  13. Stream iterate internal
  14. studentGradeGreaterThan3Stream.collect(Collectors.toList()).forEach(s->log.info(s.toString()));
  15. it has been closed or stopped

operations java.util.streams

  1. map - convert one collections to another collection
  2. flatMap - convert map into flatMap i.e., Stream<List<String>> into Stream<String> - remove List into single group
  3. peek - returns the current Stream
  4. max - return max object by Comparator
  5. min - return max object by Comparator
  6. collect - convert stream into collections
  7. reduce - reduce the stream into single object by BinaryOperator
  8. allMatch - all objects should match in given stream for given predicate
  9. anyMatch - any objects should match in given stream for given predicate
  10. noneMatch - none objects should match in given stream for given predicate
  11. findAny - return first enumerated object, can also provide sorting
  12. findFirst - return first object, can also provide sorting
  13. limit - stream objects have been limited of given number
  14. skip - rest of stream objects have been skipped of given number
  15. count - return the objs count in current stream
  16. sorted - return the objs in sorting order by Comparator in current stream
  17. distinct - returns stream of distinct objects by Comparator
  18. filter - filter stream by Predicate

short-circuiting

if(boolean1 && boolean2) // boolean2 will not be evaluated if boolean1 is false if(boolean1 || boolean2) // boolean2 will not be evaluated if boolean1 is true in Streams limit(), skip(), findAny(), findFirst(), anyMatch(), allMatch(), noneMatch() are short-circuiting operations these are not operated on each object in the stream

Stream static methods - create

  1. Stream.of(var args of Objects)
  2. Stream.iterate(seed,unaryOperator)
  3. Stream.generate(supplier)

Numeric Streams

  1. IntStream - range,rangeClosed,sum,count,min,max,average,asDoubleStream,summaryStatistics,boxed,mapToObj
  2. LongStream - range,rangeClosed,sum,count,min,max,average,asDoubleStream,summaryStatistics,boxed,mapToObj
  3. DoubleStream - sum,count,min,max,average,summaryStatistics,boxed,mapToObj

Terminal Operations

  • joining
  • counting
  • mapping
  • maxBy
  • minBy
  • summingInt, summingLong, summingDouble
  • averageInt, averageLong, averageDouble
  • groupingBy - classifier | classifier,downstream | classifier,supplier,downstream
  • partitionBy

Parallel Streams

  1. runs parallel depends on number of processors in the machine
  2. results vary on mutable objects
  3. performance is not better for operations on boxed objects

Optionals

  1. Of
  2. OfNullable
  3. Empty
  4. get
  5. orElse
  6. orElseGet
  7. orElseThrow
  8. isPresent
  9. ifPresent

java.time

  1. LocalDate
  2. LocalTime
  3. LocalDateTime
  4. Period - ComparingDates
  5. Duration - ComparingTimes
  6. Instant - DateTime From EPOCH 01-01-1970
  7. ZonedDateTime | ZoneId | ZoneOffSet
  8. DateTimeFormatter - parse String to LocalDate|LocalTime|LocalDateTime and format LocalDate|LocalTime|LocalDateTime to String

End of the file