Skip to main content

Posts

Showing posts from October, 2022

Interview Sorting Program Using Stream Java 8

Output :

Lambda Expressions

Lambda Expression  As we have seen in our last article Functional interface is introduced in Java 8 to support Lambda expression. today we will understand lambda expression : Lambda expression implement Functional Interfaces , it save lot of code. Check Example : WITHOUT LAMBDA EXPRESSION : below is same example , but using lambda expression ,in this lot of code is saved as below Lambda expression is nothing but method without name , access modifier and return type , it contain 3 main parts : 1.Parenthesis ( ) for method arguments , it can be non-empty or empty as per requirement. 2.Arrow Symbol -> indicates lambda expression  (to link method parameters or parenthesis with body). 3.Body (use curly braces for multiple lines , or if only one statement is there then curly braces are optional)  Syntax :  1.Syntax without method arguments :    () -> { } 1.Syntax with arguments :    (a1,a2) -> { } Example :check one more example to understand l...

What is Functional Interface ?

 Functional Interface Definition An Interface which contains only one abstract method but can have multiple default and static methods is called as Functional interface . Functional interface is introduced in Java 8 to support Lambda expression. We can use annotation @FunctionalInterface on top of normal interface to make it Functional interface. Examples : Runnable ,Callable, Comparable are some of example of Functional interface in Java In Java 8 , 4 main functional interfaces are introduced which could be used in different scenarios : Consumer, Predicate, Function , Supplier . We can create our own Functional Interface as below : If we write two abstract methods in Functional Interface then we get Error as :  Invalid '@FunctionalInterface' annotation; FunctionalInterfaceExample is not a functional interface Above code is giving error because two abstract methods are there in our Functional Interface ,which is not allowed. In next session we will understand Lambda Expr...

How to install java software or steps to install jdk

If you want to Install Java Software firstly you should download it from Oracle official website : follow this link to Download Java Software  Steps To Download Java Software   Once Java Software Downloaded then follow below steps to install it : steps to install JDK software STEP by STEP : 

Variables In Java

A Variable is a name given to memory location or container, which is used to hold value while Java Program is executed. 1>Syntax To Declare Variable In Java : DataType variableName; Example : String  nameOfDepartment; 2>Syntax To initialize Variable : DataType  variableName=value; Example :  String  nameOfDepartment="Computer Application"; You can also write in two lines as below : String nameOfDepartment; //declaration nameOfDepartment="Computer Application"; //initialization Types Of Variables In Java :  1>Instance Variable(non-static) 2>Local Variable 3>Static Variable 1>Instance Variable(non-static) :   a class level non-static variable declared inside class , outside method. Its value is instance specific and not share among other instances. 2>Local Variable :   variable declared within method itself , other methods can;t access it , a local variable can not be static. 3> Static Variable :   static variable memory all...