{"id":18364590,"url":"https://github.com/mukul273/advanced_java","last_synced_at":"2025-04-10T10:09:15.186Z","repository":{"id":177639523,"uuid":"311465339","full_name":"mukul273/Advanced_Java","owner":"mukul273","description":"Advanced Java course that covers Java 8 - Java 13","archived":false,"fork":false,"pushed_at":"2020-12-03T05:34:42.000Z","size":101,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-15T19:49:04.657Z","etag":null,"topics":["collectors","consumer","filter","filtering","functional","interfaces","java","java-8","java-course","java8","javase","javastreams","lambda-expression","parallelstreams","predicate","reduce"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mukul273.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-09T21:07:46.000Z","updated_at":"2020-12-03T05:34:44.000Z","dependencies_parsed_at":"2023-12-10T05:45:09.354Z","dependency_job_id":null,"html_url":"https://github.com/mukul273/Advanced_Java","commit_stats":null,"previous_names":["mukul273/advanced_java"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukul273%2FAdvanced_Java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukul273%2FAdvanced_Java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukul273%2FAdvanced_Java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mukul273%2FAdvanced_Java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mukul273","download_url":"https://codeload.github.com/mukul273/Advanced_Java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198886,"owners_count":21063628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collectors","consumer","filter","filtering","functional","interfaces","java","java-8","java-course","java8","javase","javastreams","lambda-expression","parallelstreams","predicate","reduce"],"created_at":"2024-11-05T23:11:01.451Z","updated_at":"2025-04-10T10:09:15.168Z","avatar_url":"https://github.com/mukul273.png","language":"Java","readme":"# Advanced Java\nAdvanced Java course covering Java 8 through Java 13\n\n### Imperative programming:  \nThis programming approach is about how a program should be executed step by step\n\n### Declarative programming:  \nThis approach is about not necessarily how but what should be executed\n\n### What is Lambda expression:\nLambda expression is an anonymous function without a name that doesn't belong to any class.\n\n    Method                  |           Lambda Expression\n    ------------------------------------------------------\n    Name                    |           No Name\n    Parameters List         |           Parameters list\n    Body                    |           Body (main part)\n    return type             |           No return type(JVM infers the return type by scanning the code)               \n    \n    General Syntax\n    ()              -\u003e          { }\n    Lambda         Arrow        Lambda \n    Input          denoting     Body\n    Parameters     Lambda\n\nAny interface with Single Abstract method is a functional interface and implementation may be treated as lambda expression\n\n```@FunctionalInterface``` annotation denotes that method can be treated as lambda expression.  \nFunctional interface have default and static methods which have an implementation  \nIt also means the interface has ONLY one abstract method  \n\n### Consumer interface: \nIt is a part of java.util.function package  \nIt takes one argument and produces the result, it doesn't return any result  \n\n### BiConsumer Interface\nIt takes two arguments, BiConsumer does not return value. \n\n### Predicate interface:  \nIt's a single argument function that returns true or false\n\n### BiPredicate interface:  \nIt's a functional interface which accepts two argument and returns Boolean value.  \nApply business logic for the values passed as an argument and return the boolean value.\n\n### Function Interface\nIt takes one argument and produces results.\n\n### BiFunction Interface\nIt takes two arguments and produces results.  \nWhile declaring BiFunction we need to tell what type of argument will be passed and what will be \nreturn type. We can apply our business logic with those two values and return the result.\n\n### UnaryOperator Interface\nIt's an interface where the operand and result are of same type. It extends from Function interface.\nThere are IntUnaryOperator, LongUnaryOperator and DoubleUnaryOperator types.\n\n## BinaryOperator Interface\nIt takes two params and return single value  \nBoth params must be of same type so is return type  \nGenerally used for mathematical use cases  \nIntBinaryOperator, LongBinaryOperator, DoubleBinaryOperator are specific interfaces  \n\n### Supplier Interface\nThis is opposite of Consumer Interface  \nThis is a factory interface  \n\n### Method reference\nEach time if the lambda expression is referring the method then it can be relaced with method reference  \nFor e.g: String -\u003e System.out.print(str) can be replaced like System.out::print  \nTypes:  \nClass:: staticMethod() // Reference to static method\nobject::instanceMethod // Reference to an instance method\nClass::new // Reference to constructor\n\n### Variable scope\nThe body of lambda has same scope as nested block  \nWe can't declare param name to lambda function and local var name as same  \nEffect Final: This means that local var can't be modified in the lambda function even though they are   \nnot declared as final  \n\n### Stream\nStream is a sequence of objects that support various methods and can be pipelined to produce result  \nStream supports Map-reduce-filter transformation on collection  \n** Streams are effective only when terminating operation is executed. For e.g. .collect(...)  \n\n\n    Collection                  |           Streams\n    --------------------------------------------------------------\n    Used for storing and        | Used for performing operation on \n    grouping the data           | input from collection\n                                |\n    Can add/remove elements     | Can't add/remove elements\n                                |\n    Have to be iterated         | Streams are internally iterated\n    Externally                  |\n\n    Can be traversed multiple   | Streams are traversed only once\n    times                       |\n    \n    Eagerly constructed         | Lazy construction\n    E.g. List, map, Set,        | e.g. Filtering, mapping, reduce\n\nDebugging the Stream can be done in two ways:\n1. Run the code in debug mode and then open up the \"Trace Current Stream Chain\" option (Intellij)  \n2. use peek() to check the state of that stream at that point  \n\n### MAP\n1. It converts stream of x to stream of y  \n2. It's a internmediate operation and return stream as method return  \n\n### FlatMap  \n1. It's a combination of MAP and Flat operation,\n2. Used for flatten the stream,\n\n#### distinct()\nMethod to filter or collect all distinct elements from the collection\n#### count()\nReturns the count of elements in the stream\n#### sorted()\nSorted order of elements based on natural order\n#### anyMatch()\nreturns whether any element of this stream match the provided predicate\n#### allMatch()\nreturn whether all elements of this stream match the provided predicate\n#### noneMatch()\nreturns whether no elements of this stream match the provided predicate\n#### filter(Predicate)\nStream filter with Predicate argument returns the stream of elements matching the given predicate  \n** This filter is lazy operation meaning, filter doesn't actually perform any filtering \nbut instead creates a new stream that when traversed contains the elements of the initial stream \nthat matches the predicate  \n\n## Reduce\nReduce the repeated process of combining all elements  \nIt takes an input of elements and combines them into single result by combining operations  \nlike sum, multiplication, division etc.  \nT reduce(identity, BinaryOperator)  \nOptional reduce(BinaryOperator)  \n\nOptional is a container object which may or may not contain a non-value  \n\n#### limit()\nIt takes one (long) argument and returns the stream of size number more than n\n\n#### skip(s)\nIt takes one long (n) as argument and returns a stream after removing first n elements  \n\n#### findFirst()\nIt returns an Optional Object containing first element of the stream OR an empty Optional  \nObject\n\n#### findAny()\nIt returns an Optional Object containing any one element of the stream OR an empty Optional \nObject  \n\nFactory Methods  \n#### of()  \nUsed for creating stream from similar type of data  \n\n#### Iterate()\nUsed to generate an infinite sequential ordered stream produced by  \niterative application of the provided UnaryOperator. The seed is initial element of iteration.  \n\n#### generate()\nUsed to generate an infinite sequential unordered stream where each element is  \ngenerated by the provided Supplier.\n\n## Numeric Streams\n### IntStream, LongStream abd DoubleStream\nThese streams are for primitive streams respectively for integer, long and double  \n\n## Numeric Streams Aggregate Functions\nsum(), max(), min(), average()\n\n### Boxing()\nConverting a primitive to a wrapper class object type is boxing\n\n### UnBoxing()\nConverting a wrapper object type to a primitive type is unboxing\n\n### Reference Documentation\nFor further reference, please consider the following sections:\n\n### mapToObj()\nIt returns an object valued Stream\n\n### mapToLong()\nIt returns LongStream consisting of the results of the given function\n\n### mapToDouble()\nIt returns DoubleStream consisting of the results of the given function\n\n### Joining()\nIt concatenates the input elements into string in encounter order\n\n### Joining(CharSequence delimiter)\nIt concatenates the input elements into String separated by the specified delimiter\n\n### Joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix)\nIt concatenates the input elements separated by the specified delimiter with specified prefix and suffix in the encounter order  \n\n### Counting()\nCount the no of elements in a stream\n\n### Mapping()\nCollectors class mapping() method takes a function and collector and creates a new collector which apply  \nthe function and then collects the mapped elements using the given collectors\n\n### minBy() and maxBy()\nminBy returns the collector that produces the minimal elements according to a given comparator  \nmaxBy returns the collector that produces the maximum elements according to a given comparator\n\n### Collectors.summingInt() and Collectors.averagingInt()\nsummingInt() returns a collector that constructs sum of the integer valued function applied to input elements  \naveragingInt() returns a collector that constructs average of the integer valued function applied to input elements\n\n### groupingBy()\nThis method provides functionality similar to groupBy in SQL. Output is Map(K,V)\nThere are 3 factory methods  \ngroupingBy(classifier)  \ngroupingBy(classifier, downstream)  \ngroupingBy(classifier, mapFactory, downstream)  \n\n### Collectors.partitioningBy() \nThis method is used to partition a stream of objects based on a given predicate  \nFactory methods()  \npartitioningBY(predicate) returns the Map\u003cBoolean, List\u003cT\u003e\u003e  \npartitioningBY(predicate, downstream) returns the Map\u003cBoolean, List\u003cT\u003e\u003e  \n\n# ParallelStreams\nParallel stream leverages multicore processors resulting in a substantial increase in performance  \nThis uses fork/join framework  \nThere are 2 ways to achieve parallel streams  \n1. calling parallelStream() on collection\n2. Calling parallel() on stream\n\n### Optional  \nThis class is in util package and help to avoid null checks  \nFactory methods are  \n### OrElse(), OrElseGet(), OrElseThrow()\nOrElse - get the value if present or returns the alternative value  \nOrElseGet - get the value or gets the supplier value  \nOrElseThrow - throw the exception produced by supplier function or else return the value  \n\n## Hierarchy of interfaces\noverloaded/overridden methods are always executed in following order  \nFirst from the class implementing then from the sub interfaces(child interfaces) and then from parent interfaces  \n\n### Instant\nAn instant is defined as an instant in teh datetime continuum specified as a number of milliseconds from  \n1970-01-00.00.00.000000000  \nThis represents the start of the nanosecond on teh timeline.\n\n## JShell\nJShell was introduced in Java 9. It's a interactive tool for learning and prototyping Java code.  \nREPL: Read-Evaluate-Print-Loop can help flatten out the learning curve of Java  \nIt shows the results as we code. The evaluation of code happens as we type.\nREPL is used for writing and testing small code snippets  \nIntellij gives JShell console built under tools menu. \n\n### Module System\nJava 9 introduced an abstraction layer on top of packages which is called Java Platform Module System  \njava --list-modules to list the modules in JDK  \n\n### Try-with-resources\nit is a try statement that declares one or more resource(s)  \nResource is an object that must be closed after the program is finished with  \ntry-with-resource makes sure that the resource is closed  \nResource should implement AutoClosable OR java.io.Closeable  \n\n### Type interference with var\nStarting Java 10 we can drop explicitly referring the variable type depending upon whether compiler can infer the type  \nRemember class level var(s) is not allowed, only local var as in method  \n\n\n### Garbage Collection\nG1 Garbage first collection algorithm is improved with it's worst case latency (Parallel full GC)  \n\n### Switch Expressions\nThese are different from switch statements. No boiler plate code, no break statements.\n\n### Text block\nDenoted by \"\"\" (3 quotes)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmukul273%2Fadvanced_java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmukul273%2Fadvanced_java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmukul273%2Fadvanced_java/lists"}