Found 9313 Articles for Object Oriented Programming

Difference between @Inject and @Autowired

Himanshu shriv
Updated on 09-Sep-2020 09:05:11

7K+ Views

@Inject and @Autowired both annotations are used for autowiring in your application.@Inject annotation is part of Java CDI which was introduced in Java 6, whereas @Autowire annotation is part of spring framework. Both annotations fulfill same purpose therefore, anything of these we can use in our application.Sr. No.Key@Inject@Autowired1BasicIt is part of Java CDIIt is part of Spring framework2RequiredIt has no required attributeIt has required attribute3Default ScopeDefault scope of the autowired beans is SingletonDefault scope of the inject beans is prototype4AmbiguityIn case of ambiguity in beans for injection then @Named qualifier should be added in your code.In case of ambiguity in ... Read More

Difference between Spring AOP and AspectJ AOP

Himanshu shriv
Updated on 09-Sep-2020 09:02:34

445 Views

Sr. No.KeySpring AOPAspectJ AOP1BasicIt is a simple implementation of AOP technology. It can be applied only the beans.It is a complete implementation of the AOP technology in Java. It can be applied in any java class.2Design Pattern  It uses the proxy pattern so aspects are applied on proxies objectIt doesn't use proxy pattern aspects are directly applied on the code.3PontCutsIt supports only method level points cutsNo Restriction4Weaving of AspectsThe weaving of Aspects will be performed by the container at container start-up Weaving of aspect can perform with a post compilation of your code through bytecode modification5Nested MethodAspects can’t be applied when ... Read More

Difference between singleton and prototype bean scope.

Himanshu shriv
Updated on 09-Sep-2020 08:59:54

3K+ Views

Spring framework supports five types of bean scope −SingletonPrototypeRequestSessionGlobal SessionAs per the spring documentation −Singleton − It returns a single bean instance per Spring IoC container. This single instance is stored in a cache of such singleton beans, and all subsequent requests and references for that named bean return the cached object.Spring singleton is different than Java singleton. In java, one instance of the bean is created per JVM whereas in spring, one instance of the bean is created per application context.Proptype −As per the spring documentation −Spring does not manage the complete lifecycle of a prototype bean: the container ... Read More

Difference between @Bean and @Component annotation in Spring.

Himanshu shriv
Updated on 09-Sep-2020 08:56:07

18K+ Views

 Spring supports multiple types annotations such as @Component, @Controller, @service @Repository and @Bean. All theses can be found under the org.springframework.stereotype package.When classes in our application are annotated with any of the above mentioned annotation then during project startup spring scan(using @componentScan) each class and inject the instance of the classes to the IOC container. Another thing the @ComponentScan would do is running the methods with @Bean on it and restore the return object to the Ioc Container as a bean.Sr. No.Key@Bean@Component1Auto detectionIt is used to explicitly declare a single bean, rather than letting Spring do it automatically. If any class ... Read More

Difference between Dependency Injection and Factory Pattern.

Himanshu shriv
Updated on 09-Sep-2020 08:53:23

2K+ Views

Factory and Dependency injection both are the design pattern which can be used to enhance loose coupling abilities between the software components. Factory design pattern is used to create objects. But, injection and life cycle management of the object should be handled by programmer within the application. There is no way to configure everything in a single place. Therefore, programmers need to call object creation logic wherever it needed which eventually hinder the loose coupling abilities.In DI design pattern, creation of object, injecting of the instance and life cycle management of the instance can be handled outside the code. In spring, ... Read More

Difference between IOC and Dependency Injection in Spring.

Himanshu shriv
Updated on 09-Sep-2020 08:50:55

4K+ Views

Inversion of control is a design principle which helps to invert the control of object creation.According to the paper written by Martin Fowler , inversion of control is the principle where the control flow of a program is inverted: instead of the programmer controlling the flow of a program, the external sources (framework, services, other components) take control of it. It's like we plug something into something else. He mentioned an example about EJB 2.0.Dependency Injection is a design pattern which implements IOC principle. DI provides objects that an object needs. Let’s say, class X is dependent on Y. So ... Read More

Difference Between Constructor Injection and Setter Injection in Spring

Himanshu shriv
Updated on 09-Sep-2020 08:49:37

19K+ Views

Dependency Injection is a practice to pass dependent object to other objects. Spring has two types of Dependency Injection :Constructor based Injection -When container call the constructor of the class. It should be used for mandatory dependencies.Let’s say Class X is tightly  dependent on Class Y then we should use constructor based injection.  Setter based Injection - It can be used by calling setter methods on your beans. It should be used for optional dependencies.Both types of injection has their own pros and cons. Below is a list of some differences −Sr. No.KeyConstructor based InjectionSetter based Injection1CircularIt doesn’t allow to ... Read More

Demonstrate nested loops with return statements in JavaScript?

AmitDiwan
Updated on 07-Sep-2020 08:58:48

499 Views

Here’s an example with two loops, outer and inner −Examplelet demoForLoop = ()=>{    for(var outer=1;outer

How do you make a button that adds text in HTML ?

AmitDiwan
Updated on 07-Sep-2020 09:00:55

2K+ Views

Let’s say the following is our HTML button −Click the button to add the input into the belowText BoxUse document.getElementById() to add a text in on button click. Following is the code −Example Live Demo Document Click the button to add the input into the below Text Box    document.getElementById("clickButton").addEventListener("click", () =>{       document.getElementById("readTheInput").value += "JavaScript";    }); To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code ... Read More

Converting any string into camel case with JavaScript removing whitespace as well

AmitDiwan
Updated on 07-Sep-2020 08:52:41

877 Views

In order to convert string into camel case, you need to lowercase the first letter of the word and the first letter of the remaining words must be in capital.Following is the code to convert any string into camel case −Examplefunction convertStringToCamelCase(sentence) {    return sentence.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g,    function(camelCaseMatch, i) {       if (+camelCaseMatch === 0)          return "";       return i === 0 ? camelCaseMatch.toLowerCase() :       camelCaseMatch.toUpperCase();    }); } console.log(convertStringToCamelCase("Add two variables"));To run the above program, you need to use the following command −node fileName.js.Here, my file name is ... Read More

Advertisements