Posts

Showing posts from April, 2024

3. Java 8 and Java 8 Interview Question

Image
|| Java 8 ||    1. Lambda Expression  - Lambda Expression  is an anonymous function.Its a function without name and does not belongs to any class. (just same like arrow function in Javascript) - Lambda expression is maninly used to implement functional interfaces. - Functional InterFace  - functional interface were introduced in java 8  - AN interface that contains exactly one abstract method is known as a functional interface. - Functional interface can have any number of default , static methods but can contains only one abstract method. - Lambda vs Method  1. Method is always belongs to class or objects in Java where Lambda does not belongs to any class or object. - Method   Have Name, Parameter list , Body , Return type. Ex : public int addition(int a,int b) { return a + b ; } //  2. Lambda  Syntax : addble withLambdaD = (int a, int b) -> (a+b); - No Name : as lambda is an anonymous function so no need to...

2. Spring Annotation

  Basic Spring Interview Question  1. @Component Annotation  -  @Component is a class-level annotation. -   @Component is used for declaring a Java class as a Spring component . - @Component is a stereotype annotation that marks a class as a Spring bean, making it eligible for autodetection and automatic registration in the application context. It's a fundamental annotation in Spring that enables loose coupling and modular architecture. - It's a powerful annotation that simplifies the registration process and allows for easy dependency injection. - @Component is a core annotation in Spring used for marking a class as a Spring component, allowing it to be managed by the Spring IoC container. It plays a crucial role in enabling dependency injection and the inversion of control mechanism provided by the Spring Framework. - The @Component annotation tells Spring container to create Spring bean automatically. So we don't have to create object manua...

1. Collection Framework all in one

  Collections Types of Iterators in Java There are four types of iterators or cursors available in Java. They are as follows: 1. Enumeration: Enumeration is the first iterator that was introduced in Java 1.0 version. It is located in java.util package. It is a legacy interface that is implemented to get elements one by one from the legacy collection classes such as Vector and Properties. Methods of Enumeration  1. public boolean hasMoreElements():When this method is implemented, hasMoreElements() will return true If there are still more elements to extract and false if all the elements have been enumerated. 2. public Object nextElement(): The nextElement() method returns next element in the enumeration. It will throw NoSuchElementException when the enumeration is complete 2. Iterator : An iterator in Java is a special type of object that provides sequential (one by one) access to the elements of a collection object. Iterator Methods in Java 1. public boolean hasNext(...