Showing posts with the label Java certification

Implement functional interfaces using lambda expressions

Java is Object Oriented Programming language , being object-oriented is not bad, but it brings a lot of verbosity to the program. Java 8 introduced new libraries and programming styles, for example,  functional interfaces ,  lambda expressions , and streams . These bring functional-style programming to the object-oriented programming capabilities of Java. Java Functional Interface and Lambda Expression help us in writing smaller and cleaner code by removing a lot of boilerplate code. Java Functional Interface: A functional interface in Java is an interface that contains only a single abstract method.  A functional interface can contain default and static methods which do have an implementation, in addition to the single unimplemented method. Here is a Java functional interface examples: Example 1, The below counts as a functional interface in Java because it only contains a single method, and that method has no implementation: public interface Addition { public Integer calcula

Understand Variables and its Scope in Java

Hello everyone, In this article, we will learn the types of Variables and its Scope in Java. A variable is a container that holds values that are used in a Java program. Every variable must be declared to use a data type. Variable Declaration: For example, int age; float pi; double salary; char code; Variable Initialization: To initialize a variable, you must assign it a valid value. Here, the container named 'score' holds a value of 49. For example, age = 49; pi = 3.14; salary = 456734.345; code = 'A'; Variable declaration and initialization: To initialize a variable, you must assign it a valid value. int age = 49; float pi = 3.14; double salary = 456734.345; char code = 'A'; Types of Variables and its Scope: There are three types of variables.  Instance Variables  Class Variables/Static Variable Local Variables  Instance Variables: An instance variable is a non-static variable defined in a class outside any method, constructor or block in which each instantiat