Default Method

Need for default method- Without effecting implementation classes if we want to add new method to the interface then we can do this with default interface. Syntax:

Output: Default Method Suppose if we want to provide new implementation then we can do this as well. This can be done as…

Continue reading

Lamda_SquareExample

Lamda Expression example for square of int :

Output: Square of 2 is :4 now suppose we put parenthesis in the body as below and try to compile the code using command prompt,

you will get compilation error as below: \basic>javac Lamda_SquareExample.java Lamda_SquareExample.java:13: error: not a statement Interfun…

Continue reading

Lamda_AddExample

Example of Lamda Expression for addition of two int.

Output: Sum is:30 Sum is:300 Similar posts: Java 8 Features Functional Interface Lamda Expression

Continue reading

Lamda Expression

Lamda Expression: Ealier for a function few things were mandatory,such as 1>Access Modifier. 2>Return statement. 3>Name Eg:

  But for a Lamda expression these things are not required,so the above function is written as:

  The Operator that is used to denote the lamda expression is -> Now…

Continue reading

Functional Interface

An Interface which has only one abstract method is known as Functional Interface. It can have any number of default and static method but only one abstract method is allowed. @FunctionalInterface is the annotation used to forcefully tell the compiler that the interface is a FunctionalInterface. Sample code: package com.technicalstack.basic;…

Continue reading

Java 8 Features

Some of the important Java 8 features are; Functional Interfaces and Lambda Expressions default and static methods in Interfaces forEach() method in Iterable interface Java Stream API for Bulk Data Operations on Collections Java Time API Collection API improvements Concurrency API improvements Java IO improvements Similar posts: Top Java Questions…

Continue reading

Serialization and Deserialization in java

Serialization is a process of converting object into a sequences of byte which can be written to disk or database or sent over network to any other running JVM. The reverse process of creating object from sequences of byte is called Deserialization. A class must implement the Serializable interface present…

Continue reading

Collection Interview Questions

How can we make Hashmap synchronized? HashMap can be synchronized by Map m = Collections.synchronizedMap(hashMap); Question 13 : What are IdentityHashMap and WeakHashMap? IdentityHashMap : IdentityHashMap is similar to HashMap except that it uses reference equality when comparing elements. IdentityHashMap class is not a widely used Map implementation. While this…

Continue reading

Thread Local

Thread Local Thread Local can be considered as a thread scope. You can set any object in Thread Local and this object will be global and local to the specific thread which is accessing this object. Values stored in Thread Local are global to the thread, meaning that they can…

Continue reading

Race condition in Java multi-threading

Race condition occurs in a multi-threaded environment when more than one thread try to access a shared resource (modify, write) at the same time. Note that it is safe if multiple threads are trying to read a shared resource as long as they are not trying to change it. Since…

Continue reading