Wednesday, 5 June 2019

What is a Functional interface in Java 8? What does @Functional annotation do?

What is Functional interface in Java 8

Well, a functional interface is nothing but an interface with just one abstract method e.g. Comparable, Runnable, EventListener, Comparator, etc. You can see these interfaces were present in Java even before JDK 8, but why do we call such interface functional interface?

Explain comparable interface in java

By using Comparable we can sort the objects based on any data member. For example, lets say we have an Author class has data members: Author name, book name and author age, now if we want to sort the objects based on any of the data member then we can use Comparable but what if we want to have multiple sort choices and we can sort objects based on any choice, this can be done using

Abstract class in java can’t be instantiated

Because that would contravene their whole purpose.

Abstract classes, by design, are not complete or functional. They are meant to serve as a base from which complete classes can be built, by aggregating the common members and methods that they all will need into an abstract base class, and then allowing the inheriting classes to fill out the necessary

Abstract Class in Java

Abstract class in Java is similar to interface except that it can contain default method implementation. An abstract class can have an abstract method without body and it can have methods with implementation also.

Friday, 31 May 2019

How to create immutable class in Java

An immutable class is one whose state can not be changed once created. There are certain guidelines to create a class immutable in Java.

1. Rules to create immutable classes

Don’t provide “setter” methods — methods that modify fields or objects referred to by fields.

Why Strings are Immutable in Java?

An immutable object is an object which state is guaranteed to stay identical over its entire lifetime. This is really a good definition. Isn’t it? It means that the state of object once initialized, can never be changed anyhow.

What is Marker interfaces in Java and why required

Marker interface in Java is interfaces with no field or methods or in simple word empty interface in java is called marker interface. Example of market interface is Serializable, Clonnable and Remote interface. Now if marker interface doesn't have any field or method or behavior they why would Java needs it?

Wednesday, 29 May 2019

important Interface interview questions

1) Can abstract class have constructors in Java?

Yes, abstract class can declare and define constructor in Java. Since you can not create instance of abstract class,  constructor can only be called during constructor chaining, i.e. when you create instance of concrete implementation class.

What is a Functional interface in Java 8? What does @Functional annotation do?

What is Functional interface in Java 8

Well, a functional interface is nothing but an interface with just one abstract method e.g. Comparable, Runnable, EventListener, Comparator, etc. You can see these interfaces were present in Java even before JDK 8, but why do we call such interface functional interface?

Tuesday, 14 May 2019

Explain Function Overloading and Method Overloading in Java

When in a class, we have more then one method with similar name but with different type signatures i.e. with different number of parameters or with different types of parameters, then we say that the method is overloaded. Compiler will recognize which method to execute on the basis of the type and

What is Abstraction in Java? Abstract Class or Interface

Abstraction in Java: The words "data abstraction" and "information hiding" are generally used interchangeably. The two terms mean the same thing in this context. Abstraction is a simple representation of a complicated situation. It is a technique where we hide irrelevant details and represent only the essential aspects of a context so that one can focus on features one is interested; It helps to deal a complex system by concentrating on the essential features only. It is designed to make

Explain Association, Composition and Aggregation in Java

Association is nothing more than  a connection that exists between two classes.  We use the objects of these classes to set up the connection. Association can be  done in three ways one-to-one, one-to-many and many-to-many. Let’s have a look at an example showing how association is implemented in Java.

Sunday, 12 May 2019

Can you explain how Strings are interned in Java?

String class is designed with the Flyweight design pattern in mind. Flyweight is all about re-usability without having to create too many objects in memory.

Q1. What is the difference between “==” and “equals(…)” in comparing Java String objects?

When you use “==” (i.e. shallow comparison), you are actually comparing the two object references to see if they point to the same object. When you use “equals(…)”, which is a “deep comparison” that

Spring Boot @ConfigurationProperties and Properties File

 In this tutorial, you will learn to use @ConfigurationProperties to map properties files to POJO classes in Spring Boot application. Let’s ...